[Django] #27580: add special field for storing content types

47 views
Skip to first unread message

Django

unread,
Dec 7, 2016, 12:35:41 PM12/7/16
to django-...@googlegroups.com
#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.

Django

unread,
Dec 7, 2016, 10:27:23 PM12/7/16
to django-...@googlegroups.com
#27580: add special field for storing content types
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: Sergey
| Fedoseev
Type: New feature | Status: assigned
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sergey Fedoseev):

* owner: nobody => Sergey Fedoseev
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/27580#comment:1>

Django

unread,
Dec 8, 2016, 4:33:05 AM12/8/16
to django-...@googlegroups.com
#27580: add special field for storing content types
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: Sergey
| Fedoseev
Type: New feature | Status: assigned
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Jani Tiainen):

Does this feature require changes in Django core which prevents
implementing this as an external app? I only saw quite small change in
actual Django core.

--
Ticket URL: <https://code.djangoproject.com/ticket/27580#comment:2>

Django

unread,
Dec 16, 2016, 2:40:00 PM12/16/16
to django-...@googlegroups.com
#27580: add special field for storing content types
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: Sergey
| Fedoseev
Type: New feature | Status: assigned
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Someday/Maybe

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Someday/Maybe


Comment:

Sergey, could you write to the DevelopersMailingList to get feedback on
the idea?

--
Ticket URL: <https://code.djangoproject.com/ticket/27580#comment:3>

Django

unread,
Apr 5, 2017, 12:09:30 PM4/5/17
to django-...@googlegroups.com
#27580: add special field for storing content types
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: Sergey
| Fedoseev
Type: New feature | Status: assigned
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam (Chainz) Johnson):

* cc: me@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/27580#comment:4>

Django

unread,
Apr 7, 2017, 5:10:27 AM4/7/17
to django-...@googlegroups.com
#27580: add special field for storing content types
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: Sergey
| Fedoseev
Type: New feature | Status: assigned
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Marten Kenbeek):

Note that you shouldn't hardcode the `ContentType` class anywhere, or
migrations will refer to the wrong model. Use `self.related_model` in the
field, and `self.field.related_model` in the descriptor.

--
Ticket URL: <https://code.djangoproject.com/ticket/27580#comment:5>

Django

unread,
Apr 7, 2017, 6:06:44 AM4/7/17
to django-...@googlegroups.com
#27580: add special field for storing content types
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: Sergey
| Fedoseev
Type: New feature | Status: assigned
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Sergey Fedoseev):

Replying to [comment:5 Marten Kenbeek]:


> Note that you shouldn't hardcode the `ContentType` class anywhere, or
migrations will refer to the wrong model. Use `self.related_model` in the
field, and `self.field.related_model` in the descriptor.

Thanks for the hint!

--
Ticket URL: <https://code.djangoproject.com/ticket/27580#comment:6>

Django

unread,
Jun 3, 2022, 7:53:48 AM6/3/22
to django-...@googlegroups.com
#27580: add special field for storing content types
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: (none)

Type: New feature | Status: new
Component: | Version: dev

contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sergey Fedoseev):

* owner: Sergey Fedoseev => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/27580#comment:7>

Django

unread,
Aug 12, 2024, 6:09:53 AM8/12/24
to django-...@googlegroups.com
#27580: add special field for storing content types
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: (none)
Type: New feature | Status: new
Component: | Version: dev
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sage Abdullah):

* cc: Sage Abdullah (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/27580#comment:8>
Reply all
Reply to author
Forward
0 new messages