Opened 7 years ago

Closed 7 years ago

#4681 closed (wontfix)

filter on foreign keys with None doesn't return anything

Reported by: Patrick Lauber <patrick.lauber@…> Owned by: adrian
Component: Database layer (models, ORM) Version: master
Severity: Keywords: filter foreignkey None
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


At the moment you have to do it like this:

class Category(models.Model):
    name = models.CharField(core=True, maxlength=64)
    parent = models.ForeignKey('self', blank=True, null=True, related_name='child')

def getNavigation(request,parent):
    if parent==None:
        return Category.objects.filter(parent__id__isnull=True).order_by('-priority')
        return Category.objects.filter(parent__id=parent).order_by('-priority')

I think for a newbie to Databases like me this not very intuitive. Wouldn't it be possible to make the isnull check automatically behind the scenes if the argument is None or an empty String?

Attachments (0)

Change History (1)

comment:1 Changed 7 years ago by mir@…

  • Component changed from Core framework to Database wrapper
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

Hi Patrick, you're a bit late: We had this discussion already months ago. People who know SQL find it actually more intuitive as it is, and that's a pretty basic knowledge for writing database applications.

You can use the django developers mailing list in case you want to continue discussing this.

BTW, you probably meant {{filter(parent_id...)}} with only a single underscore ;-)

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.