A bunch of fixes :
[webcomics.git] / comicsporn / models.py
index 8ccfd9d33ffd869e74c9a89b68b6ac40db020abe..0cea8c997e0274ae2acb65162a5bf9aa898c7dde 100644 (file)
@@ -1,38 +1,88 @@
 from django.db import models
-
-# Create your models here.
+from django.contrib.auth.models import User
+from django.utils.translation import ugettext_lazy as _
 
 # A very basic data model to begin with
-# Create sensible default option, test the authentification framework, ensure 
-# pertinence of the comics building way : page by page, vignette by vignette, etc. offer 
-# multiple way as much as much possible, test upload to PDF file outisde the DB...
-
-class User(models.Model):
-       first_name = models.CharField(max_length=50)
-       last_name = models.CharField(max_length=50)
-       # Not sure about this two, django should offer login/pass and session
-       #login = models.CharField(max_length=15)
-       #password = models.CharField(max_length=15) 
-       email = models.EmailField()
+# TODO: 
+# - Create sensible default options with translation; 
+# - Test the authentification framework; 
+# - Ensure pertinence of the comics building way : block by block;
+# - Test upload to images file outside the DB ...;
+# - ...
+
+class Style(models.Model):                                                    
+       """
+       TODO: The choice list should be in DB
+       """
+       TAG_NAME_CHOICES = (
+                (_('MG'), _('Manga')),
+                (_('HF'), _('Heroic Fantasy')),
+        )
+       name = models.CharField(_('name'), max_length=30, choices=TAG_NAME_CHOICES)
+       def __unicode__(self):
+               return self.name
+       class Meta:
+               verbose_name = _('Style')
+               verbose_name_plural = _('Styles')
+               ordering = ('name',)
+
+class UserProfile(models.Model):
+       user = models.OneToOneField(User)       
        headshot = models.ImageField(upload_to='user_headshots')
        is_author = models.BooleanField()
-        #num_awards = models.IntegerField()
+       """ 
+        The main difference is that the author have is own ads publisher
+        The default behaviour of class inheritance is to create OnetoOne relationship between parent and child 
+        TODO: Which fields are required to interact with the ads publisher ?
+        """
+        ADS_PUBLISHER_CHOICES = (
+                ('AS', 'Advert Stream'),
+                ('TJ', 'Traffic Junky'),
+        )
+        ads_publisher = models.CharField(max_length=50, choices=ADS_PUBLISHER_CHOICES)
+        ads_publisher_login = models.CharField(max_length=50)
+
+       class Meta:
+               verbose_name = _('User profile')
+               verbose_name_plural = _('Users profiles')
+
+# TODO: See how to handle a group of authors and the revenue sharing ... later 
 
+class Comic_block(models.Model):
+       """
+       Let's view a comics as an images serie
+       """
+       name = models.CharField(_('name'), max_length=50) # probably not useful, it's just simplier to assemble afterwards for author
+       number = models.IntegerField(_('number'))
+       content = models.ImageField(upload_to='block_contents')
+       # TODO: probably not useful
+       is_complete = models.BooleanField()
+       upload_datetime = models.DateTimeField(_('upload_datetime'), auto_now=True)
+       authors = models.ManyToManyField(UserProfile, verbose_name=_('authors'))
+       def __unicode__(self):
+               """
+               This idea is to return a visual identifier to the author, self.content is surely bogus to get the image path
+               """
+               return self.name + ' ' + self.content
 
-class Comics_page(models.Model):
-       # Not sure about vignette by vignette view or page by page ... let's start page by page 
-       page_number = models.IntegerField()
-       page_content = models.ImageField(upload_to='comics_pages')
-       upload_date = models.DateField()
-       page_authors = models.ManyToManyField(User)
+       class Meta:
+               verbose_name = _('Comic_block')
+               verbose_name_plural = _('Comic_blocks')
+               ordering = ('name',)
 
-class Comics(Comics_page):
-       title = models.CharField(max_length=300)
+class Comic(models.Model):
+       """ 
+       A comic is build from N blocks, whatever they are
+       The ManytoMany relationship is not really required but it much more reflect really : authors can share block between comic
+       """
+       title = models.CharField(max_length=50)
        rating = models.FloatField()
-       authors = models.ManyToManyField(User)
-       publication_date = models.DateField()
-       # Change the related name to a more appropriate name
-       fragment_comics = models.ManyToManyField(Comics_page, related_name="%(app_label)s_%(class)s_related")
-       full_comics = models.ImageField(upload_to='comics_full')
-       full_comics_upload_date = models.DateField()
-       #publisher = models.ForeignKey(User)
+       is_online = models.BooleanField()
+       publication_date = models.DateField(auto_now=True)
+       blocks = models.ManyToManyField(Comic_block)
+       styles = models.ManyToManyField(Style)
+       def __unicode__(self):
+               return self.title
+       
+       class Meta:
+               ordering = ('title',)