应用程序覆盖Django源

时间:2014-09-01 11:58:55

标签: python django

我试图设计一个Django管理员扩展,它需要对源代码进行细微更改,即django.contrib.admin.utilsdjango.contrib.admin.helpersdjango.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)

0 个答案:

没有答案