我已经按照Django ModelForm文档中的流程以及几个教程进行了操作。我的字段显示为标准文本条目,而不是下拉列表。有人能指出我正确的方向吗?
forms.py
create table tbl ("NAME" varchar(20));
insert into tbl values ('pppp apple pppp');
insert into tbl values ('pppp beer pppp');
insert into tbl values ('apple pppp pppp');
select *
from tbl
where tbl."NAME" like '%apple%'
views.py
from .models import Authority # change to rating!!!
from django import forms
class AuthorityForm(forms.ModelForm):
class Meta:
model = Authority
fields = ('authority_name',)
models.py
from django.shortcuts import render
from django.views.generic import CreateView
from .models import Authority
from .forms import AuthorityForm
# Create your views here.
class HomeCreateView(CreateView):
model = Authority
form_class = AuthorityForm
template_name = 'home.html'
success_url = 'home.html'
home.html的
from django.db import models
# Create your models here.
class Authority(models.Model):
authority_name = models.CharField(max_length = 100)
authority_url = models.URLField()
def __str__(self):
return self.authority_name
class Rating(models.Model):
authority_name = models.CharField(max_length = 100)
ratings = models.CharField(max_length = 20000)
# Could this be reduced if remove the trailing letters of non-int values?
# Perhaps all values could be one-hot encoded