]> gitweb.fperrin.net Git - djsite.git/blob - quotes_beta/models.py
Try new multilinks approach
[djsite.git] / quotes_beta / models.py
1 from django.db import models
2 from django.urls import reverse
3
4 from quotes.localmodels import HTMLField
5
6 # Create your models here.
7 class Tag(models.Model):
8     tag = models.CharField(max_length=100, unique=True)
9
10     def __unicode__(self):
11         return self.tag
12
13     def get_absolute_url(self):
14         return reverse('quotes_beta:tags', args=[str(self.id)])
15
16 class Context(models.Model):
17     creation_date = models.DateTimeField(auto_now_add=True)
18     last_modification = models.DateTimeField(auto_now=True)
19
20     name = models.CharField(max_length=100,
21                             unique=True)
22
23     date = models.DateField(blank=True, null=True,
24                             help_text="Date of the quote")
25
26     notes = HTMLField(blank=True, help_text= \
27                       "Notes about the entry; may be left blank. Displayed \
28                       on the public pages")
29     pvt_notes = HTMLField(blank=True, help_text= \
30                           "Notes about the entry; not displayed on \
31                           the public interface")
32
33     tags = models.ManyToManyField(Tag, blank=True,
34                                   help_text='Not implemented yet')
35
36     nb_display = models.BigIntegerField(default=0)
37     def incr_display(self):
38         self.nb_display = models.F('nb_display') + 1
39         self.save()
40
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)
47
48     def __unicode__(self):
49         return self.name
50
51     class Meta:
52         ordering = ['name']
53
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 \
59                                   if still alive!)")
60
61     def get_absolute_url(self):
62         return reverse('quotes_beta:person', args=[str(self.id)])
63
64 class Book(Context):
65     def get_absolute_url(self):
66         return reverse('quotes_beta:work', args=[str(self.id)])
67
68 class Film(Context):
69     def get_absolute_url(self):
70         return reverse('quotes_beta:work', args=[str(self.id)])
71
72 class Quote(Context):
73     text = HTMLField()
74
75     def __unicode__(self):
76         return self.work.author.name + ": " + self.text
77
78     def get_absolute_url(self):
79         return reverse('quotes_beta:onequote', args=[str(self.id)])
80
81     # class Meta(Context.Meta):
82     #     ordering = ['-pk']
83
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)
88
89