question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The content_type attribute on the Document model clashes with custom models with a content_type ForeignKey to ContentType

See original GitHub issue

We 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:open
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gasmancommented, Mar 5, 2021

Good to hear! Renaming AbstractDocument’s content_type to mimetype (or mime_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.

0reactions
zerolabcommented, Mar 5, 2021

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found