Docs: Update Cookbook tutorial

This commit is contained in:
Stefan Stammberger 2017-12-02 19:35:17 +01:00 committed by GitHub
parent 24706f50d4
commit 443b5eaafc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -68,7 +68,8 @@ Let's get started with these models:
class Ingredient(models.Model):
name = models.CharField(max_length=100)
notes = models.TextField()
category = models.ForeignKey(Category, related_name='ingredients')
category = models.ForeignKey(
Category, related_name='ingredients', on_delete=models.CASCADE)
def __str__(self):
return self.name
@ -80,9 +81,21 @@ Add ingredients as INSTALLED_APPS:
INSTALLED_APPS = [
...
# Install the ingredients app
'ingredients',
'cookbook.ingredients',
]
Register models with admin panel:
.. code:: python
# cookbook/ingredients/admin.py
from django.contrib import admin
from cookbook.ingredients.models import Category, Ingredient
admin.site.register(Category)
admin.site.register(Ingredient)
Don't forget to create & run migrations:
.. code:: bash