我试图设计一个Django管理员扩展,它需要对源代码进行细微更改,即django.contrib.admin.utils
,django.contrib.admin.helpers
和django.forms.forms
。
这是我创建Python / Django软件包的第一次经历,而且我还没有找到任何关于如何使用外部应用程序实际覆盖Django源代码行为的信息,而无需更改原始文件。在理想情况下,应该只在INSTALLED_APPS
左右列出应用程序。我会非常感谢任何指示。
UPD。确切的变化是:
django.contrib.admin.utils
中的:
def flatten_fieldsets(fieldsets):
"""Returns a list of field names from an admin fieldsets structure."""
field_names = []
for name, opts in fieldsets:
for field in opts['fields']:
if isinstance(field, (list, tuple)):
field = filter(lambda a: a != None, field)
**field_names.extend(field)
elif field != None:
field_names.append(field)**
return field_names
django.contrib.admin.helpers
中的:
class Fieldset(object):
def __init__(self, form, name=None, readonly_fields=(), fields=(), classes=(), **settings=()**,
description=None, model_admin=None):
self.form = form
self.name, self.fields = name, fields
self.classes = ' '.join(classes)
self.description = description
self.model_admin = model_admin
self.readonly_fields = readonly_fields
**self.settings = settings**
...
django.forms.forms
中的:
class BaseForm(object):
...
def __getitem__(self, name):
"Returns a BoundField with the given name."
try:
field = self.fields[name]
except KeyError:
**if name != None:**
raise KeyError('Key %r not found in Form' % name)
else:
field = Field(widget = TextInput(attrs={'style': 'visibility: hidden;'}))
return BoundField(self, field, name)