Add support for GenericForeignKey
|Reported by:||adrian||Owned by:||adrian|
|Severity:||critical||Keywords:||rthml tab space editor js|
|Cc:||hi-world, cup||Triage Stage:||Unreviewed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
sopel had the idea of a GenericForeignKey, which would abstract the concept of "content_type_id" and "object_id". Basically, it'd be a way to relate an object to "one of several types of objects."
For example, we currently have this in the Comment model:
class Comment(meta.Model): # ... content_type = meta.ForeignKey(core.ContentType) object_id = meta.IntegerField()
That could be replaced with this:
class Comment(meta.Model): # ... content_object = meta.GenericForeignKey()
With that, Comment objects would get an automatic get_content_object() method, which would return whatever object was related, regardless of its type.
This is a messy problem, so we'd have to figure out a couple of loose ends:
- Does every other object in the system get a get_comment_list method?
- Do we enforce referential integrity, so that, for example, all the appropriate comments would be deleted if a story was deleted?
Change History (15)
comment:12 Changed 9 years ago by anonymous
- Component changed from Metasystem to Contrib apps
- milestone set to Version 1.0
- priority changed from low to high
- Severity changed from normal to critical
- Type changed from defect to enhancement
comment:13 Changed 9 years ago by hi-world cup
- Cc hi-world cup added
- Keywords rthml tab space editor js added
- Summary changed from Add support for GenericForeignKey to hi-world cup
comment:14 Changed 9 years ago by adrian
- Summary changed from hi-world cup to Add support for GenericForeignKey