From 5fd79049673e5cd27dc2de828cf7c6d2560aea1f Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Thu, 30 Dec 2010 01:07:57 -0500 Subject: Cleaning up model imports and adding slug field --- greenbox/recipe/models.py | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/greenbox/recipe/models.py b/greenbox/recipe/models.py index b4925cd..8463447 100644 --- a/greenbox/recipe/models.py +++ b/greenbox/recipe/models.py @@ -1,9 +1,6 @@ -from django.contrib import admin -from django.contrib.admin import sites as admin_sites -from django.contrib.admin import ModelAdmin, TabularInline from django.db import models -from django.db.models import CharField, IntegerField, TextField, FloatField -from django.db.models import ForeignKey +from django.contrib import admin +from django.db.models import fields class Unit(models.Model): @@ -11,8 +8,8 @@ class Unit(models.Model): class Meta: ordering = ('name',) - name = CharField(max_length=100) - abbreviation = CharField(max_length=10, blank=True, null=True) + name = fields.CharField(max_length=100) + abbreviation = fields.CharField(max_length=10, blank=True, null=True) def __unicode__(self): return "{0} ({1})".format(self.name, self.abbreviation) @@ -23,13 +20,14 @@ class Recipe(models.Model): class Meta: ordering = ('title',) - title = CharField(max_length=100) - description = TextField(blank=True, null=True) - servings = IntegerField(blank=True, null=True) - instructions = TextField() - oven_temp = IntegerField(blank=True, null=True) - cook_time = IntegerField(blank=True, null=True) - prep_time = IntegerField(blank=True, null=True) + title = fields.CharField(max_length=100) + slug = fields.SlugField(max_length=150) + description = fields.TextField(blank=True, null=True) + servings = fields.IntegerField(blank=True, null=True) + instructions = fields.TextField() + oven_temp = fields.IntegerField(blank=True, null=True) + cook_time = fields.IntegerField(blank=True, null=True) + prep_time = fields.IntegerField(blank=True, null=True) def __unicode__(self): @@ -41,7 +39,7 @@ class Ingredient(models.Model): class Meta: ordering = ('name',) - name = CharField(max_length=100, unique=True) + name = fields.CharField(max_length=100, unique=True) def __unicode__(self): return self.name @@ -49,35 +47,36 @@ class Ingredient(models.Model): class RecipeIngredient(models.Model): - ingredient = ForeignKey(Ingredient) - units = ForeignKey(Unit) - quantity = FloatField() - recipe = ForeignKey(Recipe) + ingredient = models.ForeignKey(Ingredient) + units = models.ForeignKey(Unit) + quantity = fields.FloatField() + recipe = models.ForeignKey(Recipe) def __unicode__(self): return "{0} in {1}".format(self.ingredient.name, self.recipe.title) -class UnitAdmin(ModelAdmin): +class UnitAdmin(admin.ModelAdmin): list_display = ('name', 'abbreviation') ordering = ('name',) -class IngredientInline(TabularInline): +class IngredientInline(admin.TabularInline): model = RecipeIngredient extra = 12 -class RecipeAdmin(ModelAdmin): +class RecipeAdmin(admin.ModelAdmin): list_display = ('title',) inlines = (IngredientInline,) search_fields = ('title',) + prepopulated_fields = { "slug": ("title",) } -class IngredientAdmin(ModelAdmin): +class IngredientAdmin(admin.ModelAdmin): list_display = ('name',) search_fields = ('name',) @@ -87,5 +86,5 @@ try: admin.site.register(Unit, UnitAdmin) admin.site.register(Ingredient, IngredientAdmin) admin.site.register(Recipe, RecipeAdmin) -except admin_sites.AlreadyRegistered: +except admin.sites.AlreadyRegistered: pass -- cgit v1.2.3