Skip to content

Instantly share code, notes, and snippets.

@wellic
Created April 8, 2020 09:05
Show Gist options
  • Select an option

  • Save wellic/a0054d45f2399da0f487fa5c44bb772e to your computer and use it in GitHub Desktop.

Select an option

Save wellic/a0054d45f2399da0f487fa5c44bb772e to your computer and use it in GitHub Desktop.

How to toggle of the var_anyname_dev_mod variables for admin templates:

  • prepare Admin class (Django)
#Example
class SomeClassAdmin(...):

    #process request parameters
    def get_queryset(self, request):
        qs = super(SomeClassAdmin, self).get_queryset(request)
        self.request = request
        return qs

    # add into a rendering page request parametes
    def some_method(self, obj=None):
        ...
        return render_to_string('template.html', params,
        request=self.request) # <- add var 'var_anyname_dev_mod' to template
  • prepare template
{% if var_anyname_dev_mod %}
...
{% endif %}
  • create bookmark toggle dev modein browsers with url:
javascript:
n='var_anyname_dev_mod';
v=document.cookie.match('(^|; )'+n+'=([^;]+)');
document.cookie=n+'='+(v?';path=/;expires='+(new Date(0)).toGMTString()+';':'1;path=/;');
window.location.reload();
//create bookmark with name dev_mode:
//add to url code:
//javascript:n='var_anyname_dev_mod'; v=document.cookie.match('(^|; )'+n+'=([^;]+)'); document.cookie=n+'='+(v?';path=/;expires='+(new Date(0)).toGMTString()+';':'1;path=/;');window.location.reload();
n='var_anyname_dev_mod';
v=document.cookie.match('(^|; )'+n+'=([^;]+)');
document.cookie=n+'='+(v?';path=/;expires='+(new Date(0)).toGMTString()+';':'1;path=/;');
window.location.reload();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment