Commit | Line | Data |
---|---|---|
c8070854 | 1 | from django.db import models |
298255d2 JB |
2 | from django.contrib.auth.models import User |
3 | from django.utils.translation import ugettext_lazy as _ | |
c8070854 JB |
4 | |
5 | # A very basic data model to begin with | |
298255d2 JB |
6 | # TODO: |
7 | # - Create sensible default options with translation; | |
8 | # - Test the authentification framework; | |
9 | # - Ensure pertinence of the comics building way : block by block; | |
10 | # - Test upload to images file outside the DB ...; | |
11 | # - ... | |
12 | ||
13 | class Style(models.Model): | |
14 | """ | |
15 | TODO: The choice list should be in DB | |
16 | """ | |
17 | TAG_NAME_CHOICES = ( | |
18 | (_('MG'), _('Manga')), | |
19 | (_('HF'), _('Heroic Fantasy')), | |
20 | ) | |
21 | name = models.CharField(_('name'), max_length=30, choices=TAG_NAME_CHOICES) | |
22 | def __unicode__(self): | |
23 | return self.name | |
24 | class Meta: | |
25 | verbose_name = _('Style') | |
26 | verbose_name_plural = _('Styles') | |
27 | ordering = ('name',) | |
28 | ||
29 | class UserProfile(models.Model): | |
30 | user = models.OneToOneField(User) | |
c8070854 JB |
31 | headshot = models.ImageField(upload_to='user_headshots') |
32 | is_author = models.BooleanField() | |
298255d2 JB |
33 | """ |
34 | The main difference is that the author have is own ads publisher | |
35 | The default behaviour of class inheritance is to create OnetoOne relationship between parent and child | |
36 | TODO: Which fields are required to interact with the ads publisher ? | |
37 | """ | |
38 | ADS_PUBLISHER_CHOICES = ( | |
39 | ('AS', 'Advert Stream'), | |
40 | ('TJ', 'Traffic Junky'), | |
41 | ) | |
42 | ads_publisher = models.CharField(max_length=50, choices=ADS_PUBLISHER_CHOICES) | |
43 | ads_publisher_login = models.CharField(max_length=50) | |
44 | ||
45 | class Meta: | |
46 | verbose_name = _('User profile') | |
47 | verbose_name_plural = _('Users profiles') | |
48 | ||
49 | # TODO: See how to handle a group of authors and the revenue sharing ... later | |
c8070854 | 50 | |
298255d2 JB |
51 | class Comic_block(models.Model): |
52 | """ | |
53 | Let's view a comics as an images serie | |
54 | """ | |
55 | name = models.CharField(_('name'), max_length=50) # probably not useful, it's just simplier to assemble afterwards for author | |
56 | number = models.IntegerField(_('number')) | |
57 | content = models.ImageField(upload_to='block_contents') | |
58 | # TODO: probably not useful | |
59 | is_complete = models.BooleanField() | |
60 | upload_datetime = models.DateTimeField(_('upload_datetime'), auto_now=True) | |
61 | authors = models.ManyToManyField(UserProfile, verbose_name=_('authors')) | |
62 | def __unicode__(self): | |
63 | """ | |
64 | This idea is to return a visual identifier to the author, self.content is surely bogus to get the image path | |
65 | """ | |
66 | return self.name + ' ' + self.content | |
c8070854 | 67 | |
298255d2 JB |
68 | class Meta: |
69 | verbose_name = _('Comic_block') | |
70 | verbose_name_plural = _('Comic_blocks') | |
71 | ordering = ('name',) | |
c8070854 | 72 | |
298255d2 JB |
73 | class Comic(models.Model): |
74 | """ | |
75 | A comic is build from N blocks, whatever they are | |
76 | The ManytoMany relationship is not really required but it much more reflect really : authors can share block between comic | |
77 | """ | |
78 | title = models.CharField(max_length=50) | |
c8070854 | 79 | rating = models.FloatField() |
298255d2 JB |
80 | is_online = models.BooleanField() |
81 | publication_date = models.DateField(auto_now=True) | |
82 | blocks = models.ManyToManyField(Comic_block) | |
83 | styles = models.ManyToManyField(Style) | |
84 | def __unicode__(self): | |
85 | return self.title | |
86 | ||
87 | class Meta: | |
88 | ordering = ('title',) |