Opened 16 years ago
Closed 10 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 , 16 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 16 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 , 16 years ago
| milestone: | 1.2 |
|---|
1.2 is feature-frozen, moving this feature request off the milestone.
comment:4 by , 14 years ago
| Severity: | → Normal |
|---|---|
| Type: | → New feature |
comment:7 by , 10 years ago
| Component: | Database layer (models, ORM) → contrib.contenttypes |
|---|---|
| Resolution: | → wontfix |
| Status: | new → closed |
Closing given the alternate solution described in comment 2 and a lack of interest in 6 years.
Marking as accepted, but this probably shouldn't use teh standard ManyToManyField