]> git.parisson.com Git - mezzo.git/commitdiff
use Slugged for various models
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 21 Jul 2016 11:56:26 +0000 (13:56 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 21 Jul 2016 11:56:26 +0000 (13:56 +0200)
app/organization/core/models.py
app/organization/media/admin.py
app/organization/media/migrations/0002_auto_20160721_1351.py [new file with mode: 0644]
app/organization/team/migrations/0007_auto_20160721_1351.py [new file with mode: 0644]
app/organization/team/models.py
app/organization/team/translation.py

index 24a295e8e87d16b4f7a2d175c7679b4e27ce8afd..241dee18639a5014194f3253369067a29ac0c8b7 100644 (file)
@@ -5,18 +5,27 @@ from django.core.urlresolvers import reverse, reverse_lazy
 
 from mezzanine.pages.models import Page, RichText
 from mezzanine.core.fields import RichTextField, OrderField, FileField
+from mezzanine.core.models import Displayable, Slugged
 
 
-class Named(models.Model):
+class Description(models.Model):
+    """Base object description"""
+
+    description = models.TextField(_('description'), blank=True)
+
+    class Meta:
+        abstract = True
+
+
+class Named(Description):
     """Named object with description"""
 
     name = models.CharField(_('name'), max_length=512)
-    description = models.TextField(_('description'), blank=True)
-    
+
     class Meta:
         abstract = True
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     @property
@@ -24,18 +33,12 @@ class Named(models.Model):
         return slugify(self.__unicode__())
 
 
-class Titled(models.Model):
-    """Base object with title and description"""
-
-    title = models.CharField(_('title'), max_length=512)
-    description = models.TextField(_('description'), blank=True)
+class Titled(Slugged, Description):
+    """Base object with title, slug and description"""
 
     class Meta:
         abstract = True
 
-    def __unicode__(self):
-        return self.title
-
 
 class SubTitle(models.Model):
 
index 9ea7f15c8bca76216bfd6acd0c0a854c577438cc..b3b71c97ce00b8e747deab72aeeb02068ed43fe1 100644 (file)
@@ -29,7 +29,7 @@ class AudioAdminDisplayable(DisplayableAdmin):
 class PlaylistAdmin(admin.ModelAdmin):
 
     model = Playlist
-    list_display = ('__unicode__',)
+    list_display = ('__str__',)
     filter_horizontal = ['audios']
 
 
diff --git a/app/organization/media/migrations/0002_auto_20160721_1351.py b/app/organization/media/migrations/0002_auto_20160721_1351.py
new file mode 100644 (file)
index 0000000..a7614ae
--- /dev/null
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-07-21 11:51
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('sites', '0002_alter_domain_unique'),
+        ('organization-media', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='playlist',
+            name='site',
+            field=models.ForeignKey(default=1, editable=False, on_delete=django.db.models.deletion.CASCADE, to='sites.Site'),
+            preserve_default=False,
+        ),
+        migrations.AddField(
+            model_name='playlist',
+            name='slug',
+            field=models.CharField(blank=True, help_text='Leave blank to have the URL auto-generated from the title.', max_length=2000, null=True, verbose_name='URL'),
+        ),
+        migrations.AlterField(
+            model_name='playlist',
+            name='title',
+            field=models.CharField(max_length=500, verbose_name='Title'),
+        ),
+    ]
diff --git a/app/organization/team/migrations/0007_auto_20160721_1351.py b/app/organization/team/migrations/0007_auto_20160721_1351.py
new file mode 100644 (file)
index 0000000..c3a6a37
--- /dev/null
@@ -0,0 +1,116 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-07-21 11:51
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('sites', '0002_alter_domain_unique'),
+        ('organization-team', '0006_auto_20160720_2136'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='department',
+            name='name',
+        ),
+        migrations.RemoveField(
+            model_name='department',
+            name='name_en',
+        ),
+        migrations.RemoveField(
+            model_name='department',
+            name='name_fr',
+        ),
+        migrations.RemoveField(
+            model_name='organization',
+            name='name',
+        ),
+        migrations.RemoveField(
+            model_name='team',
+            name='name',
+        ),
+        migrations.RemoveField(
+            model_name='team',
+            name='name_en',
+        ),
+        migrations.RemoveField(
+            model_name='team',
+            name='name_fr',
+        ),
+        migrations.AddField(
+            model_name='department',
+            name='site',
+            field=models.ForeignKey(default=1, editable=False, on_delete=django.db.models.deletion.CASCADE, to='sites.Site'),
+            preserve_default=False,
+        ),
+        migrations.AddField(
+            model_name='department',
+            name='slug',
+            field=models.CharField(blank=True, help_text='Leave blank to have the URL auto-generated from the title.', max_length=2000, null=True, verbose_name='URL'),
+        ),
+        migrations.AddField(
+            model_name='department',
+            name='title',
+            field=models.CharField(default='', max_length=500, verbose_name='Title'),
+            preserve_default=False,
+        ),
+        migrations.AddField(
+            model_name='department',
+            name='title_en',
+            field=models.CharField(max_length=500, null=True, verbose_name='Title'),
+        ),
+        migrations.AddField(
+            model_name='department',
+            name='title_fr',
+            field=models.CharField(max_length=500, null=True, verbose_name='Title'),
+        ),
+        migrations.AddField(
+            model_name='organization',
+            name='site',
+            field=models.ForeignKey(default=1, editable=False, on_delete=django.db.models.deletion.CASCADE, to='sites.Site'),
+            preserve_default=False,
+        ),
+        migrations.AddField(
+            model_name='organization',
+            name='slug',
+            field=models.CharField(blank=True, help_text='Leave blank to have the URL auto-generated from the title.', max_length=2000, null=True, verbose_name='URL'),
+        ),
+        migrations.AddField(
+            model_name='organization',
+            name='title',
+            field=models.CharField(default='', max_length=500, verbose_name='Title'),
+            preserve_default=False,
+        ),
+        migrations.AddField(
+            model_name='team',
+            name='site',
+            field=models.ForeignKey(default=1, editable=False, on_delete=django.db.models.deletion.CASCADE, to='sites.Site'),
+            preserve_default=False,
+        ),
+        migrations.AddField(
+            model_name='team',
+            name='slug',
+            field=models.CharField(blank=True, help_text='Leave blank to have the URL auto-generated from the title.', max_length=2000, null=True, verbose_name='URL'),
+        ),
+        migrations.AddField(
+            model_name='team',
+            name='title',
+            field=models.CharField(default='', max_length=500, verbose_name='Title'),
+            preserve_default=False,
+        ),
+        migrations.AddField(
+            model_name='team',
+            name='title_en',
+            field=models.CharField(max_length=500, null=True, verbose_name='Title'),
+        ),
+        migrations.AddField(
+            model_name='team',
+            name='title_fr',
+            field=models.CharField(max_length=500, null=True, verbose_name='Title'),
+        ),
+    ]
index ada1bab472ca37bc04940fdaa207b903c0e1b6b1..f187876bc37c9f76cea3e057150422ca882ba537 100644 (file)
@@ -20,7 +20,7 @@ from mezzanine.core.fields import RichTextField, OrderField, FileField
 from mezzanine.utils.models import AdminThumbMixin, upload_to
 
 from organization.media.models import Photo
