0👍
say you have object B with fields att2 and att3
class modelA(models.Model):
att1 = models.ForeignKey(modelB)
class modelB(models.Model):
att2 = models.CharField(max_length=255)
att3 = models.CharField(max_length=255)
then you filter by doing:
results = modelA.objects.filter(att1__att2=’foo’)
hope this helps
- Django: Print out all choices for a models.Model class
- How to get ID from another model in django?
- The 'profile_pic' attribute has no file associated with it
- How to add datetimefield to Django and migrate
Source:stackexchange.com