#27580: add special field for storing content types
------------------------------------------------+------------------------
Reporter: Sergey Fedoseev | Owner: nobody
Type: New feature | Status: new
Component: contrib.contenttypes | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
`ContentType` model is quite specific, so we could add the subclass of
ForeignKey field with some specific features.
For example we have such model:
{{{
#!python
class ModelWithContentTypeField(models.Model):
ct = ContentTypeField(on_delete=models.CASCADE)
}}}
In comparison with `ForeignKey` `ContentTypeField` will have these
features:
1. `ModelWithContentTypeField.objects.first().ct` will use content types
cache.
2. `ContentTypeField` will support lookups on the model classes:
`ModelWithContentTypeField.objects.filter(ct=FooModel)` vs
`ModelWithContentTypeField.objects.filter(ct=ContentType.objects.get_for_model(FooModel))`
`ModelWithContentTypeField.objects.filter(ct__in=[FooModel, BarModel])` vs
`ModelWithContentTypeField.objects.filter(ct__in=[ContentType.objects.get_for_model(model)
in [FooModel, BarModel]])`
3. Creation using a model class as a value:
`ModelWithContentTypeField.objects.create(ct=FooModel)`
Here's [https://github.com/sir-sigurd/django/tree/contenttype-field-3
rough implementation].
--
Ticket URL: <https://code.djangoproject.com/ticket/27580>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.2275423dc28e230a3d254a2f4c2c05cc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.