Opened 11 years ago

Closed 4 years ago

#11018 closed New feature (wontfix)

Generic foreign keys in custom m2m relationship model

Reported by: Alexandr Owned by: nobody
Component: contrib.contenttypes Version: 1.1-beta
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In version 1.0.2 and older we can use custom table for ManyToManyField with parameter through = MyRelationModel. MyRelationModel should include foreign keys. I want to use generic foreign key as one foreign keys:

class SomeModel(models.Model):
    marks = models.ManyToManyField(to=Mark, through=MarkedItem)

class MarkedItem(models.Model):
    mark = models.ForeignKey(Mark)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')

Example: content object as one of foreign keys.

But this code is't work.

Change History (7)

comment:1 Changed 10 years ago by Alex Gaynor

Triage Stage: UnreviewedAccepted

Marking as accepted, but this probably shouldn't use teh standard ManyToManyField

comment:2 Changed 10 years ago by Tobias McNulty

This seems low priority to me because you can accomplish the same thing without a ManyToManyField by explicitly joining across your "through" model, e.g.:

class SomeModel(models.Model):
    marked_items = models.GenericRelation(MarkedItem)


While I don't know anything about the ManyToMany code this seems like an edge case that would add unnecessary complexity to the core

comment:3 Changed 10 years ago by James Bennett

milestone: 1.2

1.2 is feature-frozen, moving this feature request off the milestone.

comment:4 Changed 9 years ago by Julien Phalip

Severity: Normal
Type: New feature

comment:5 Changed 8 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 Changed 8 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:7 Changed 4 years ago by Tim Graham

Component: Database layer (models, ORM)contrib.contenttypes
Resolution: wontfix
Status: newclosed

Closing given the alternate solution described in comment 2 and a lack of interest in 6 years.

Note: See TracTickets for help on using tickets.
Back to Top