Commits

Guilherme Gondim committed ad3c6bf

Remove unique constraint between album_id and slug in Picture mode and improve
Picture URL

Comments (0)

Files changed (4)

galeria/migrations/0004_auto__del_unique_picture_album_slug.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Removing unique constraint on 'Picture', fields ['album', 'slug']
+        db.delete_unique('galeria_picture', ['album_id', 'slug'])
+
+
+    def backwards(self, orm):
+        # Adding unique constraint on 'Picture', fields ['album', 'slug']
+        db.create_unique('galeria_picture', ['album_id', 'slug'])
+
+
+    models = {
+        'galeria.album': {
+            'Meta': {'unique_together': "(('slug', 'parent'),)", 'object_name': 'Album'},
+            'cover': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'cover'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['galeria.Picture']"}),
+            'date_added': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_public': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'order': ('django.db.models.fields.CharField', [], {'default': "'-date_added'", 'max_length': '16'}),
+            'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['galeria.Album']"}),
+            'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '256'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+            'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+        },
+        'galeria.picture': {
+            'Meta': {'ordering': "('-date_added',)", 'object_name': 'Picture'},
+            'album': ('mptt.fields.TreeForeignKey', [], {'related_name': "'pictures'", 'to': "orm['galeria.Album']"}),
+            'date_added': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'date_modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'date_taken': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_public': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'original_image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '256'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '256'})
+        }
+    }
+
+    complete_apps = ['galeria']

galeria/models.py

         get_latest_by = 'date_added'
         verbose_name = _('picture')
         verbose_name_plural = _('pictures')
-        unique_together = (('slug', 'album'),)
 
     @property
     def EXIF(self):
     @models.permalink
     def get_absolute_url(self):
         return ('galeria-picture', None, {
-            'year' : str(self.date_added.year),
-            'month': str(self.date_added.month).zfill(2),
-            'day'  : str(self.date_added.day).zfill(2),
+            'album_slug' : str(self.album.slug),
+            'pk' : str(self.pk),
             'slug' : str(self.slug)
         })
 
 urlpatterns = patterns('',
     url(
-        '^(?P<year>\d{4})/(?P<month>[0-9]{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',
+        '(?P<album_slug>[-\w]+)/(?P<pk>[0-9]+)/(?P<slug>[-\w]+)/$',
         views.PictureDetail.as_view(),
         name='galeria-picture'
     ),
     url(
-        '^album/(?P<slug>[-\w]+)/$',
+        '^(?P<slug>[-\w]+)/$',
         views.AlbumDetail.as_view(),
         name='galeria-album'
     ),
     paginate_by = 20
 
 
-class PictureDetail(generic.dates.DateDetailView):
-    date_field = 'date_added'
+class PictureDetail(generic.detail.DetailView):
     model = Picture
-    month_format = '%m'
-    slug_field = 'slug'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.