Let's say I am using django-tagging application and I decide I want to add a form class to the existing tagging forms. I do not want to patch the form into the existing forms.py since it will be blown out when updated. How do I extend forms.py to include my form class?
I tried adding a "tagging" folder in my app with a forms.py that only included my class, but that breaks the installed app's form classes. (I know it was a long shot, just thought I would give it a try).
Any suggestions on where to look for info on adding a form class to an existing application?
The simple answer is, you inherit from the form classes, create your own modifications, and use your modified version.
So, instead of importing from taggit, you would import from your own forms.py
I have done this many times when I want to decorate/enhance an existing app's functionality. The downside is if the the documentation is poor, you have to dig through the source to find out what the call stack is and the inheritance tree for the functionality you want to modify.
The downside of this approach is you cannot modify the contributed application's behavior. So if you want some internal functionality of taggit to use your custom code - this is difficult to implement. However, this is a very rare case.
Should you really want to do that (as I had to do once), you can clone the source and maintain your own copy. Create a branch with your modifications, and make sure you write good tests.
You should then add this code to your django project as its own application; due to Python's lookup rules - it will find your local copy and use it instead of the one from the global site-packages directory.
If the upstream is updated, your burden is then to maintain your copy by making sure tests don't fail when you update/rebase.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With