2012-04-25 00:47:31 +08:00
|
|
|
from django.db import models
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-04-25 00:47:31 +08:00
|
|
|
class Person(models.Model):
|
|
|
|
first_name = models.CharField(max_length=20)
|
|
|
|
last_name = models.CharField(max_length=20)
|
2018-07-11 16:18:41 +08:00
|
|
|
friends = models.ManyToManyField('self')
|
2018-07-12 04:37:56 +08: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)
|