Hi, I'm having trouble with inlining models with a many-to-many relationship through the intermediary model. My models are recipes and categories (a category includes multiple recipes and a recipe can belong to multiple categories).
Models (simplified):
class Recipe(models.Model):
title = models.CharField(_('Title'), max_length=100, unique=True)
categories = models.ManyToManyField('Category', through='PairRecipeCategory', verbose_name=_('Categories'))
class Category(models.Model):
title = models.CharField(_('Title'), max_length=100, unique=True)
recipes = models.ManyToManyField('Recipe', through='PairRecipeCategory', verbose_name=_('Recipes'))
class PairRecipeCategory(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE)
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
Admin:
class RecipeInline(admin.TabularInline):
model = PairRecipeCategory
# fields = ['recipe__title']
class CategoryInline(admin.TabularInline):
model = PairRecipeCategory
# fields = ['category__title']
+ ordinary recipe and category ModelAdmin classes
What I want to do is to show
editable fields from the parent model (Recipe or Category) in the inlined PairRecipeCategory model instead of just listing the inlines. I get the "Unknown field for model xyz error" because the fields are not reachable from the intermediary model if I uncomment the fields lines.
I've read about this on StackOverflow and such and I could not find a working solution. If anyone has any (even hacky) ideas, I would really appreciate the help.