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