0
請幫助創建selectBox adminpaneli。我使用: models.py:如何創建選擇框?
from django.db import models
from django.forms.models import ChoiceField
from django import forms
CHOICES = ('volvo', 'saab', 'opel', 'audi', 'cyan',)
class Sponsors(models.Model):
title = models.CharField(max_length=30)
link = models.URLField(max_length=100)
background_color = forms.ChoiceField(widget=forms.Select, choices=CHOICES)
admin.py:
from django.contrib import admin
from sponsors.models import Sponsors
class sponsorsAdmin(admin.ModelAdmin):
fields = ['title', 'link', 'background_color']
list_display = ('title',)
search_fields = ['title']
class Meta:
verbose_name = 'Спонсор'
verbose_name_plural = 'Спонсоры'
admin.site.register(Sponsors, sponsorsAdmin)
其結果是,管理面板纔可見域 「ID」, 「標題」, 「鏈接」。但是「background_color」字段不可見。它在數據庫中也不存在。
我需要adminpanel還田「BACKGROUND_COLOR」看起來像this: