Answer the question
In order to leave comments, you need to log in
How to work with data in intermediate table in Django ORM?
How to work with data in an intermediate table using Django ORM, with a many-to-many relationship?
For example, table A and B are linked through table A_B and it has fields A_id B_id and let's say the Value field, how to work with it if we select entity a and want to display all related entities B plus this value?
Answer the question
In order to leave comments, you need to log in
Your answer is here https://docs.djangoproject.com/es/1.9/topics/db/ex...
as an option:
class Publication(models.Model):
title = models.CharField(max_length=30)
def __str__(self): # __unicode__ on Python 2
return self.title
class Meta:
ordering = ('title',)
class Article(models.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication)
def __str__(self): # __unicode__ on Python 2
return self.headline
class Meta:
ordering = ('headline',)
Publication.objects.get(id=4).article_set.all()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question