Skip to content

Commit 0ceef46

Browse files
committed
a few admin changes to make entering data easier
1 parent 5ac046a commit 0ceef46

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

examples/cookbook/cookbook/ingredients/admin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22

33
from cookbook.ingredients.models import Category, Ingredient
44

5-
admin.site.register(Ingredient)
5+
@admin.register(Ingredient)
6+
class IngredientAdmin(admin.ModelAdmin):
7+
list_display = ("id","name","category")
8+
list_editable = ("name","category")
9+
610
admin.site.register(Category)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9 on 2016-11-04 00:50
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('ingredients', '0001_initial'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='ingredient',
17+
name='notes',
18+
field=models.TextField(blank=True, null=True),
19+
),
20+
]

examples/cookbook/cookbook/ingredients/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def __str__(self):
1010

1111
class Ingredient(models.Model):
1212
name = models.CharField(max_length=100)
13-
notes = models.TextField()
13+
notes = models.TextField(null=True,blank=True)
1414
category = models.ForeignKey(Category, related_name='ingredients')
1515

1616
def __str__(self):

examples/cookbook/cookbook/recipes/admin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22

33
from cookbook.recipes.models import Recipe, RecipeIngredient
44

5-
admin.site.register(Recipe)
6-
admin.site.register(RecipeIngredient)
5+
class RecipeIngredientInline(admin.TabularInline):
6+
model = RecipeIngredient
7+
8+
@admin.register(Recipe)
9+
class RecipeAdmin(admin.ModelAdmin):
10+
inlines = [RecipeIngredientInline]

examples/cookbook/cookbook/recipes/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
class Recipe(models.Model):
77
title = models.CharField(max_length=100)
88
instructions = models.TextField()
9-
9+
__unicode__ = lambda self: self.title
1010

1111
class RecipeIngredient(models.Model):
1212
recipes = models.ForeignKey(Recipe, related_name='amounts')
1313
ingredient = models.ForeignKey(Ingredient, related_name='used_by')
1414
amount = models.FloatField()
1515
unit = models.CharField(max_length=20, choices=(
16+
('unit', 'Units'),
1617
('kg', 'Kilograms'),
1718
('l', 'Litres'),
18-
('', 'Units'),
19+
('st', 'Shots'),
1920
))

0 commit comments

Comments
 (0)