Browse files

[1.5.x] Made custom m2m fields without through easier to use

The change in f105fbe made through=None
m2m fields fail in cases where they worked before. It isn't possible to
create such fields using public APIs. The fix is trivial, so it seems
worth adding it.

This is not a backport from master. Master has gotten enough other
changes to related fields internal API that this fix alone isn't enough
to do any good.
  • Loading branch information...
1 parent 44afe44 commit 77f6eb2a6099fc06d01c77df2374e0528351822b @akaariai akaariai committed Feb 10, 2013
Showing with 3 additions and 1 deletion.
  1. +3 −1 django/db/models/fields/
@@ -591,12 +591,14 @@ def __init__(self, model=None, query_field_name=None, instance=None, symmetrical
"a many-to-many relationship can be used." %
def _get_fk_val(self, obj, field_name):
Returns the correct value for this relationship's foreign key. This
might be something else than pk value when to_field is used.
+ if not self.through:
+ # Make custom m2m fields with no through model defined usable.
+ return
fk = self.through._meta.get_field(field_name)
if fk.rel.field_name and fk.rel.field_name !=
attname = fk.rel.get_related_field().get_attname()

0 comments on commit 77f6eb2

Please sign in to comment.