Created
October 16, 2012 12:37
-
-
Save ionelmc/3899011 to your computer and use it in GitHub Desktop.
terse admin.py
This file contains 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 SomeModel, OtherModelWithFKToSomeModel | |
def register(model): | |
def decorator(klass): | |
admin.site.register(model, klass) | |
return klass | |
return decorator | |
def inline(model, klass=admin.TabularInline, **options): | |
return type( | |
"%sInlineAdmin" % model.__name__, | |
(klass,), | |
dict(model=model, **options) | |
) | |
@register(SomeModel) | |
class SomeModelAdmin(admin.ModelAdmin): | |
inlines = ( | |
inline(OtherModelWithFKToSomeModel, extra=0), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment