Skip to content

Commit

Permalink
Added metadata to the model for seo stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Oordt committed Apr 22, 2010
1 parent 0b27adc commit 031c328
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
19 changes: 19 additions & 0 deletions categories/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def clean_slug(self):
self.cleaned_data['slug'] = slugify(self.cleaned_data['name'])
return self.cleaned_data['slug']

def clean_alternate_title(self):
if self.instance is None or not self.cleaned_data['alternate_title']:
return self.cleaned_data['name']
else:
return self.cleaned_data['alternate_title']

def clean(self):
super(CategoryAdminForm, self).clean()

Expand Down Expand Up @@ -65,6 +71,19 @@ class CategoryAdmin(TreeEditor, admin.ModelAdmin):
list_display = ('__unicode__',)
search_fields = (('name',))
prepopulated_fields = {'slug': ('name',)}
fieldsets = (
(None, {
'fields': ('parent', 'name')
}),
('Meta Data', {
'fields': ('alternate_title', 'description', 'meta_keywords', 'meta_extra'),
'classes': ('collapse',),
}),
('Advanced', {
'fields': ('order', 'slug'),
'classes': ('collapse',),
}),
)


admin.site.register(Category, CategoryAdmin)
Expand Down
6 changes: 6 additions & 0 deletions categories/migration/2add_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN;
ALTER TABLE "categories_category" ADD COLUMN "alternate_title" varchar(100);
ALTER TABLE "categories_category" ADD COLUMN "meta_keywords" varchar(255);
ALTER TABLE "categories_category" ADD COLUMN "meta_extra" text;
ALTER TABLE "categories_category" ALTER COLUMN "description" TYPE text;
COMMIT;
6 changes: 6 additions & 0 deletions categories/migration/2drop_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN;
ALTER TABLE "categories_category" DROP COLUMN "alternate_title" varchar(100);
ALTER TABLE "categories_category" DROP COLUMN "meta_keywords" varchar(255);
ALTER TABLE "categories_category" DROP COLUMN "meta_extra" text;
ALTER TABLE "categories_category" ALTER COLUMN "description" TYPE varchar(255);
COMMIT;
18 changes: 17 additions & 1 deletion categories/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,25 @@ class Category(models.Model):
help_text="Leave this blank for an Category Tree",
verbose_name='Parent')
name = models.CharField(max_length=100)
description = models.CharField(blank=True, null=True, max_length=255)
order = models.IntegerField(blank=True, null=True)
slug = models.SlugField()
alternate_title = models.CharField(
blank=True,
default="",
max_length=100,
help_text="An alternative title to use on pages with this category."
)
description = models.TextField(blank=True, null=True)
meta_keywords = models.CharField(
blank=True,
default="",
max_length=255,
help_text="Comma-separated keywords for search engines.")
meta_extra = models.TextField(
blank=True,
default="",
help_text="(Advanced) Any additional HTML to be placed verbatim in the <head>")


def get_absolute_url(self):
"""Return a path"""
Expand Down

0 comments on commit 031c328

Please sign in to comment.