Opened 5 years ago

Last modified 4 years ago

#11018 new New feature

Generic foreign keys in custom m2m relationship model

Reported by: Alexandr Owned by: nobody
Component: Database layer (models, ORM) 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.

Attachments (0)

Change History (6)

comment:1 Changed 5 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

comment:2 Changed 5 years ago by tobias

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 4 years ago by ubernostrum

  • milestone 1.2 deleted

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

comment:4 Changed 3 years ago by julien

  • Severity set to Normal
  • Type set to New feature

comment:5 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:6 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

Add Comment

Modify Ticket

Change Properties
<Author field>
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'

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

Note: See TracTickets for help on using tickets.