2012-04-24 18:47:31 +02:00
|
|
|
from django.db import models
|
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2012-04-24 18:47:31 +02:00
|
|
|
class Person(models.Model):
|
|
|
|
first_name = models.CharField(max_length=20)
|
|
|
|
last_name = models.CharField(max_length=20)
|
2018-07-11 10:18:41 +02:00
|
|
|
friends = models.ManyToManyField('self')
|
2018-07-11 22:37:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
# A set of models that use a non-abstract inherited 'through' model.
|
|
|
|
class ThroughBase(models.Model):
|
|
|
|
person = models.ForeignKey(Person, models.CASCADE)
|
|
|
|
b = models.ForeignKey('B', models.CASCADE)
|
|
|
|
|
|
|
|
|
|
|
|
class Through(ThroughBase):
|
|
|
|
extra = models.CharField(max_length=20)
|
|
|
|
|
|
|
|
|
|
|
|
class B(models.Model):
|
|
|
|
people = models.ManyToManyField(Person, through=Through)
|