mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
newforms-admin: Added fieldsets(), fieldsets_add() and fieldsets_change() methods to ModelAdmin. These hooks aren't called from anywhere yet.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@4357 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7227d41f48
commit
53f94937f0
@ -67,6 +67,13 @@ class AdminFieldLine(object):
|
|||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.fields)
|
return len(self.fields)
|
||||||
|
|
||||||
|
# New implementation of Fieldset
|
||||||
|
class Fieldset(object):
|
||||||
|
def __init__(self, name, field_list, classes=None, description=None):
|
||||||
|
self.name, self.field_list = name, field_list
|
||||||
|
self.classes = classes or ()
|
||||||
|
self.description = description
|
||||||
|
|
||||||
class ModelAdmin(object):
|
class ModelAdmin(object):
|
||||||
"Encapsulates all admin options and functionality for a given model."
|
"Encapsulates all admin options and functionality for a given model."
|
||||||
|
|
||||||
@ -126,6 +133,32 @@ class ModelAdmin(object):
|
|||||||
new_fieldset_list.append(AdminFieldSet(name, classes, opts.get_field, options['fields'], description))
|
new_fieldset_list.append(AdminFieldSet(name, classes, opts.get_field, options['fields'], description))
|
||||||
return new_fieldset_list
|
return new_fieldset_list
|
||||||
|
|
||||||
|
def fieldsets(self, request):
|
||||||
|
"""
|
||||||
|
Generator that yields Fieldset objects for use on add and change admin
|
||||||
|
form pages.
|
||||||
|
|
||||||
|
This default implementation looks at self.fields, but subclasses can
|
||||||
|
override this implementation and do something special based on the
|
||||||
|
given HttpRequest object.
|
||||||
|
"""
|
||||||
|
if self.fields is None:
|
||||||
|
default_fields = [f.name for f in self.opts.fields + self.opts.many_to_many if f.editable and not isinstance(f, models.AutoField)]
|
||||||
|
yield Fieldset(fields=default_fields)
|
||||||
|
else:
|
||||||
|
for name, options in self.fields:
|
||||||
|
yield Fieldset(name, options['fields'], classes=options.get('classes'), description=options.get('description'))
|
||||||
|
|
||||||
|
def fieldsets_add(self, request):
|
||||||
|
"Hook for specifying Fieldsets for the add form."
|
||||||
|
for fs in self.fieldsets(request):
|
||||||
|
yield fs
|
||||||
|
|
||||||
|
def fieldsets_change(self, request, object_id):
|
||||||
|
"Hook for specifying Fieldsets for the change form."
|
||||||
|
for fs in self.fieldsets(request):
|
||||||
|
yield fs
|
||||||
|
|
||||||
def has_add_permission(self, request):
|
def has_add_permission(self, request):
|
||||||
"Returns True if the given request has permission to add an object."
|
"Returns True if the given request has permission to add an object."
|
||||||
opts = self.opts
|
opts = self.opts
|
||||||
|
Loading…
x
Reference in New Issue
Block a user