﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14113	Access to extra fields in M2M relations	jprafael	nobody	"I'm using a model similar to
{{{
#!python
class Recipe(models.Model):
	name = models.CharField(max_length = 32, unique=True)
	products = models.ManyToManyField(Product, through=""RecipeProduct"")

class Product(models.Model):
	name = models.CharField(max_length = 32, unique=True)

	amound = models.IntegerField() # in stock

class RecipeProduct(models.Model):
	recipe = models.ForeignKey(Recipe)
	product	= models.ForeignKey(Product)

	amount	= models.IntegerField()
}}}
And need to list all my recipes, along with their products' amounts.
{{{
#!python
Recipe.objects.select_related().all()
}}}
Gives access to the list of products in each recipe, but not access to the amount field in the intermediary table.

Perhaps recipe.products.all() should merge the extra fields into the Product objects by means of another parameter in the ManyToManyField definition where the user can choose the fields to select (and the names they would be accessible by) like:
{{{
#!python
products = models.ManyToManyField(Product, through=""RecipeProduct"", extra_fields={'amount': 'recipe_amount'})
}}}

This would allow direct usage like:
{{{
#!python
{% for recipe in recipes %}
	{% for product in recipe.products.all() %}
		product: {{ product.name }} ({{ product.amount }} in stock)
		amount: {{ product.recipe_amound }}
	{% endfor}
{% endfor %}
}}}
while avoiding name colision problems
"		closed	Database layer (models, ORM)	1.2		invalid	Many2ManyField intermediary fields		Unreviewed	0	0	0	0	0	0
