Modify

Ticket #262 (closed defect: fixed)

Opened 5 years ago

Last modified 4 years ago

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

moved_auto_through_and_added_through_to_m2m.diff (4.9 KB) - added by tommi@… 4 years ago.
updated__moved_auto_through_and_added_through_to_m2m.diff (4.9 KB) - added by tommi@… 4 years ago.
Updated the patch since the last one was built on one of my own changesets. (Nothing's changed except for timestamps and revision numbers.(

Change History

comment:1 Changed 5 years ago by andrew

  • Status changed from new to assigned
  • Milestone set to 0.7

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

comment:2 Changed 4 years ago by hcarvalhoalves@…

How can I access the relation with the related_name until then?

comment:3 Changed 4 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)

Changed 4 years ago by tommi@…

comment:4 Changed 4 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 4 years ago by tommi@…

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 4 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!

View

Add a comment

Modify Ticket

Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.