From: Jérôme Benoit Date: Fri, 1 Nov 2013 01:35:59 +0000 (+0100) Subject: A bunch of fixes : X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=298255d2254e2dd9c80e3378493cd296e1d54ba1;p=webcomics.git A bunch of fixes : * Correct the data models to make use of django user management. There's still some questions but I think the is_author will be useful to filter author from user quickly; * Finalize the comic data model, looks really cool now; * Work on the admin interface; Probably more ... I've forgot. Signed-off-by: Jérôme Benoit --- diff --git a/comicsporn/admin.py b/comicsporn/admin.py new file mode 100644 index 0000000..9799d44 --- /dev/null +++ b/comicsporn/admin.py @@ -0,0 +1,36 @@ +from django.contrib import admin +from django.contrib.auth.admin import UserAdmin +from django.contrib.auth.models import User +from comicsporn.models import Style, UserProfile, Comic_block, Comic +from django.utils.translation import ugettext as _ + +admin.site.register(Style) + +class UserProfileInline(admin.StackedInline): + model = UserProfile + can_delete = False + verbose_name_plural = _('Users profiles') + +class UserAdmin(UserAdmin): + inlines = (UserProfileInline, ) + +admin.site.unregister(User) +admin.site.register(User, UserAdmin) + +class Comic_blockInline(admin.TabularInline): + model = Comic.blocks.through + extra = 10 + +class ComicAdmin(admin.ModelAdmin): + fieldsets = [ + ('Title', {'fields': ['title']}), + ('Online', {'fields': ['is_online']}), + ('Comic block', {'fields': ['blocks']}), + ] + inlines = [ + Comic_blockInline, + ] + +admin.site.register(Comic_block) + +admin.site.register(Comic) diff --git a/comicsporn/models.py b/comicsporn/models.py index 8ccfd9d..0cea8c9 100644 --- a/comicsporn/models.py +++ b/comicsporn/models.py @@ -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',) diff --git a/comicsporn/models.pyc b/comicsporn/models.pyc index af24cbc..1ad9b55 100644 Binary files a/comicsporn/models.pyc and b/comicsporn/models.pyc differ diff --git a/settings.py b/settings.py index cc21cbb..d408123 100644 --- a/settings.py +++ b/settings.py @@ -109,7 +109,7 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.messages.middleware.MessageMiddleware', ) -ROOT_URLCONF = 'django.urls' +ROOT_URLCONF = 'urls' TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". diff --git a/urls.py b/urls.py index 07576d3..658585a 100644 --- a/urls.py +++ b/urls.py @@ -1,8 +1,8 @@ from django.conf.urls.defaults import patterns, include, url # Uncomment the next two lines to enable the admin: -# from django.contrib import admin -# admin.autodiscover() +from django.contrib import admin +admin.autodiscover() urlpatterns = patterns('', # Examples: