Thanks Malcolm. I couldn't find a ticket for this particular enhancement so I created http://code.djangoproject.com/ticket/2400.
On 7/22/06, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > On Sat, 2006-07-22 at 19:43 +1000, Matthew Flanagan wrote: > > Hi, > > > > I have the following simplified models. Then I create a number of IP > > addresses and interfaces, with not all IP addresses being related to > > an interface. > > > > class IPAddress(models.Model): > > address = models.CharField(maxlength=15) > > > > class Admin: pass > > > > class Interface(models.Model): > > name = models.CharField(maxlength=15) > > ipaddress = models.ForeignKey(IPAddress) > > > > class Admin: pass > > > > Then when I try: > > > > >>> IPAddress.objects.filter(interface__isnull=False) > > > > I get a list of IPAddresses that have related interfaces. > > > > Then if I try: > > > > >>> IPAddress.objects.filter(interface__isnull=True) > > > > I get an empty list when I expected to be getting the IP addresses > > that are not related to any interfaces. Right? > > > > Ultimately I'd like to do this: > > > > class Interface(models.Model): > > name = models.CharField(maxlength=15) > > ipaddress = models.ForeignKey(IPAddress, > > limit_choices_to={'interface__isnull':True}) > > > > class Admin: pass > > > > so that the admin will only should "free" ip addresses not ones that > > ae already used. > > > > Is this a bug? Am I doing the wrong lookup? > > It's not a bug. But it could be argued it's a missing feature. Because > the reverse relation does not exist yet, you cannot query against it. We > would need to special case this type of situation. For the moment, you > will need to construct a custom SQL query if you want to do this (it's > not too painful). > > If there's not a ticket for it already (it came up in [1]), maybe file > an enhancement request. > > [1] > http://groups.google.com/group/django-users/browse_frm/thread/98b7aedf8f9d806c/385833fa2b597afe?lnk=gst&rnum=1#385833fa2b597afe > > Regards, > Malcolm > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---