【问题标题】:ModelForm not showing in adminModelForm 未显示在管理员中
【发布时间】:2015-09-23 11:59:48
【问题描述】:

我有一个名为 profile 的应用程序,它具有 de 模型 Profile(models.Model)。然后,我有另一个名为 offer 的应用程序,其模型为 Offer(models.Model),它几乎具有 Profile 的所有属性,所以我想包含一个表单在报价中具有配置文件的属性。 在 offer 应用的 forms.py 中,我创建了:

from django.forms import ModelForm
from profile.models import Profile
from offer.models import Offer

class ProfileOfferForm(ModelForm):
    #extrafields
    class Meta:
        model = Profile
        exclude = ('min_salary',)

然后在 admin.py(在应用程序 Offer 中)我有:

from django.contrib import admin
from django import forms
from offer.models import *
from offer.forms import *
# Register your models here.

from profile.models import Profile
@admin.register(Offer)
#admin.site.register(Offer, OfferAdmin, ProfileForm)
class OfferAdmin(admin.ModelAdmin):
    inlines = [
        QuestionInline,
        AutomatismInline,
        CandidateInline
    ]
    form = ProfileOfferForm

我没有收到任何错误,唯一的问题是 Profile 的 de 字段没有出现在 Offer 部分的管理中。留下什么东西吗? 任何帮助将不胜感激, 谢谢!

【问题讨论】:

  • 我不明白你想在这里做什么。您不能使用与不同模型相关的表单。

标签: django django-models django-forms django-admin django-modeladmin


【解决方案1】:

您似乎忘记将自定义管理员注册到您的模型。

# At the bottom do something like this
admin.site.register(Offer, OfferAdmin)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-14
    • 2021-09-14
    相关资源
    最近更新 更多