Search code examples
djangodjango-settingsdjango-endless-pagination

Django settings values from a Database table


Is it possible to set the values for the variables in settings.py from a database table?

I'm using endless_pagination and it has a overwrite-able setting

ENDLESS_PAGINATION_PER_PAGE = 10,

I need to set this value with a value from my database table, is it possible?

like

config = Config.objects.get(param_name__exact="ENDLESS_PAGINATION_PER_PAGE") 
settings.ENDLESS_PAGINATION_PER_PAGE= config.param_value

Solution

  • According to their documentation, this variable can be overwritten by your template tag:

    {% paginate objects %}
    {% paginate 20 objects %} {# makes it 20 per page #}
    

    Source: http://code.google.com/p/django-endless-pagination/source/browse/endless_pagination/templatetags/endless.py

    Update: using this fact, you can set a variable in your View which gets passed to the template:

    {% paginate my_pagination_count objects %}