Opened 6 years ago

Last modified 2 years ago

#11760 new New feature

Placeholder for through value in ManyToManyField of abstract class

Reported by: MS Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1
Severity: Normal Keywords:
Cc: django.tickets@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If you have an abstract class with ManyToManyField it is possible to user %(class)s in related_name for generic related name. Same should be possible for through, to define a generic name for through tables.

Example:

class ClassA(models.Model):
    ...

class AbstractClass(models.Model):
    name = models.ManyToManyField(ClassA, related_name = '%(class)s_name', through = 'ClassA_%(class)s')

class MyClass(AbstractClass):
    ...

Class ClassA_MyClass(models.Model)
    class_a=models.ForeignKey(ClassA)
    my_class=models.ForeignKey(MyClass)

The applied patch uses the same mechanism as used for related_name.

Attachments (1)

MtoM_abstract_through.patch (645 bytes) - added by MS 6 years ago.
Patch for django/db/models/fields/related.py to use through in ManyToMany Field of an abstact class

Download all attachments as: .zip

Change History (8)

Changed 6 years ago by MS

Patch for django/db/models/fields/related.py to use through in ManyToMany Field of an abstact class

comment:1 Changed 6 years ago by vitaliy

  • Cc django-tickets@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Yes, very useful feature!

comment:2 Changed 6 years ago by anonymous

  • Cc django.tickets@… added; django-tickets@… removed

comment:3 Changed 6 years ago by russellm

  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to New feature

comment:5 Changed 4 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:6 Changed 4 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:7 Changed 2 years ago by aaugustin

  • Component changed from Core (Other) to Database layer (models, ORM)
Note: See TracTickets for help on using tickets.
Back to Top