Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to register model chooser without touching the original models.py code ? #41

Open
lugishr opened this issue Jan 23, 2023 · 1 comment

Comments

@lugishr
Copy link

lugishr commented Jan 23, 2023

In documentation, you mentioned: "To enable the chooser for your model, you must register the model. For simple cases, decorate your model with @register_model_chooser".
How would you register the model in other cases ?
For example, I have a Django project to which I additionally added Wagtail. So I still have many pure Django apps. And I don't want to touch their source code so registering them with decorator is not an option for me.
Is there another way to register models ? Could I import this models into Wagtail app and make registration there ?

@seb-b
Copy link
Member

seb-b commented Jan 29, 2023

I haven't tested this but you should be able to call register_model_chooser as a function, so something like this should work

from wagtailmodelchooser import register_model_chooser
from other.package.models import Thing

register_model_chooser(Thing)

as long as you put this somewhere that's called on startup like wagtail_hooks.py or models.py I believe this should work. If it doesn't then we should look into making it work, let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants