selfsimilar
selfsimilar

Reputation: 1387

Django dynamic filter failure

As a follow-up to this question, I'd like to pinpoint the actual error that was occurring. Am I doing something wrong, or is this a bug?

    f = {'groups__isnull': 'True'}
    students1 = models.Student.objects.filter( **f )
    students2 = models.Student.objects.filter(groups__isnull=True)

These two queries should be identical, but are not.

For reference, my models:

class Student (models.Model):
    user = models.ForeignKey(User, unique=True, null=False, related_name='student')
    teacher = models.ForeignKey(User, null=False, related_name='students')
    assignment = models.ForeignKey(LabJournal, blank=True, null=True, related_name='students')

class JournalGroup (models.Model):
    title = models.CharField(null=False, max_length=256)
    owner = models.ForeignKey(User, null=True, related_name='journal_groups')
    members = models.ManyToManyField(Student, blank=True, related_name='groups')

Upvotes: 0

Views: 241

Answers (1)

simplyharsh
simplyharsh

Reputation: 36393

I see an obvious difference between queries.

{'groups__isnull': True} is never equal to {'groups__isnull': 'True'}.

One provides True as boolean, other as a string.

Upvotes: 5

Related Questions