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, BatchRecipe, BatchRecipe from yeast.models import Yeast from config.extras import BREWFATHER_APP_ROOT class SampleInline(admin.TabularInline): model = Yeast extra = 0 @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 = "Brewfather Batch ID: {batch_id}" def batch_url(self, obj): bf_id = obj.brewfather_id return format_html("Brewfather App: {batch_id}", 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: pass