-from organization.core.models import Named
+from organization.core.models import Named, Titled
 
 from django_countries.fields import CountryField
 from .nationalities.fields import NationalityField
@@ -52,23 +52,20 @@ class Address(models.Model):
     postal_code = models.CharField(_('postal code'), max_length=16, blank=True)
     country = CountryField(_('country'))
 
-    def __unicode__(self):
-        return u"Address"
+    def __str__(self):
+        return ' '.join((self.address, self.postal_code, self.country))
 
         class Meta:
             abstract = True
 
 
-class Organization(Named, Address, Photo):
+class Organization(Titled, Address, Photo):
     """(Organization description)"""
 
     type = models.ForeignKey('OrganizationType', verbose_name=_('organization type'), blank=True, null=True, on_delete=models.SET_NULL)
     url = models.URLField(_('URL'), max_length=512, blank=True)
     is_on_map = models.BooleanField(_('is on map'), default=True)
 
-    def __unicode__(self):
-        return self.name
-
     class Meta:
         verbose_name = _('organization')
 
@@ -80,21 +77,18 @@ class OrganizationType(Named):
         verbose_name = _('organization type')
 
 
-class Department(Named):
+class Department(Titled):
     """(Department description)"""
 
     organization = models.ForeignKey('Organization', verbose_name=_('organization'))
     url = models.URLField(_('URL'), max_length=512, blank=True)
     weaving_css_class = models.CharField(_('weaving CSS class'), max_length=64, blank=True)
 
-    def __unicode__(self):
-        return self.name
-
     class Meta:
         verbose_name = _('department')
 
 
-class Team(Named):
+class Team(Titled):
     """(Team description)"""
 
     department = models.ForeignKey('Department', verbose_name=_('department'), blank=True, null=True, on_delete=models.SET_NULL)
@@ -104,9 +98,6 @@ class Team(Named):
     class Meta:
         verbose_name = _('team')
 
-    def __unicode__(self):
-        return self.name
-
 
 class Person(AdminThumbMixin, Photo):
     """(Person description)"""
index 3dfc4c99506e9337b62d3d53331fef6d4150032d..4d4302e4e6883f79985cfcc677e1824d93f90fce 100644 (file)
@@ -12,13 +12,13 @@ class OrganizationTranslationOptions(TranslationOptions):
 @register(Department)
 class DepartmentTranslationOptions(TranslationOptions):
 
-    fields = ('name', 'description',)
+    fields = ('title', 'description',)
 
 
 @register(Team)
 class TeamTranslationOptions(TranslationOptions):
 
-    fields = ('name', 'description',)
+    fields = ('title', 'description',)
 
 
 @register(Person)