2012-06-07 16:08:47 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2011-12-22 20:42:40 +00:00
|
|
|
from django.db import models
|
2012-08-12 10:32:08 +00:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2011-12-22 20:42:40 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
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(
|
|
|
|
'self',
|
|
|
|
models.SET_NULL,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
related_name='children',
|
|
|
|
)
|
2011-12-22 20:42:40 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['name']
|
|
|
|
|
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
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
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
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
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)
|
|
|
|
tags = models.ManyToManyField(Tag, through='StaffTag')
|
|
|
|
coworkers = models.ManyToManyField('self')
|
|
|
|
|
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
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
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)
|