robin
unread,May 31, 2011, 4:53:26 AM5/31/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Example code:
class Parent(models.Model):
name = models.CharField(max_length='20',blank=True)
class Child(Parent):
pass
I want to get the result of Child.objects.all() but I DO NOT want to
use Child.
I want to use Parent instead, which I tried to do with:
Parent.objects.filter(child__isnull=False)
Which doesn't work and gives the result of Product.objects.all()
instead.
However If I do the following, it WORKS:
Parent.objects.filter(child__name__isnull=False)
Another way, if I insist on using
Parent.objects.filter(child__isnull=False), is to change the Child
model to the following:
class Child(models.Model):
parent = models.OneToOneField(Parent)
Then Parent.objects.filter(child__isnull=False) would WORK
The problem with the 2 solutions above is that filtering with
child__name__isnull looks hackish, and I don't want to change my Child
model to use OneToOneField.
So is there a better way?
Thanks,
Robin