如何在需要一些参数的管理中生成内联表单?

wwtsj6pe  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(238)

我在django admin中有以下代码:

class MarkFormatInline(admin.TabularInline):
    model = MarkFormat
    form = MarkFormatForm
    fields = ('format', 'url_template', 'start', 'count', 'delay',
              'xmltimeout', 'adtimeout', 'only_fire', 
              'server_timeout')
    extra = 1

及以下表格:

class MarkFormatForm(forms.ModelForm):
    def clean(self):
        cleaned_data = super(MarkFormatForm, self).clean()

        if self.instance.pk:
            return cleaned_data

        format = cleaned_data.get("format")
        if not format:
            return cleaned_data

        for f in ("url_template", "delay", "start", "count",
                  "xmltimeout", "adtimeout", "is_server_request",
                  "server_timeout"):
            if not cleaned_data.get(f):
                cleaned_data[f] = getattr(format, f)
        return cleaned_data

我需要将url\u模板字符串字段强制设置为非空,将唯一的\u fire布尔标志强制设置为false。如何在django中实现它?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题