Commit 8ae7f9f5 authored by fred's avatar fred
Browse files

add an image field to emissions and episodes (#1080)

parent c0fdbaaa
# -*- 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):
# Adding field 'Episode.image'
db.add_column(u'emissions_episode', 'image',
self.gf('django.db.models.fields.files.ImageField')(max_length=250, null=True, blank=True),
keep_default=False)
# Adding field 'Emission.image'
db.add_column(u'emissions_emission', 'image',
self.gf('django.db.models.fields.files.ImageField')(max_length=250, null=True, blank=True),
keep_default=False)
def backwards(self, orm):
# Deleting field 'Episode.image'
db.delete_column(u'emissions_episode', 'image')
# Deleting field 'Emission.image'
db.delete_column(u'emissions_emission', 'image')
models = {
u'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
u'emissions.category': {
'Meta': {'object_name': 'Category'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'emissions.diffusion': {
'Meta': {'object_name': 'Diffusion'},
'datetime': ('django.db.models.fields.DateTimeField', [], {}),
'episode': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['emissions.Episode']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
u'emissions.emission': {
'Meta': {'object_name': 'Emission'},
'archived': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'categories': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['emissions.Category']", 'symmetrical': 'False'}),
'description': ('ckeditor.fields.RichTextField', [], {'null': 'True', 'blank': 'True'}),
'duration': ('django.db.models.fields.IntegerField', [], {'default': '60'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '254', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
'text': ('ckeditor.fields.RichTextField', [], {'null': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'})
},
u'emissions.episode': {
'Meta': {'object_name': 'Episode'},
'description': ('ckeditor.fields.RichTextField', [], {'null': 'True', 'blank': 'True'}),
'emission': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['emissions.Emission']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
'text': ('ckeditor.fields.RichTextField', [], {'null': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'emissions.schedule': {
'Meta': {'object_name': 'Schedule'},
'datetime': ('django.db.models.fields.DateTimeField', [], {}),
'emission': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['emissions.Emission']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'rerun': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
},
u'emissions.soundfile': {
'Meta': {'object_name': 'SoundFile'},
'episode': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['emissions.Episode']"}),
'file': ('django.db.models.fields.files.FileField', [], {'max_length': '250'}),
'fragment': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'podcastable': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'taggit.tag': {
'Meta': {'object_name': 'Tag'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'})
},
u'taggit.taggeditem': {
'Meta': {'object_name': 'TaggedItem'},
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "u'taggit_taggeditem_tagged_items'", 'to': u"orm['contenttypes.ContentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "u'taggit_taggeditem_items'", 'to': u"orm['taggit.Tag']"})
}
}
complete_apps = ['emissions']
\ No newline at end of file
......@@ -20,6 +20,11 @@ class Category(models.Model):
return self.title
def get_emission_image_path(instance, filename):
return os.path.join('images', instance.emission.slug,
os.path.basename(filename))
class Emission(models.Model):
title = models.CharField(max_length=50)
slug = models.SlugField()
......@@ -35,6 +40,8 @@ class Emission(models.Model):
email = models.EmailField(max_length=254, null=True, blank=True)
website = models.URLField(null=True, blank=True)
image = models.ImageField(upload_to=get_emission_image_path, max_length=250, null=True, blank=True)
def get_absolute_url(self):
return reverse('emission-view', kwargs={'slug': str(self.slug)})
......@@ -64,6 +71,11 @@ class Schedule(models.Model):
return False
def get_episode_image_path(instance, filename):
return os.path.join('images', instance.episode.emission.slug,
os.path.basename(filename))
class Episode(models.Model):
emission = models.ForeignKey('Emission', verbose_name=u'Emission')
title = models.CharField(max_length=50)
......@@ -72,6 +84,8 @@ class Episode(models.Model):
text = RichTextField(null=True)
tags = TaggableManager(blank=True)
image = models.ImageField(upload_to=get_episode_image_path, max_length=250, null=True, blank=True)
# XXX: languages (models.ManyToManyField(Language))
def __unicode__(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment