The content_type attribute on the Document model clashes with custom models with a content_type ForeignKey to ContentType
See original GitHub issueWe have a CustomDocument model with a content_type = models.ForeignKey(ContentType, ...)
field
https://github.com/wagtail/wagtail/blob/master/wagtail/documents/models.py#L170-L176 is preventing us from upgrading cleanly to 2.11+
One workaround is to rename the field and adding a db_column="content_type_id"
kwarg on the definition to keep the values, and rewrite loads of code.
I would argue that content_type = models.ForeignKey(ContentType, ...)
is a typical convention (and we use it with Page https://github.com/wagtail/wagtail/blob/master/wagtail/core/models.py#L748) and that we should change the property on the Document model
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
The contenttypes framework | Django documentation
At the heart of the contenttypes application is the ContentType model, ... Adding a foreign key from one of your own models to...
Read more >Admin error due to ModelLogEntry after site setting model has ...
Issue Summary I've removed a custom site settings model (actually I've reverted the migration), which has been edited before, ...
Read more >When running the command to make migrations it throws a ...
Simply put you need to change the field name for your content type in your model from "content-Type" to just "content-type". Share.
Read more >Model Reference - Pages - Wagtail's documentation
This document contains reference information for the model classes inside the wagtailcore module. ... (foreign key to django.contrib.contenttypes.models.
Read more >[Solved]-How to use abstract model as a ForeignKey in Django?
ForeignKey (A, null=True, blank=True, on_delete=models. ... from django.contrib.contenttypes.fields import GenericForeignKey from ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Good to hear! Renaming AbstractDocument’s
content_type
tomimetype
(ormime_type
? I think there’s precedence in Python for the single-word version, but I could be wrong…) is probably still worth doing, then, but if it isn’t a blocker for upgrading to 2.11 then we can do that in a feature release with the proper deprecation process.@gasman took more time to look at this without deadlines looming. It is indeed the inheritance precedence 🤦♂️ swapping things around allows adding new docs without an issue. It leaves the inline serving breakage which you had a plan for