Created
April 28, 2017 09:58
-
-
Save nemesifier/1f2eb47876ef6a8771b520d3bc9fe660 to your computer and use it in GitHub Desktop.
possible bug in django admin extra_context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib import admin | |
| from .models import Config | |
| class ConfigAdmin(admin.ModelAdmin): | |
| def add_view(self, request, form_url='', extra_context={}): | |
| if 'config' in self.model.__name__.lower(): | |
| extra_context.update({'CONFIG_SPECIFIC': True}) | |
| return super(ParentAdmin, self).add_view(request, form_url, extra_context) | |
| admin.site.register(Config, ConfigAdmin) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not a bug, but a wrong function definition. Must be
extra_context=Noneinstead ofextra_context={}because the function definition is evaluated only once at import time, defining a default mutable object keeps the object in memory on subsequent requests.