Files @ cdf95f86ba07
Branch filter:

Location: django-shaker/djangoshaker/admin.py

branko
Forgot to provide all ingredients on the user's page.
from djangoshaker.models import Measure, Ingredient, Brand, MeasureConversion, Recipe, RecipeIngredient

from django.contrib import admin

def publish_recipe(modeladmin, request, queryset):
    """
    Action which publishes the select recipes on the admin page for Recipes.
    """

    for recipe in queryset:
        recipe.publish()

publish_recipe.short_description = "Publish selected recipes"

class RecipeIngredientInline(admin.TabularInline):
    """
    Defines the rendering for the administration of recipes.
    """

    model = RecipeIngredient
    extra = 3
    fields = ('amount', 'measure', 'ingredient')

class RecipeAdmin(admin.ModelAdmin):
    """
    Defines the rendering for the administration of recipes. Add the
    ingredient-recipe mapping to be show inline.
    """

    inlines = (RecipeIngredientInline, )
    actions = [publish_recipe]
    list_display = ('name', 'is_published')
    ordering = ['name']

class MeasureAdmin(admin.ModelAdmin):
    """
    Defines the rendering for the administration of measures.
    """

    ordering = ['name']

class IngredientAdmin(admin.ModelAdmin):
    """
    Defines the rendering for the administration of ingredients.
    """

    ordering = ['name']

class BrandAdmin(admin.ModelAdmin):
    """
    Defines the rendering for the administration of brands.
    """

    ordering = ['name']


admin.site.register(Measure, MeasureAdmin)
admin.site.register(Ingredient, IngredientAdmin)
admin.site.register(Brand, BrandAdmin)
admin.site.register(MeasureConversion)
admin.site.register(Recipe, RecipeAdmin)