topic app

This commit is contained in:
nitely 2015-07-24 18:08:30 -03:00
parent 078860a64d
commit bedff1a924
17 changed files with 185 additions and 9 deletions

View File

@ -14,7 +14,7 @@ from ...core.utils import paginator
class CommentBookmark(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_("user"))
topic = models.ForeignKey('spirit.Topic')
topic = models.ForeignKey('spirit_topic.Topic')
comment_number = models.PositiveIntegerField(default=0)

View File

@ -29,7 +29,7 @@ ACTION = (
class Comment(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_("user"))
topic = models.ForeignKey('spirit.Topic')
topic = models.ForeignKey('spirit_topic.Topic')
comment = models.TextField(_("comment"), max_length=COMMENT_MAX_LEN)
comment_html = models.TextField(_("comment html"))

View File

@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('spirit', '0015_auto_20150724_1940'),
]
state_operations = [
migrations.RemoveField(
model_name='topic',
name='category',
),
migrations.RemoveField(
model_name='topic',
name='user',
),
migrations.AlterField(
model_name='comment',
name='topic',
field=models.ForeignKey(to='spirit_topic.Topic'),
),
migrations.AlterField(
model_name='commentbookmark',
name='topic',
field=models.ForeignKey(to='spirit_topic.Topic'),
),
migrations.AlterField(
model_name='topicfavorite',
name='topic',
field=models.ForeignKey(to='spirit_topic.Topic'),
),
migrations.AlterField(
model_name='topicnotification',
name='topic',
field=models.ForeignKey(to='spirit_topic.Topic'),
),
migrations.AlterField(
model_name='topicpoll',
name='topic',
field=models.OneToOneField(to='spirit_topic.Topic', related_name='poll', primary_key=True, verbose_name='topic', serialize=False),
),
migrations.AlterField(
model_name='topicprivate',
name='topic',
field=models.ForeignKey(related_name='topics_private', to='spirit_topic.Topic'),
),
migrations.AlterField(
model_name='topicunread',
name='topic',
field=models.ForeignKey(to='spirit_topic.Topic'),
),
migrations.DeleteModel(
name='Topic',
),
]
operations = [
migrations.SeparateDatabaseAndState(
state_operations=state_operations)
]

View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
def rename_model_content_type(apps, schema_editor):
content_types = apps.get_model('contenttypes.ContentType')
content_types.objects.filter(
app_label='spirit', model='Topic'.lower()
).update(app_label='spirit_topic')
class Migration(migrations.Migration):
dependencies = [
('spirit', '0016_auto_20150724_2103'),
]
operations = [
migrations.RunPython(rename_model_content_type),
]

View File

@ -6,7 +6,6 @@ from .comment.history.models import CommentHistory
from .comment.bookmark.models import CommentBookmark
from .comment.flag.models import Flag
from .comment.like.models import CommentLike
from .topic.models import Topic
from .topic.unread.models import TopicUnread
from .topic.favorite.models import TopicFavorite
from .topic.notification.models import TopicNotification

View File

@ -49,6 +49,7 @@ INSTALLED_APPS = [
'spirit.core',
'spirit.category',
'spirit.user',
'spirit.topic',
# 'spirit.core.tests'
]

View File

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
default_app_config = 'spirit.topic.apps.SpiritTopicConfig'

12
spirit/topic/apps.py Normal file
View File

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class SpiritTopicConfig(AppConfig):
name = 'spirit.topic'
verbose_name = "Spirit Topic"
label = 'spirit_topic'

View File

@ -11,7 +11,7 @@ from django.utils import timezone
class TopicFavorite(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
topic = models.ForeignKey('spirit.Topic')
topic = models.ForeignKey('spirit_topic.Topic')
date = models.DateTimeField(default=timezone.now)
@ -21,3 +21,4 @@ class TopicFavorite(models.Model):
verbose_name = _("favorite")
verbose_name_plural = _("favorites")
db_table = 'spirit_favorite_topicfavorite' # TODO: remove in Spirit 0.4
app_label = 'spirit'

View File

@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import spirit.core.utils.models
import django.utils.timezone
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('spirit_category', '0002_auto_20150724_1644'),
('spirit', '0016_auto_20150724_2103')
]
state_operations = [
migrations.CreateModel(
name='Topic',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(verbose_name='title', max_length=255)),
('slug', spirit.core.utils.models.AutoSlugField(populate_from='title', db_index=False, blank=True)),
('date', models.DateTimeField(verbose_name='date', default=django.utils.timezone.now)),
('last_active', models.DateTimeField(verbose_name='last active', default=django.utils.timezone.now)),
('is_pinned', models.BooleanField(verbose_name='pinned', default=False)),
('is_globally_pinned', models.BooleanField(verbose_name='globally pinned', default=False)),
('is_closed', models.BooleanField(verbose_name='closed', default=False)),
('is_removed', models.BooleanField(default=False)),
('view_count', models.PositiveIntegerField(verbose_name='views count', default=0)),
('comment_count', models.PositiveIntegerField(verbose_name='comment count', default=0)),
('category', models.ForeignKey(verbose_name='category', to='spirit_category.Category')),
('user', models.ForeignKey(verbose_name='user', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'topic',
'db_table': 'spirit_topic_topic',
'ordering': ['-last_active', '-pk'],
'verbose_name_plural': 'topics',
},
),
]
operations = [
migrations.SeparateDatabaseAndState(
state_operations=state_operations)
]

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('spirit_topic', '0001_initial'),
]
operations = [
migrations.AlterModelTable(
name='topic',
table=None,
),
]

