86 lines
1.8 KiB
Python
86 lines
1.8 KiB
Python
from django.contrib import admin
|
|
from django.utils.html import format_html
|
|
from django.apps import apps
|
|
|
|
from beer.models import Batch, BatchRecipe, Mash, MashStep, \
|
|
RecipeFermentable, RecipeHop, RecipeMisc, RecipeYeast
|
|
from yeast.models import Yeast
|
|
|
|
from config.extras import BREWFATHER_APP_ROOT
|
|
|
|
|
|
class SampleInline(admin.TabularInline):
|
|
model = Yeast
|
|
extra = 0
|
|
|
|
|
|
class FermentableInline(admin.TabularInline):
|
|
model = RecipeFermentable
|
|
extra = 1
|
|
|
|
|
|
class HopInline(admin.TabularInline):
|
|
model = RecipeHop
|
|
extra = 1
|
|
|
|
|
|
class MiscInline(admin.TabularInline):
|
|
model = RecipeMisc
|
|
extra = 1
|
|
|
|
|
|
class StrainInline(admin.TabularInline):
|
|
model = RecipeYeast
|
|
extra = 1
|
|
|
|
|
|
@admin.register(BatchRecipe)
|
|
class BatchRecipeAdmin(admin.ModelAdmin):
|
|
list_display = ['name']
|
|
inlines = [
|
|
FermentableInline,
|
|
HopInline,
|
|
MiscInline,
|
|
StrainInline
|
|
]
|
|
|
|
|
|
@admin.register(Batch)
|
|
class BeerBatchAdmin(admin.ModelAdmin):
|
|
list_display = ['brewfather_id', 'batch_url']
|
|
inlines = [
|
|
SampleInline,
|
|
]
|
|
|
|
def batch_url(self, obj):
|
|
url_string = ('<a href="{root}/tabs/batches/batch/{batch_id}">'
|
|
'Brewfather Batch ID: {batch_id}</a>')
|
|
bf_id = obj.brewfather_id
|
|
return format_html(
|
|
url_string,
|
|
batch_id=bf_id,
|
|
root=BREWFATHER_APP_ROOT
|
|
)
|
|
|
|
|
|
class MashStepInline(admin.TabularInline):
|
|
model = MashStep
|
|
extra = 1
|
|
|
|
|
|
@admin.register(Mash)
|
|
class MashAdmin(admin.ModelAdmin):
|
|
list_display = ['name', ]
|
|
inlines = [
|
|
MashStepInline,
|
|
]
|
|
|
|
|
|
app = apps.get_app_config('beer')
|
|
for model_name, model in app.models.items():
|
|
|
|
try:
|
|
admin.site.register(model)
|
|
except admin.exceptions.AlreadyRegistered:
|
|
pass
|