我想要获取用户列表并将其填充到select下拉列表中,但是值的格式不正确。 [models.py]
from django.contrib.auth.models import User
class Post(models.Model):
title = models.CharField()
author = models.ForeignKey(User, on_delete= models.CASCADE)
[forms.py]
from django.contrib.auth.models import User
class PostForm(forms.ModelForm
我是django的新手,我正在尝试连接来自不同模型的不同查询集,基于以下答案:
当我试图在我的管理中查看这个错误时,我一直得到这个错误。
'list' object has no attribute 'iterator'
我在我的forms.py里叫它
from django import forms
from itertools import chain
from content.models import Article, Tutorial
class DashboardChoiceForm(forms.Modelform):
dashb
首先,我想说我对Django很陌生,所以温柔点。提前感谢!
我有两个下拉框,All_team_Form和Product_Form (都是ModelChoiceField)。
class All_team_Form(forms.ModelForm):
teams = forms.ModelChoiceField(queryset= All_teams.objects.all().order_by('team_name'))
class Meta:
model = All_teams
fields = ('team_name'
要求是在下拉列表中显示不同登录的M2M实例。每个登录将只能看到属于他们自己的域的实例。由于这个下拉列表是表行值的动态列表,所以我想使用
widget = forms.CheckboxSelectMultiple which is part of the ModelForm where we need to pass the queryset. This queryset overrides the M2M form field definition:
def formfield_for_manytomany(self, db_field, request, **kwargs):
它
在我的forms.py里
class CollegeForm(forms.ModelForm):
collegeName = forms.ModelChoiceField(label='Select College', queryset=College.objects.all(), widget=forms.Select(attrs={'class': 'form-control'}))
class Meta:
model = College
fields = ('collegeName&
我有这个型号 class AgeRange(models.Model):
frm = models.CharField(max_length=20, blank=False)
to = models.CharField(max_length=20, blank=False) 现在,当我尝试通过从frm+to文件收缩的值填充下拉列表时。所以,我运行这个查询集: class ReportForm(forms.ModelForm):
ranges = AgeRange.objects.all().values()
print(ranges)
for item
我正在尝试编写一个简单的测试用例来测试Django表单,该表单允许将Orange对象分配给Apple对象。
forms.py
class AppleOrangeAssignmentForm(forms.ModelForm):
orange = forms.ModelChoiceField(required=True, \
queryset=Orange.objects.filter(apple=None))
class Meta:
model = Apple
fields = ('orange')
queryset
我在django表单中的下拉字段有一个小问题。我想添加到这个字段占位符(或者不作为占位符的active first选项)和其他一些东西,比如没有标签、类等等。我在forms.py中写了这样的东西,但是现在我的表单坏了--不要将值保存到数据库中。
from .models import Scenario, ScenarioArea
from django import forms
class newScenario(forms.ModelForm):
scenarioArea=forms.ModelChoiceField(label="", queryset=Scena
我是这个领域的新手。我正在处理依赖下拉列表,我参考了。在使用以下代码复制相同的代码时:
Forms.py
class AddressForm(forms.ModelForm):
class Meta:
model=City
country = forms.ModelChoiceField(
queryset=Country.objects.all(),
label=u"Country",
widget= ModelSelect2Widget(
search_fi
这必须是一个常见的需求,但我在SO或Django文档中没有发现对我有用的东西。我对Django很陌生。我的问题是:我需要根据拥有区域所有权的公司,更改表格下拉列表中显示的区域列表。
在我的应用程序中:帐户(即用户)是公司的成员。一个公司管理一个地区。该地区内有若干条路线。本公司可增加/更新/移走路线,或将路线分配到不同地区。
因此,在我的表单中,我想确保只有属于公司的区域才会显示在下拉列表中。基本上,用户会选择一个区域,然后是与该区域相关联的CRUD路由。
class Company(models.Model):
name = models.CharField(...
ac
我正在尝试为我的表单下拉列表过滤我的查询集
form.py
class ProductForm(forms.ModelForm):
class Meta:
model = Product
fields = [ 'GTIN','name','style1','style2','style3','size','dimension','color','UOM','description','k
在我的表单中,有几个用AJAX链接在它们之间的下拉列表。
这就是我填充它们的方式
function getleaseterm() {
//get a reference to the select element
$select = $('#id_leaseterm');
//request the JSON data and parse into the select element
var l_id = ($("select[name='lease'] option:selec
我已经看到了关于Stackoverflow的所有问题。但我还是不可能解决这个错误。我希望下拉列表数据出现在我的网站上。我从另一个模型得到的数据。所以在这之前我要做得很好。现在,当我试图将这些数据保存到数据库中时,会出现此错误。
Select a valid choice. That choice is not one of the available choices.
我的模特是这样的
apn = models.CharField(null=True, blank=False, max_length=255)
我的form.py文件是这样的
class labelModelForm(form
当我将产品添加到我的数据库中时,我有一个关于如何最好地生成我的表单的挑战。model.py
class Category(models.Model):
title = models.CharField(max_length...)
class Department(models.Model):
categories = models.ForeignKey(Category)
class ProductDivisions(models.Model):
departments = models.ForeignKey(Department)
class Product(mo
“管辖权”字段的查询集在初始化过程中设置如下。查询集依赖于传入的id,该id来自用户单击的特定链接。因此,我无法在forms.ModelChoiceField()中定义单个查询集,但似乎django需要我这样做。
class TaxForm (forms.ModelForm): #Will be used for state tax and other taxes
jurisdiction = forms.ModelChoiceField(queryset=?????)
class Meta:
model = Tax
exclude = (
我的模特:
class Annonce(models.Model):
created_at = models.DateTimeField(editable=False)
modified_at = models.DateTimeField()
title = models.CharField(max_length=24)
domaines = models.ManyToManyField(Domaine, null=True,related_name="%(app_label)s_%(class)s_related")
我的表格:
class a
我在使用ChoiceField在数据库中创建值的下拉列表时遇到问题。以下是代码片段
from django import forms
from testplatform.models import ServiceOffering
class ContactForm(forms.Form):
subject = forms.ChoiceField(queryset=ServiceOffering.objects.all())
#subject = forms.ModelMultipleChoiceField(queryset=ServiceOffering.objects.a