116 lines
2.5 KiB
Python
116 lines
2.5 KiB
Python
from django.contrib import admin
|
|
from django.utils.html import format_html
|
|
from django.apps import apps
|
|
|
|
from beer.models import Batch, Recipe, Mash, MashStep, \
|
|
RecipeFermentable, RecipeHop, RecipeMisc, RecipeYeast
|
|
from yeast.models import Yeast
|
|
|
|
from config.extras import BREWFATHER_APP_ROOT
|
|
from beer.extras import plato_sg
|
|
|
|
|
|
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(Recipe)
|
|
class RecipeAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'total_extract_kg']
|
|
inlines = [
|
|
FermentableInline,
|
|
HopInline,
|
|
MiscInline,
|
|
StrainInline
|
|
]
|
|
|
|
|
|
@admin.register(Batch)
|
|
class BeerBatchAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
'brewfather_id',
|
|
'batch_url',
|
|
'brewhouse_efficiency',
|
|
'conversion_efficiency',
|
|
]
|
|
inlines = [
|
|
SampleInline,
|
|
]
|
|
|
|
fieldsets = [
|
|
[None, {
|
|
'fields': [
|
|
('brewfather_id', 'brewfather_num', 'brewfather_name'),
|
|
'recipe',
|
|
]
|
|
}],
|
|
['Mash', {
|
|
'fields': ['first_runnings', 'mash_ph'],
|
|
}],
|
|
['Boil', {
|
|
'fields': [
|
|
('pre_boil_vol', 'pre_boil_sg'),
|
|
('post_boil_vol', 'post_boil_sg'),
|
|
],
|
|
}],
|
|
['Ferment', {
|
|
'fields': [
|
|
('fermenter_topup_vol', 'fermenter_vol'),
|
|
('original_sg', 'final_sg'),
|
|
],
|
|
}],
|
|
]
|
|
|
|
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
|