Skip to content

Commit

Permalink
Add optional thumbnail model field.
Browse files Browse the repository at this point in the history
  • Loading branch information
eculver authored and coordt committed May 8, 2011
1 parent cda1d0f commit 1ac5ae0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions categories/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CategoryAdmin(TreeEditor, admin.ModelAdmin):
prepopulated_fields = {'slug': ('name',)}
fieldsets = (
(None, {
'fields': ('parent', 'name')
'fields': ('parent', 'name', 'thumbnail')
}),
('Meta Data', {
'fields': ('alternate_title', 'description', 'meta_keywords', 'meta_extra'),
Expand Down Expand Up @@ -117,4 +117,4 @@ class Media:
'fieldsets': fieldsets + (('Categories',{
'fields': fields
}),)
}))
}))
3 changes: 3 additions & 0 deletions categories/migration/add_thumbnail.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BEGIN;
ALTER TABLE "categories_category" ADD COLUMN "thumbnail" varchar(100);
COMMIT;
3 changes: 2 additions & 1 deletion categories/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from mptt.models import MPTTModel

from settings import RELATION_MODELS, RELATIONS
from settings import RELATION_MODELS, RELATIONS, THUMBNAIL_UPLOAD_PATH

class Category(MPTTModel):
parent = models.ForeignKey('self',
Expand All @@ -19,6 +19,7 @@ class Category(MPTTModel):
help_text="Leave this blank for an Category Tree",
verbose_name='Parent')
name = models.CharField(max_length=100)
thumbnail = models.ImageField(upload_to=THUMBNAIL_UPLOAD_PATH, null=True, blank=True)
order = models.IntegerField(blank=True, null=True)
slug = models.SlugField()
alternate_title = models.CharField(
Expand Down
3 changes: 3 additions & 0 deletions categories/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
DEFAULT_RELATION_MODELS = []
RELATION_MODELS = getattr(settings, 'CATEGORIES_RELATION_MODELS', DEFAULT_RELATION_MODELS) or []
RELATIONS = [Q(app_label=al, model=m) for al, m in [x.split('.') for x in RELATION_MODELS]]

# For assigning a thumbnail to a category
THUMBNAIL_UPLOAD_PATH = getattr(settings, 'CATEGORIES_THUMBNAIL_UPLOAD_PATH', 'uploads/categories/thumbnails')

0 comments on commit 1ac5ae0

Please sign in to comment.