I am learning Django and trying to get foreign key information through a bridge table. Sorry if this is a duplicate, I could not find the answer by doing a search. I have models defined as follows.
class Place(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=100)
class PlaceRef(models.Model):
place = models.ForeignKey(Place)
entry = models.ForeignKey(Entry)
class Entry(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=10)
If I want to get all the records associated with a specific place, how to do this?
place = get_object_or_404(Place, id=id)
placerefs = PlaceRef.objects.filter(place=place)
entries = Entry.objects.filter(id.....)
Also, if there is a smarter way to define (or get rid of) PlaceRefs in Django, feel free to suggest alternatives.
Thanks for helping the newbies!
AP257 source
share