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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c094f569-4cea-42cd-bd12-05f50e40c8f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to