Closed CapAlex94 closed 2 years ago
Hi it's possible to have an update about this topic? In particular about the signals when a settings is updated.
thanks
Hi,
For the first item in your issue, you'd probably have to override the django admin templates, but I cannot provide any guidance for that, unfortunately.
I'm trying to use signals to perform action when a preference is updated. At the moment, I'm following the documentation and I have create the callback function inside an utils.py file and I have registered the signal receiver inside the apps.py file inside one of the application of my Django project. I have updated one of the preference available using the admin interface but my callback function is not called. Is that normal or I am missing something?
(Sorry, I closed by mistake)
As for your second problem, can you please share the relevant code of each file?
I used the same code provided by you on the wiki page (https://django-dynamic-preferences.readthedocs.io/en/latest/react_to_updates.html), no other custom code was created as the basic one was not working correctly.
Is the app config in question installed in your settings.INSTALLED_APPS
? Can you try putting a raise
or print('hello')
statement in the ready()
function to ensure it is loaded properly py Django?
Yes the apps.py is loaded by django on startup:
Is the registering signals
line coming from your code?
It would be easier for me (or anyone else) to help if you shared the relevant bits of code (settings.INSTALLED_APPS
, apps.py
, utils.py
) and the layout of your project.
dashboard/apps.py
from django.apps import AppConfig
from dynamic_preferences.signals import preference_updated
from dashboard.utils import notify_on_preference_update
class DashboardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'dashboard'
def ready(self):
print('Registering signals')
preference_updated.connect(notify_on_preference_update)
Settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dynamic_preferences',
'dashboard',
dashboard/utils.py
def notify_on_preference_update(sender, section, name, old_value, new_value, **kwargs):
print("Preference {} in section {} changed from {} to {}".format(
name, section, old_value, new_value))
Thank you, I have reproduced it locally and published a fix. Can you please try the develop branch on your project and let me know if it works?
Yes, now it's working correctly.
Thanks!!
Alright, I'll publish a release on PyPi tomorrow :)
Release 1.14.0 including this fix was just published on PyPi https://pypi.org/project/django-dynamic-preferences/1.14.0/#history
I think that in this update the preferences per instance was not considered :thinking:
Hi, first of all congratulations for the excellent extension!
I'm using the global_preference for different configurations inside my app, using the admin interface to allow users to update the configurations. I'm currently using 2 different section to define configurations. I would like to divide the "GLOBAL PREFERENCE" block by section in order to make more easily to update preferences of a specific section.
What i would like to create is something like the following structure:
How can I create this structure inside the admin interface?
Second problem:
I'm trying to use signals to perform action when a preference is updated. At the moment, I'm following the documentation and I have create the callback function inside an utils.py file and I have registered the signal receiver inside the apps.py file inside one of the application of my Django project. I have updated one of the preference available using the admin interface but my callback function is not called. Is that normal or I am missing something?
Thanks for the support!!