There should be no difference with the operational perspective, so the only difference is the definition of the model and the things that affect it (for example, in manager classes).
You also do not have to define a class through. Django does this automatically for you, and this whole class does support a third table to track the corresponding identifiers for each related record in two other tables. You have to decide if you want to add anything to this third table, which is important.
For example, let's say you are developing a web application for a conference. They may want to store information about visitors (both individuals and companies), as well as speakers and sponsors (as well as individuals and companies). Some of your company models may look like this:
class Company(models.Model): name = models.CharField(max_length=100) sponsored_segment = models.ForeignKey(ConferenceSegment, null=True) class ConferenceSegment(models.Model): title = models.CharField(max_length=100)
But this is quickly becoming cumbersome, and you will have many companies that have nothing to do with sponsorship. In addition, you can track your rating / package on the website (in the end, large sponsors get more placement):
class Company(models.Model): name = models.CharField(max_length=100) class ConferenceSegment(models.Model): title = models.CharField(max_length=100) sponsors = models.ManyToManyField(Company, through=u'Sponsor', related_name=u'sponsored_segments') class Sponsor(models.Model): company = models.ForeignKey(Company) segment = models.ForeignKey(ConferenceSegment) rank = models.PositiveIntegerField()
Also note the "related_name" attribute in ManyToManyField . This means that we can access the ConferenceSegment object through the Company instance using this name:
c = Company.objects.get(...) segments = c.sponsored_segments.all()
Hope this helps.
source share