from django.db import models
from django.core.urlresolvers import reverse
from nani.models import TranslatableModel, TranslatedFields, TranslationManager
from multilingual_model.models import MultilingualModel, MultilingualTranslation
from django.contrib.auth.models import User
class Reference(models.Model):
pass
class TagModel():
class Tag(TranslatableModel):
translations = TranslatedFields(
name=models.CharField(max_length=255),
slug=models.SlugField(unique=True),
)
def __unicode__(self):
return self.name
#@models.permalink
def get_absolute_url(self):
#return ('post.views.PageDetail.as_view()', (), {
# 'slug': self.slug,
# })
return '/tag/{}'.format(self.slug)
class Meta:
ordering = ("slug",)
class PublishedManager(TranslationManager):
def get_query_set(self):
return super(self.class, self).get_query_set().filter(published=True)
############################
class Page(TranslatableModel):
translations = TranslatedFields(
title=models.CharField(max_length=255),
slug=models.CharField(max_length=255, db_index=True, blank=True),
description=models.CharField(max_length=255),
published=models.BooleanField(default=False),
content=models.TextField(),
)
tags = models.ManyToManyField(Tag, blank=True)
def __unicode__(self):
return self.title
#@models.permalink
def get_absolute_url(self):
#return ('post.views.PageDetail.as_view()', (), {
# 'slug': self.slug,
# })
return '/{}'.format(self.slug)
def get_admin_url(self):
return reverse('admin:{:s}_{:s}_change'.format(
self._meta.app_label,
#Remove 'published' to get to real Model
self._meta.module_name.replace('published', '')
), args=(self.pk,))
class Meta:
ordering = ("slug",)
class PublishedPage(Page):
objects = PublishedManager()
#objects = Page.objects
class Meta:
proxy = True
class Entry(TranslatableModel):
translations = TranslatedFields(
title=models.CharField(max_length=255),
slug=models.CharField(max_length=255, db_index=True, blank=True),
description=models.CharField(max_length=255),
published=models.BooleanField(default=False),
content=models.TextField(),
topics=models.ManyToManyField(Page, related_name='entry_set', null=True, blank=True),
authors=models.ManyToManyField(User, blank=True),
updated=models.DateTimeField(
#auto_now=True,
null=True,
),
)
tags = models.ManyToManyField(Tag, blank=True)
def __unicode__(self):
return self.title
#@property
#def topics(self):
# return self.categories
@property
def full_slug(self):
return '{}/{:02d}/{}'.format(self.updated.year, self.updated.month, self.slug)
class Meta:
ordering = ("-updated",)
pass
class PublishedEntry(Entry):
objects = PublishedManager()
def get_absolute_url(self):
try:
return self.news.get_absolute_url()
except:
return self.article.get_absolute_url()
class Meta:
proxy = True
class Article(Entry):
references = models.ManyToManyField(Reference, blank=True)
def get_absolute_url(self):
return '/article/{}'.format(self.full_slug)
class PublishedArticle(Article):
objects = PublishedManager()
class News(Entry):
def get_absolute_url(self):
return '/news/{}'.format(self.full_slug)
class Meta:
verbose_name_plural = "news"
class PublishedNews(News):
objects = PublishedManager()
bash -cl "/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Applications/PyCharm.app/helpers/pycharm/django_manage.py validate"
Traceback (most recent call last):
File "/Applications/PyCharm.app/helpers/pycharm/django_manage.py", line 17, in
run_module(manage_file, None, 'main')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 180, in run_module
fname, loader, pkg_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/Users/truongsinh/Sources/gabc_pro/manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(_args, *_options.dict)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(_args, *_options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/validate.py", line 9, in handle_noargs
self.validate(display_num_errors=True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/loading.py", line 158, in get_app_errors
self._populate()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name, True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
import(name)
File "/Users/truongsinh/Sources/gabc_pro/post/models.py", line 69, in
class PublishedPage(Page):
File "/Users/truongsinh/Sources/gabc_pro/lib/django-hvad/nani/models.py", line 141, in new
"TranslatableModel must define TranslatedFields." % new_model
django.core.exceptions.ImproperlyConfigured: No TranslatedFields found on <class 'post.models.PublishedPage'>, subclasses of TranslatableModel must define TranslatedFields.
Process finished with exit code 1