Tuesday, November 22, 2016

Re: Custom PG Range: where to place register_range() call?

I found a way to do it. For those interested take a look at https://github.com/djangonauts/django-hstore/blob/master/django_hstore/apps.py

That example solves the problem for register_hstore() but it can be extrapolated for register_range() as well.

The method is the following, in the file apps.py of your app create a ready() method for the AppConfig child class. Inside it create a hook using the signal functionality of django for database connection creation, that is, use connection_created.connect(connection_handler). The argument connection_handler is the function that should call register_range() for the connection provided by connection_created. Registration is done for connections and it can be globally, in which case the hook is a one off event or it can be not globally, in which case the hook is called for every connection established. Reading on the issues of that app, it seems that doing it globally is great for simple apps, but it doesn't deal well with complex setups using multiple databases.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/86dd0037-cf40-4474-856b-d4397722efe7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment