2010-10-12 11:33:19 +08:00
|
|
|
from django.db import models
|
|
|
|
|
2014-10-01 01:24:20 +08:00
|
|
|
|
2014-09-29 23:17:44 +08:00
|
|
|
class Car(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2014-10-01 01:24:20 +08:00
|
|
|
|
2010-10-12 11:33:19 +08:00
|
|
|
class Person(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2014-09-29 23:17:44 +08:00
|
|
|
cars = models.ManyToManyField(Car, through='PossessedCar')
|
2012-12-13 19:33:11 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2014-09-29 23:17:44 +08:00
|
|
|
|
2014-10-01 01:24:20 +08:00
|
|
|
|
2014-09-29 23:17:44 +08:00
|
|
|
class PossessedCar(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
car = models.ForeignKey(Car, models.CASCADE)
|
|
|
|
belongs_to = models.ForeignKey(Person, models.CASCADE)
|