Hey everyone! This is my first post here on the forum, so I apologize for any mistakes or missing information, okay?
Has anyone had experience taking a Django project and migrating some models to Django Polymorphic? Welcome to django-polymorphic’s documentation! — django-polymorphic 3.1 documentation
If so, did you encounter any issues with the unit tests that already existed? Any “incompatibilities”?
We are performing this migration here and are encountering ContentType errors in models that don’t even have relationships with the models that were migrated to Polymorphic.
I appreciate any responses in advance!
Welcome @niltonpimentel !
I don’t use this package, so I can’t help you here - maybe someone else here can.
It may be helpful getting started if you posted more details about the environment - what versions of Django, django-polymorphic, and Python you are using, along with perhaps more details about the specific errors you are receiving.
What I’d like to point out is that the version currently on pypi (3.1) is fairly old (3 years) and may have issues with current versions of Django and Python.
If you look at the issues thread at Support for Django 4.x · Issue #598 · jazzband/django-polymorphic · GitHub you’ll see that you need to pull the current version directly from github and not from pypi.
1 Like
Hello Ken, thank you for your reply and welcome to the forum! We are using these versions:
python==3.10.8
Django==3.2
django-polymorphic==3.1.0
In your experience would you recommend using the package that seems “abandoned” or is there a more “correct” way to do that in django?
First, addressing this specific package, django-polymorphic does not appear to be abandoned. The linked issues thread implies that the current issue is an administrative issue with pypi and not a technical issue with the project.
My first suggestion then is to pull the most current version to see if it improves the situation for you. (You’re also due to upgrade your Django version as well, since 3.2 went EOL back in April.)
Regarding “abandoned” packages in general, we take a very pragmatic view. If we rely on a package that becomes abandoned, we’re prepared to do what we need to do to keep it up to date. (I can only think of two cases where that has been necessary, and in both cases, our fixes were temporary as the original package owners did eventually update them.)
1 Like
@KenWhitesell let’s say that I don’t want to rely on an external package… can you point me in a direction to achieve that goal without using django-polymorphic? I don’t have any experience working with polymorphic models so any tip will be helpful.
A polymorphic model in this case intrinsically handles the retrieval of a child class when the parent class is queried.
You have a couple different options here.
First, you might want to carefully evaluate the application being developed to determine whether or not the abstraction you’re looking to implement is really going to provide the benefits you hope to obtain. This means that you would be looking at all views and queries that you’re currently aware of that needs to use this data.
Then, if you decide that this is an abstraction you will benefit from, read the source code of django-polymorphic. Learn how someone else has solved this problem. See how they implement it. Look at the edge-cases they may have been forced to address. Identify all the “touch-points” that needed to be implemented.
That’s the beauty of the OpenSource ecosystem. Even if you choose not to use their package, you can still learn from it.
1 Like