Ticket #262 (closed defect: fixed)
ManyToManyField also needs related_name (and through?) when frozen
| Reported by: | rnairn@… | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | 0.7 |
| Component: | migrations | Version: | 0.6.1 |
| Keywords: | Cc: |
Description
This is important when you have multiple ManyToManyFields? that link to the same model.
modelsinspector.py needs to be changed to have this I think:
(models.ManyToManyField,),
[],
{
"to": ["rel.to", {}],
"symmetrical": ["rel.symmetrical", {"default": True}],
"related_name": ["rel.related_name", {"default": None}],
},
"through" is also important but I gather that there is some difficulty with that?
Attachments
Change History
comment:2 Changed 4 years ago by hcarvalhoalves@…
How can I access the relation with the related_name until then?
comment:3 Changed 3 years ago by andrew
For now, manually do the query using the other end; for example, if you wanted to do book.authors, just do Author.objects.filter(booksid=foo.id)
comment:4 Changed 3 years ago by tommi@…
The patch I included will include "through" keyword if necessary. For this, auto_through had to be moved (it wasn't using AutoChanges? for anything anyway).
Patch also corrects a typo with brackets being used with current_model_from_key.
Patch also corrects the "# Have they _added_ a through= ?" and its opposite being actually in incorrect order.
The problem was with through tables e.g. in following models:
from django.db import models
class Target(models.Model):
pass
class ProblemModel(models.Model):
bugs = models.ManyToManyField('Target', through='ThroughModel')
# adding_this_will_fail = models.BooleanField(default=False)
class ThroughModel(models.Model):
problem_model = models.ForeignKey('ProblemModel')
target = models.ForeignKey('Target')
(As written in the diff,) patch was built on 632:3885e6f4db33 although I had to turn off index creation for non-unique columns since it broke during latest changesets.
Changed 3 years ago by tommi@…
- Attachment updated__moved_auto_through_and_added_through_to_m2m.diff added
Updated the patch since the last one was built on one of my own changesets. (Nothing's changed except for timestamps and revision numbers.(
comment:5 Changed 3 years ago by andrew
- Status changed from assigned to closed
- Resolution set to fixed
Patch applied in [6b80917fd58a]. This would seem to complete the ticket; thanks for the patch!

Yes, this was lost in the transition to inspection. Marking for inclusion.