Opened 15 years ago

Closed 8 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

Description

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 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

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

comment:2 by Tobias McNulty, 15 years ago

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)

some_model.marked_items.selected_related('mark')

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 by James Bennett, 14 years ago

milestone: 1.2

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

comment:4 by Julien Phalip, 13 years ago

Severity: Normal
Type: New feature

comment:5 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:7 by Tim Graham, 8 years ago

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