#4306: 'to_field' breaks lookups that span relationships
---------------------+------------------------------------------------------
   Reporter:  shwag  |                Owner:  adrian          
     Status:  new    |            Component:  Database wrapper
    Version:  SVN    |           Resolution:                  
   Keywords:         |                Stage:  Accepted        
  Has_patch:  0      |           Needs_docs:  0               
Needs_tests:  0      |   Needs_better_patch:  0               
---------------------+------------------------------------------------------
Changes (by mtredinnick):

  * stage:  Unreviewed => Accepted

Old description:

> class Website(models.Model):
>     id = models.IntegerField(primary_key=True)
>     dfp_id = models.IntegerField()
>     name = models.CharField(maxlength=300)
>     url = models.CharField(maxlength=150)
> 
> class Report(models.Model):
>     id = models.IntegerField(primary_key=True)
>     site = models.ForeignKey(Website, to_field='dfp_id')
> 
> 444549 is a valid dfp_id in the Website model.
> 
> Report.objects.filter(site=444549)  <-- Returns results. good.
> Report.objects.filter(site__id=444549)  <-- Returns results, but it
> shouldn't.
> Report.objects.filter(site__dfp_id=444549)  <-- No results, but it
> should.
> 
> 130 is the valid id for a Website.
> Report.objects.filter(site__id=130) <- No results, no work around.
> Report.objects.filter(site__name='Validname') <- Also no results.
> Report.objects.filter(site__url='validurl.com') <- Also no results

New description:

 {{{
 #!python
 class Website(models.Model):
     id = models.IntegerField(primary_key=True)
     dfp_id = models.IntegerField()
     name = models.CharField(maxlength=300)
     url = models.CharField(maxlength=150)
 
 class Report(models.Model):
     id = models.IntegerField(primary_key=True)
     site = models.ForeignKey(Website, to_field='dfp_id')
 }}}
 444549 is a valid dfp_id in the Website model.
 
 {{{
 Report.objects.filter(site=444549)  <-- Returns results. good.
 Report.objects.filter(site__id=444549)  <-- Returns results, but it
 shouldn't.
 Report.objects.filter(site__dfp_id=444549)  <-- No results, but it should.
 }}}
 130 is the valid id for a Website.
 {{{
 Report.objects.filter(site__id=130) <- No results, no work around.
 Report.objects.filter(site__name='Validname') <- Also no results.
 Report.objects.filter(site__url='validurl.com') <- Also no results
 }}}

Comment:

 Fixed description formatting.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/4306#comment:6>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to