add admin command to delete unattached ingredients and steps
This commit is contained in:
parent
711f80b1fb
commit
19750cf499
@ -10,12 +10,13 @@ from treebeard.forms import movenodeform_factory
|
|||||||
|
|
||||||
from cookbook.managers import DICTIONARY
|
from cookbook.managers import DICTIONARY
|
||||||
|
|
||||||
from .models import (BookmarkletImport, Comment, CookLog, Food, FoodInheritField, ImportLog,
|
from .models import (Automation, BookmarkletImport, Comment, CookLog, Food, FoodInheritField,
|
||||||
Ingredient, InviteLink, Keyword, MealPlan, MealType, NutritionInformation,
|
ImportLog, Ingredient, InviteLink, Keyword, MealPlan, MealType,
|
||||||
Recipe, RecipeBook, RecipeBookEntry, RecipeImport, SearchPreference, ShareLink,
|
NutritionInformation, Property, PropertyType, Recipe, RecipeBook,
|
||||||
ShoppingList, ShoppingListEntry, ShoppingListRecipe, Space, Step, Storage,
|
RecipeBookEntry, RecipeImport, SearchPreference, ShareLink, ShoppingList,
|
||||||
Supermarket, SupermarketCategory, SupermarketCategoryRelation, Sync, SyncLog,
|
ShoppingListEntry, ShoppingListRecipe, Space, Step, Storage, Supermarket,
|
||||||
TelegramBot, Unit, UserFile, UserPreference, ViewLog, Automation, UserSpace, UnitConversion, PropertyType, Property)
|
SupermarketCategory, SupermarketCategoryRelation, Sync, SyncLog, TelegramBot,
|
||||||
|
Unit, UnitConversion, UserFile, UserPreference, UserSpace, ViewLog)
|
||||||
|
|
||||||
|
|
||||||
class CustomUserAdmin(UserAdmin):
|
class CustomUserAdmin(UserAdmin):
|
||||||
@ -150,9 +151,16 @@ class KeywordAdmin(TreeAdmin):
|
|||||||
admin.site.register(Keyword, KeywordAdmin)
|
admin.site.register(Keyword, KeywordAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
@admin.action(description='Delete Steps not part of a Recipe.')
|
||||||
|
def delete_unattached_steps(modeladmin, request, queryset):
|
||||||
|
with scopes_disabled():
|
||||||
|
Step.objects.filter(recipe=None).delete()
|
||||||
|
|
||||||
|
|
||||||
class StepAdmin(admin.ModelAdmin):
|
class StepAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'order',)
|
list_display = ('name', 'order',)
|
||||||
search_fields = ('name',)
|
search_fields = ('name',)
|
||||||
|
actions = [delete_unattached_steps]
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Step, StepAdmin)
|
admin.site.register(Step, StepAdmin)
|
||||||
@ -209,9 +217,16 @@ class UnitConversionAdmin(admin.ModelAdmin):
|
|||||||
admin.site.register(UnitConversion, UnitConversionAdmin)
|
admin.site.register(UnitConversion, UnitConversionAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
@admin.action(description='Delete Ingredients not part of a Recipe.')
|
||||||
|
def delete_unattached_ingredients(modeladmin, request, queryset):
|
||||||
|
with scopes_disabled():
|
||||||
|
Ingredient.objects.filter(step__recipe=None).delete()
|
||||||
|
|
||||||
|
|
||||||
class IngredientAdmin(admin.ModelAdmin):
|
class IngredientAdmin(admin.ModelAdmin):
|
||||||
list_display = ('food', 'amount', 'unit')
|
list_display = ('food', 'amount', 'unit')
|
||||||
search_fields = ('food__name', 'unit__name')
|
search_fields = ('food__name', 'unit__name')
|
||||||
|
actions = [delete_unattached_ingredients]
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Ingredient, IngredientAdmin)
|
admin.site.register(Ingredient, IngredientAdmin)
|
||||||
|
Loading…
Reference in New Issue
Block a user