View File

View File

@ -37,7 +37,6 @@ class Topic(models.Model):
ordering = ['-last_active', '-pk']
verbose_name = _("topic")
verbose_name_plural = _("topics")
db_table = 'spirit_topic_topic' # TODO: remove in Spirit 0.4
def get_absolute_url(self):
if self.category_id == settings.ST_TOPIC_PRIVATE_CATEGORY_PK:

View File

@ -23,7 +23,7 @@ ACTION_CHOICES = (
class TopicNotification(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_("user"))
topic = models.ForeignKey('spirit.Topic')
topic = models.ForeignKey('spirit_topic.Topic')
comment = models.ForeignKey('spirit.Comment', null=True, blank=True)
date = models.DateTimeField(default=timezone.now)
@ -39,6 +39,7 @@ class TopicNotification(models.Model):
verbose_name = _("topic notification")
verbose_name_plural = _("topics notification")
db_table = 'spirit_notification_topicnotification' # TODO: remove in Spirit 0.4
app_label = 'spirit'
def get_absolute_url(self):
return self.comment.get_absolute_url()

View File

@ -10,7 +10,7 @@ from django.utils import timezone
class TopicPoll(models.Model):
topic = models.OneToOneField('spirit.Topic', verbose_name=_("topic"), primary_key=True, related_name='poll')
topic = models.OneToOneField('spirit_topic.Topic', verbose_name=_("topic"), primary_key=True, related_name='poll')
date = models.DateTimeField(default=timezone.now)
choice_limit = models.PositiveIntegerField(_("choice limit"), default=1)
@ -20,6 +20,7 @@ class TopicPoll(models.Model):
verbose_name = _("topic poll")
verbose_name_plural = _("topics polls")
db_table = 'spirit_poll_topicpoll' # TODO: remove in Spirit 0.4
app_label = 'spirit'
def get_absolute_url(self):
return self.topic.get_absolute_url()
@ -41,6 +42,7 @@ class TopicPollChoice(models.Model):
verbose_name = _("poll choice")
verbose_name_plural = _("poll choices")
db_table = 'spirit_poll_topicpollchoice' # TODO: remove in Spirit 0.4
app_label = 'spirit'
class TopicPollVote(models.Model):
@ -55,3 +57,4 @@ class TopicPollVote(models.Model):
verbose_name = _("poll vote")
verbose_name_plural = _("poll votes")
db_table = 'spirit_poll_topicpollvote' # TODO: remove in Spirit 0.4
app_label = 'spirit'

View File

@ -13,7 +13,7 @@ from .managers import TopicPrivateQuerySet
class TopicPrivate(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
topic = models.ForeignKey('spirit.Topic', related_name='topics_private')
topic = models.ForeignKey('spirit_topic.Topic', related_name='topics_private')
date = models.DateTimeField(default=timezone.now)
@ -25,6 +25,7 @@ class TopicPrivate(models.Model):
verbose_name = _("private topic")
verbose_name_plural = _("private topics")
db_table = 'spirit_private_topicprivate' # TODO: remove in Spirit 0.4
app_label = 'spirit'
def get_absolute_url(self):
return self.topic.get_absolute_url()

View File

@ -11,7 +11,7 @@ from django.utils import timezone
class TopicUnread(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_("user"))
topic = models.ForeignKey('spirit.Topic')
topic = models.ForeignKey('spirit_topic.Topic')
date = models.DateTimeField(default=timezone.now)
is_read = models.BooleanField(default=True)
@ -22,6 +22,7 @@ class TopicUnread(models.Model):
verbose_name = _("topic unread")
verbose_name_plural = _("topics unread")
db_table = 'spirit_unread_topicunread' # TODO: remove in Spirit 0.4
app_label = 'spirit'
def get_absolute_url(self):
return self.topic.get_absolute_url()