Skip to content

Instantly share code, notes, and snippets.

View guillaumepiot's full-sized avatar

Guillaume Piot guillaumepiot

View GitHub Profile
"""
Two things are wrong with Django's default `SECRET_KEY` system:
1. It is not random but pseudo-random
2. It saves and displays the SECRET_KEY in `settings.py`
This snippet
1. uses `SystemRandom()` instead to generate a random key
2. saves a local `secret.txt`
class MyAdmin(admin.ModelAdmin):
list_filter = ['market']
# Duplicate list_filter to assign on a pre request basis
_list_filter = list_filter
# Change list filter on the view depending on user
def changelist_view(self, request, extra_context=None):
if not request.user.is_superuser:
self.list_filter = None