Opened 15 years ago

Last modified 4 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: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no
Pull Requests:How to create a pull request

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.

According to the ticket's flags, the next step(s) to move this issue forward are:

  • To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is: [https://github.com/django/django/pull/#### PR].

Change History (9)

by MS, 15 years ago

Attachment: MtoM_abstract_through.patch added

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

comment:1 by vitaliy, 15 years ago

Cc: django-tickets@… added

Yes, very useful feature!

comment:2 by anonymous, 15 years ago

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

comment:3 by Russell Keith-Magee, 15 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

comment:4 by Julien Phalip, 14 years ago

Severity: Normal
Type: New feature

comment:5 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:7 by Aymeric Augustin, 12 years ago

Component: Core (Other)Database layer (models, ORM)

comment:8 by Mariusz Felisiak, 4 years ago

Has patch: unset
Needs tests: unset
Note: See TracTickets for help on using tickets.
Back to Top