brewery-website/beer/admin.py
2024-05-30 16:26:55 -04:00

39 lines
1.1 KiB
Python

from django.contrib import admin
from django.urls import reverse
from django.utils.html import format_html
from beer.models import Batch, Recipe, BatchRecipe
from yeast.models import Yeast
from config.extras import BREWFATHER_APP_ROOT
import logging
logger = logging.getLogger('django')
class SampleInline(admin.TabularInline):
model = Yeast
extra = 0
class RecipeAdmin(admin.ModelAdmin):
list_display = ['name']
class BatchRecipeAdmin(admin.ModelAdmin):
list_display = ['name']
class BeerBatchAdmin(admin.ModelAdmin):
list_display = ['brewfather_id', 'batch_url']
inlines = [
SampleInline,
]
url_string = "<a href='{root}/tabs/batches/batch/{batch_id}'>Brewfather Batch ID: {batch_id}</a>"
def batch_url(self, obj):
bf_id = obj.brewfather_id
return format_html("<a href='{root}/tabs/batches/batch/{batch_id}'>Brewfather App: {batch_id}</a>", batch_id=bf_id, root=BREWFATHER_APP_ROOT)
admin.site.register(Batch, BeerBatchAdmin)
admin.site.register(Recipe, RecipeAdmin)
admin.site.register(BatchRecipe, BatchRecipeAdmin)