1 from django.db import models
2 from django.urls import reverse
4 from quotes.localmodels import HTMLField
6 # Create your models here.
7 class Tag(models.Model):
8 tag = models.CharField(max_length=100, unique=True)
10 def __unicode__(self):
13 def get_absolute_url(self):
14 return reverse('quotes_beta:tags', args=[str(self.id)])
16 class Context(models.Model):
17 creation_date = models.DateTimeField(auto_now_add=True)
18 last_modification = models.DateTimeField(auto_now=True)
20 name = models.CharField(max_length=100,
23 date = models.DateField(blank=True, null=True,
24 help_text="Date of the quote")
26 notes = HTMLField(blank=True, help_text= \
27 "Notes about the entry; may be left blank. Displayed \
29 pvt_notes = HTMLField(blank=True, help_text= \
30 "Notes about the entry; not displayed on \
31 the public interface")
33 tags = models.ManyToManyField(Tag, blank=True,
34 help_text='Not implemented yet')
36 nb_display = models.BigIntegerField(default=0)
37 def incr_display(self):
38 self.nb_display = models.F('nb_display') + 1
41 def add_parent(self, parent):
42 descendants = self.childs + self
43 ascendants = parent + parent.parents
44 for descendant in descendants:
45 for ascendant in ascendants:
46 Link.objects.create(child=descendant, parent=ascendant)
48 def __unicode__(self):
54 class Person(Context):
55 birth_date = models.DateField(blank=True, null=True,
56 help_text="Date of birth")
57 death_date = models.DateField(blank=True, null=True,
58 help_text="Date of death (leave blank \
61 def get_absolute_url(self):
62 return reverse('quotes_beta:person', args=[str(self.id)])
65 def get_absolute_url(self):
66 return reverse('quotes_beta:work', args=[str(self.id)])
69 def get_absolute_url(self):
70 return reverse('quotes_beta:work', args=[str(self.id)])
75 def __unicode__(self):
76 return self.work.author.name + ": " + self.text
78 def get_absolute_url(self):
79 return reverse('quotes_beta:onequote', args=[str(self.id)])
81 # class Meta(Context.Meta):
84 class Link(models.Model):
85 child = models.ForeignKey(Context, related_name='parents')
86 parent = models.ForeignKey(Context, related_name='childs')
87 relation_type = models.CharField(max_length=100)