Try writing an admin action to clone a brew...
This commit is contained in:
parent
2dd52d1a33
commit
bfa660f53c
1 changed files with 28 additions and 0 deletions
|
|
@ -44,3 +44,31 @@ class BrewAdmin(admin.ModelAdmin):
|
|||
|
||||
list_display = ["name", "style", "pitch_date"]
|
||||
date_hierarchy = "pitch_date"
|
||||
|
||||
actions = ["clone"]
|
||||
|
||||
@admin.action(description="I brewed another one of these")
|
||||
def clone(self, request, queryset):
|
||||
for brew in queryset:
|
||||
malt_additions = brew.maltaddition_set.all()
|
||||
fermentable_additions = brew.fermentableaddition_set.all()
|
||||
hop_additions = brew.hopaddition_set.all()
|
||||
chemical_additions = brew.chemicaladdition_set.all()
|
||||
yeast_additions = brew.yeastaddition_set.all()
|
||||
|
||||
brew.pk = None
|
||||
brew.save()
|
||||
|
||||
for add_type in (
|
||||
malt_additions,
|
||||
fermentable_additions,
|
||||
hop_additions,
|
||||
chemical_additions,
|
||||
yeast_additions
|
||||
):
|
||||
for addition in add_type:
|
||||
addition.pk = None
|
||||
addition.brew_id = brew.pk
|
||||
addition.save()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue