--- /dev/null
+from django.db import models
+from django.urls import reverse
+
+from quotes.localmodels import HTMLField
+
+# Create your models here.
+class Tag(models.Model):
+ tag = models.CharField(max_length=100, unique=True)
+
+ def __unicode__(self):
+ return self.tag
+
+ def get_absolute_url(self):
+ return reverse('quotes_beta:tags', args=[str(self.id)])
+
+class Context(models.Model):
+ creation_date = models.DateTimeField(auto_now_add=True)
+ last_modification = models.DateTimeField(auto_now=True)
+
+ name = models.CharField(max_length=100,
+ unique=True)
+
+ date = models.DateField(blank=True, null=True,
+ help_text="Date of the quote")
+
+ notes = HTMLField(blank=True, help_text= \
+ "Notes about the entry; may be left blank. Displayed \
+ on the public pages")
+ pvt_notes = HTMLField(blank=True, help_text= \
+ "Notes about the entry; not displayed on \
+ the public interface")
+
+ tags = models.ManyToManyField(Tag, blank=True,
+ help_text='Not implemented yet')
+
+ nb_display = models.BigIntegerField(default=0)
+ def incr_display(self):
+ self.nb_display = models.F('nb_display') + 1
+ self.save()
+
+ def add_parent(self, parent):
+ descendants = self.childs + self
+ ascendants = parent + parent.parents
+ for descendant in descendants:
+ for ascendant in ascendants:
+ Link.objects.create(child=descendant, parent=ascendant)
+
+ def __unicode__(self):
+ return self.name
+
+ class Meta:
+ ordering = ['name']
+
+class Person(Context):
+ birth_date = models.DateField(blank=True, null=True,
+ help_text="Date of birth")
+ death_date = models.DateField(blank=True, null=True,
+ help_text="Date of death (leave blank \
+ if still alive!)")
+
+ def get_absolute_url(self):
+ return reverse('quotes_beta:person', args=[str(self.id)])
+
+class Book(Context):
+ def get_absolute_url(self):
+ return reverse('quotes_beta:work', args=[str(self.id)])
+
+class Film(Context):
+ def get_absolute_url(self):
+ return reverse('quotes_beta:work', args=[str(self.id)])
+
+class Quote(Context):
+ text = HTMLField()
+
+ def __unicode__(self):
+ return self.work.author.name + ": " + self.text
+
+ def get_absolute_url(self):
+ return reverse('quotes_beta:onequote', args=[str(self.id)])
+
+ # class Meta(Context.Meta):
+ # ordering = ['-pk']
+
+class Link(models.Model):
+ child = models.ForeignKey(Context, related_name='parents')
+ parent = models.ForeignKey(Context, related_name='childs')
+ relation_type = models.CharField(max_length=100)
+
+