X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=quotes_beta%2Fmodels.py;fp=quotes_beta%2Fmodels.py;h=ba05a2860c24bbaee491382a32320b36ef6dfad7;hb=24bbf1b4cdcd0c0192ca9df3749f7a3b8d3ed211;hp=0000000000000000000000000000000000000000;hpb=6dff47145bbfa9ab014df350f192b9794d319509;p=djsite.git diff --git a/quotes_beta/models.py b/quotes_beta/models.py new file mode 100644 index 0000000..ba05a28 --- /dev/null +++ b/quotes_beta/models.py @@ -0,0 +1,89 @@ +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) + +