2011-12-23 04:42:40 +08:00
|
|
|
from django.db import models
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-12-23 04:42:40 +08:00
|
|
|
class Tag(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey(
|
|
|
|
"self",
|
|
|
|
models.SET_NULL,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
related_name="children",
|
|
|
|
)
|
2011-12-23 04:42:40 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["name"]
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-12-23 04:42:40 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-12-23 04:42:40 +08:00
|
|
|
class Celebrity(models.Model):
|
|
|
|
name = models.CharField("Name", max_length=20)
|
2015-07-22 22:43:21 +08:00
|
|
|
greatest_fan = models.ForeignKey(
|
|
|
|
"Fan",
|
|
|
|
models.SET_NULL,
|
|
|
|
null=True,
|
|
|
|
unique=True,
|
|
|
|
)
|
2011-12-23 04:42:40 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-12-23 04:42:40 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-12-23 04:42:40 +08:00
|
|
|
class Fan(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
fan_of = models.ForeignKey(Celebrity, models.CASCADE)
|
2011-12-23 04:42:40 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-12-23 04:42:40 +08:00
|
|
|
class Staff(models.Model):
|
|
|
|
id = models.IntegerField(primary_key=True)
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
organisation = models.CharField(max_length=100)
|
|
|
|
tags = models.ManyToManyField(Tag, through="StaffTag")
|
|
|
|
coworkers = models.ManyToManyField("self")
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-12-23 04:42:40 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-12-23 04:42:40 +08:00
|
|
|
class StaffTag(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
staff = models.ForeignKey(Staff, models.CASCADE)
|
|
|
|
tag = models.ForeignKey(Tag, models.CASCADE)
|
2011-12-23 04:42:40 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return "%s -> %s" % (self.tag, self.staff)
|