Django 1.2.1 Inline Admin for Many To Many Fields Django 1.2.1 Inline Admin for Many To Many Fields django django

Django 1.2.1 Inline Admin for Many To Many Fields


Do one of these examples accomplish what you are trying to do?

a:

# Models:class Ingredient(models.Model):    name = models.CharField(max_length=128)class Recipe(models.Model):    name = models.CharField(max_length=128)    ingredients = models.ManyToManyField(Ingredient, through='RecipeIngredient')class RecipeIngredient(models.Model):    recipe = models.ForeignKey(Recipe)    ingredient = models.ForeignKey(Ingredient)    amount = models.CharField(max_length=128)# Admin:class RecipeIngredientInline(admin.TabularInline):    model = Recipe.ingredients.throughclass RecipeAdmin(admin.ModelAdmin):    inlines = [RecipeIngredientInline,]class IngredientAdmin(admin.ModelAdmin):    passadmin.site.register(Recipe,RecipeAdmin)admin.site.register(Ingredient, IngredientAdmin)

b:

# Models:class Recipe(models.Model):    name = models.CharField(max_length=128)class Ingredient(models.Model):    name = models.CharField(max_length=128)    recipe = models.ForeignKey(Recipe)# Admin:class IngredientInline(admin.TabularInline):    model = Ingredientclass RecipeAdmin(admin.ModelAdmin):    inlines = [IngredientInline,]admin.site.register(Recipe,RecipeAdmin)


If I remember correctly (and it's been a while since I've done this part), you need to add the admin for Ingredient and set it to have the custom ModelForm. Then that form will be used in the inline version of Ingredient.