【发布时间】:2020-05-11 04:33:56
【问题描述】:
我已经复制了这篇文章的所有代码 Dropdown in Django Model
我必须做什么才能使此列表可见? 当我运行 manage.py makemigrations 或 managepy migrate 时,它告诉我没有任何变化。
我的代码。 views.py
from django.http import HttpResponse
from django.shortcuts import render
def index(request):
return HttpResponse('<h1>Witamy w aplikacji dla najlepszych inwestorów!</h1>')
class CreateMyModelView(CreateView):
model = MyModel
form_class = MyModelForm
template_name = 'myapp/template.html'
success_url = 'myapp/success.html'
models.py
from django.db import models
from multiselectfield import MultiSelectField
COLOR_CHOICES = (
('green','GREEN'),
('blue', 'BLUE'),
('red','RED'),
('orange','ORANGE'),
('black','BLACK'),
)
class MyModel(models.Model):
color = models.CharField(max_length=6, choices=COLOR_CHOICES, default='green')
forms.py
class MyModelForm(ModelForm):
class Meta:
model = MyModel
fields = ['color']
template.html
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Create" />
</form>
一切都是一样的,当我运行我的服务器时 only this appears
可能是什么问题?
【问题讨论】:
-
您不会触发您的
CreateMyModelView,而是您的index视图。
标签: python django drop-down-menu