2010-10-12 03:33:19 +00:00
|
|
|
from django.db import models
|
2012-12-13 13:33:11 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2010-10-12 03:33:19 +00:00
|
|
|
|
2014-09-30 13:24:20 -04:00
|
|
|
|
2014-09-29 17:17:44 +02:00
|
|
|
@python_2_unicode_compatible
|
|
|
|
class Car(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2013-11-02 16:34:05 -05:00
|
|
|
|
2014-09-30 13:24:20 -04:00
|
|
|
|
2012-12-13 13:33:11 +02:00
|
|
|
@python_2_unicode_compatible
|
2010-10-12 03:33:19 +00:00
|
|
|
class Person(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2014-09-29 17:17:44 +02:00
|
|
|
cars = models.ManyToManyField(Car, through='PossessedCar')
|
2012-12-13 13:33:11 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2014-09-29 17:17:44 +02:00
|
|
|
|
2014-09-30 13:24:20 -04:00
|
|
|
|
2014-09-29 17:17:44 +02:00
|
|
|
@python_2_unicode_compatible
|
|
|
|
class PossessedCar(models.Model):
|
|
|
|
car = models.ForeignKey(Car)
|
|
|
|
belongs_to = models.ForeignKey(Person)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.color
|