48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
from django.contrib import admin
|
|
from django.urls import reverse
|
|
from django.utils.html import format_html
|
|
from django.apps import apps
|
|
|
|
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
|
|
|
|
@admin.register(Recipe)
|
|
class RecipeAdmin(admin.ModelAdmin):
|
|
list_display = ['name']
|
|
|
|
@admin.register(BatchRecipe)
|
|
class BatchRecipeAdmin(admin.ModelAdmin):
|
|
list_display = ['name']
|
|
|
|
@admin.register(Batch)
|
|
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)
|
|
|
|
|
|
app = apps.get_app_config('beer')
|
|
for model_name, model in app.models.items():
|
|
|
|
try:
|
|
admin.site.register(model)
|
|
except admin.exceptions.AlreadyRegistered:
|
|
logger.critical(model)
|