Add basic news model
authorCyprien Mangin <cyprien.mangin@m4x.org>
Sat, 2 Feb 2013 14:12:12 +0000 (15:12 +0100)
committerCyprien Mangin <cyprien.mangin@m4x.org>
Sat, 2 Feb 2013 14:23:26 +0000 (15:23 +0100)
Signed-off-by: Cyprien Mangin <cyprien.mangin@m4x.org>
requirements.txt
xnet/news/__init__.py [new file with mode: 0644]
xnet/news/admin.py [new file with mode: 0644]
xnet/news/factories.py [new file with mode: 0644]
xnet/news/models.py [new file with mode: 0644]
xnet/settings.py

index e7a7ee3..8c520f1 100644 (file)
@@ -1,3 +1,4 @@
 https://www.djangoproject.com/download/1.5c1/tarball/
 django_authgroupex
 django-xworkflows
+pil
diff --git a/xnet/news/__init__.py b/xnet/news/__init__.py
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/xnet/news/admin.py b/xnet/news/admin.py
new file mode 100644 (file)
index 0000000..d7cae64
--- /dev/null
@@ -0,0 +1,11 @@
+from django.contrib import admin
+
+from . import models
+
+
+class NewsAdmin(admin.ModelAdmin):
+    list_display = ['title', 'group', 'author', 'expiration', 'restricted']
+    list_filter = ['group', 'author']
+    search_fields = ['group__name', 'title', 'content', 'author__first_name', 'author__last_name', 'contacts']
+
+admin.site.register(models.News, NewsAdmin)
diff --git a/xnet/news/factories.py b/xnet/news/factories.py
new file mode 100644 (file)
index 0000000..1158152
--- /dev/null
@@ -0,0 +1,8 @@
+import factory
+
+from . import models
+
+
+class GroupFactory(factory.DjangoModelFactory):
+    FACTORY_FOR = models.News
+
diff --git a/xnet/news/models.py b/xnet/news/models.py
new file mode 100644 (file)
index 0000000..221d979
--- /dev/null
@@ -0,0 +1,29 @@
+# coding: utf-8
+
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+
+
+class News(models.Model):
+
+    title = models.CharField(max_length=200, verbose_name=u"titre")
+    content = models.TextField(verbose_name=u"contenu")
+    contacts = models.TextField(verbose_name=u"contacts", blank=True)
+    illustration = models.ImageField(upload_to='blah', verbose_name=u"illustration", null=True, blank=True)
+    expiration = models.DateField(verbose_name=u"date de péremption")
+    
+# TODO : attached_event = null
+    
+    restricted = models.BooleanField(default=True, verbose_name=u"visibilité restreinte")
+    promo_min = models.PositiveSmallIntegerField(verbose_name=u"promotion la plus ancienne", null=True, blank=True)
+    promo_max = models.PositiveSmallIntegerField(verbose_name=u"promotion la plus jeune", null=True, blank=True)
+    
+    author = models.ForeignKey('accounts.Account', related_name='+')
+    group = models.ForeignKey('accounts.XGroup', related_name='news')
+
+    class Meta:
+        verbose_name = _(u"news")
+        verbose_name_plural = _(u"news")
+
+    def __unicode__(self):
+        return self.title
index cc5b9b8..57eb721 100644 (file)
@@ -142,6 +142,7 @@ INSTALLED_APPS = (
     'django_authgroupex',
     'xnet.site',
     'xnet.accounts',
+    'xnet.news',
     'xnet.example',
 )