Skip to content

Instantly share code, notes, and snippets.

@nemesifier
Created April 28, 2017 09:58
Show Gist options
  • Select an option

  • Save nemesifier/1f2eb47876ef6a8771b520d3bc9fe660 to your computer and use it in GitHub Desktop.

Select an option

Save nemesifier/1f2eb47876ef6a8771b520d3bc9fe660 to your computer and use it in GitHub Desktop.
possible bug in django admin extra_context
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)
@nemesifier

nemesifier commented Apr 28, 2017 •

Copy link
Copy Markdown
Author

Not a bug, but a wrong function definition. Must be extra_context=None instead of extra_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment