From 0100adcca74837ad7b2e7f6d5a416113e11e3fdb Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Sat, 2 Jan 2010 12:48:57 -0500 Subject: Adding pretty ordering --- .hgignore | 5 +++-- greenbox/recipe/models.py | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.hgignore b/.hgignore index dee9ae3..5ab741f 100644 --- a/.hgignore +++ b/.hgignore @@ -1,3 +1,4 @@ -glob:*.pyc -glob:*.db +syntax: glob +*.pyc +*.db nohup.out diff --git a/greenbox/recipe/models.py b/greenbox/recipe/models.py index 1c23eda..0718096 100755 --- a/greenbox/recipe/models.py +++ b/greenbox/recipe/models.py @@ -7,6 +7,9 @@ from django.db.models import ForeignKey class Unit(models.Model): + class Meta: + ordering = ('name',) + name = CharField(max_length=100) abbreviation = CharField(max_length=10, blank=True, null=True) @@ -16,6 +19,9 @@ class Unit(models.Model): 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) @@ -31,6 +37,9 @@ class Recipe(models.Model): class Ingredient(models.Model): + class Meta: + ordering = ('name',) + name = CharField(max_length=100, unique=True) def __unicode__(self): @@ -44,26 +53,33 @@ class RecipeIngredient(models.Model): quantity = FloatField() recipe = ForeignKey(Recipe) + def __unicode__(self): + return "{0} in {1}".format(self.ingredient.name, self.recipe.title) + class UnitAdmin(ModelAdmin): - list_display = ('abbreviation', 'name') + list_display = ('name', 'abbreviation') + ordering = ('name',) class IngredientInline(TabularInline): model = RecipeIngredient + extra = 12 class RecipeAdmin(ModelAdmin): list_display = ('title',) inlines = (IngredientInline,) + search_fields = ('title',) class IngredientAdmin(ModelAdmin): list_display = ('name',) + search_fields = ('name',) admin.site.register(Unit, UnitAdmin) -- cgit v1.2.3