Opened 17 years ago

Last modified 16 years ago

#4306 closed

'to_field' breaks lookups that span relationships — at Initial Version

Reported by: shwag Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: qs-rf-fixed
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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(siteid=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(siteid=130) <- No results, no work around.
Report.objects.filter(site
name='Validname') <- Also no results.
Report.objects.filter(siteurl='validurl.com') <- Also no results

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top