Reputation: 110382
I would like to get all positions associated with a particular job post. JobPost
is an FK to Position
, and when I do normal .values()
, I get the foreign key id rather than the position as a string. For example:
>>> JobPost.objects.filter(production=p).values('position')
[{'position': 4L}]
What I really need to get would be something like, in pseudocode:
>>> JobPost.objects.filter(production=p).values('position.position')
And the models:
class JobPost(models.Model):
name = models.CharField(max_length=100)
position = models.ForeignKey(Position)
class Position(models.Model):
position = models.CharField(max_length=100)
How would I do this?
Upvotes: 0
Views: 390
Reputation: 174662
JobPost.objects.filter(production=p).values('position__position')
See field lookups that span relationships.
Upvotes: 3