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 = "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) admin.site.register(Batch, BeerBatchAdmin) admin.site.register(Recipe, RecipeAdmin) admin.site.register(BatchRecipe, BatchRecipeAdmin)