File tree Expand file tree Collapse file tree 5 files changed +35
-6
lines changed
examples/cookbook/cookbook Expand file tree Collapse file tree 5 files changed +35
-6
lines changed Original file line number Diff line number Diff line change 2
2
3
3
from cookbook .ingredients .models import Category , Ingredient
4
4
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
+
6
10
admin .site .register (Category )
Original file line number Diff line number Diff line change
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
+ ]
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ def __str__(self):
10
10
11
11
class Ingredient (models .Model ):
12
12
name = models .CharField (max_length = 100 )
13
- notes = models .TextField ()
13
+ notes = models .TextField (null = True , blank = True )
14
14
category = models .ForeignKey (Category , related_name = 'ingredients' )
15
15
16
16
def __str__ (self ):
Original file line number Diff line number Diff line change 2
2
3
3
from cookbook .recipes .models import Recipe , RecipeIngredient
4
4
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 ]
Original file line number Diff line number Diff line change 6
6
class Recipe (models .Model ):
7
7
title = models .CharField (max_length = 100 )
8
8
instructions = models .TextField ()
9
-
9
+ __unicode__ = lambda self : self . title
10
10
11
11
class RecipeIngredient (models .Model ):
12
12
recipes = models .ForeignKey (Recipe , related_name = 'amounts' )
13
13
ingredient = models .ForeignKey (Ingredient , related_name = 'used_by' )
14
14
amount = models .FloatField ()
15
15
unit = models .CharField (max_length = 20 , choices = (
16
+ ('unit' , 'Units' ),
16
17
('kg' , 'Kilograms' ),
17
18
('l' , 'Litres' ),
18
- ('' , 'Units ' ),
19
+ ('st ' , 'Shots ' ),
19
20
))
You can’t perform that action at this time.
0 commit comments