Adding covers: make source_url field not required
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 10 Oct 2013 08:10:58 +0000 (10:10 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 10 Oct 2013 08:10:58 +0000 (10:10 +0200)
apps/cover/forms.py
apps/cover/migrations/0003_auto__chg_field_image_source_url.py [new file with mode: 0644]
apps/cover/models.py

index 67a0c53..4c71886 100755 (executable)
@@ -15,11 +15,14 @@ class ImageAddForm(forms.ModelForm):
 
     def __init__(self, *args, **kwargs):
         super(ImageAddForm, self).__init__(*args, **kwargs)
 
     def __init__(self, *args, **kwargs):
         super(ImageAddForm, self).__init__(*args, **kwargs)
-        self.fields['file'].required = self.fields['download_url'].required = False
+        self.fields['file'].required = self.fields['download_url'].required = self.fields['source_url'].required = False
 
     def clean_download_url(self):
         return self.cleaned_data['download_url'] or None
 
 
     def clean_download_url(self):
         return self.cleaned_data['download_url'] or None
 
+    def clean_source_url(self):
+        return self.cleaned_data['source_url'] or None
+
     def clean(self):
         cleaned_data = super(ImageAddForm, self).clean()
         if not cleaned_data.get('download_url', None) and not cleaned_data.get('file', None):
     def clean(self):
         cleaned_data = super(ImageAddForm, self).clean()
         if not cleaned_data.get('download_url', None) and not cleaned_data.get('file', None):
diff --git a/apps/cover/migrations/0003_auto__chg_field_image_source_url.py b/apps/cover/migrations/0003_auto__chg_field_image_source_url.py
new file mode 100644 (file)
index 0000000..98951e3
--- /dev/null
@@ -0,0 +1,34 @@
+# -*- 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):
+
+        # Changing field 'Image.source_url'
+        db.alter_column(u'cover_image', 'source_url', self.gf('django.db.models.fields.URLField')(max_length=200, null=True))
+
+    def backwards(self, orm):
+
+        # User chose to not deal with backwards NULL issues for 'Image.source_url'
+        raise RuntimeError("Cannot reverse this migration. 'Image.source_url' and its values cannot be restored.")
+
+    models = {
+        u'cover.image': {
+            'Meta': {'object_name': 'Image'},
+            'author': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'download_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'unique': 'True', 'null': 'True'}),
+            'file': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'license_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'license_url': ('django.db.models.fields.URLField', [], {'max_length': '255', 'blank': 'True'}),
+            'source_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        }
+    }
+
+    complete_apps = ['cover']
\ No newline at end of file
index 5574f34..d4432c2 100644 (file)
@@ -20,7 +20,7 @@ class Image(models.Model):
     author = models.CharField(max_length=255, verbose_name=_('author'))
     license_name = models.CharField(max_length=255, verbose_name=_('license name'))
     license_url = models.URLField(max_length=255, blank=True, verbose_name=_('license URL'))
     author = models.CharField(max_length=255, verbose_name=_('author'))
     license_name = models.CharField(max_length=255, verbose_name=_('license name'))
     license_url = models.URLField(max_length=255, blank=True, verbose_name=_('license URL'))
-    source_url = models.URLField(verbose_name=_('source URL'))
+    source_url = models.URLField(verbose_name=_('source URL'), null = True)
     download_url = models.URLField(unique=True, verbose_name=_('image download URL'), null = True)
     file = models.ImageField(upload_to='cover/image', editable=True, verbose_name=_('file'))
 
     download_url = models.URLField(unique=True, verbose_name=_('image download URL'), null = True)
     file = models.ImageField(upload_to='cover/image', editable=True, verbose_name=_('file'))