my forms.py
from django import forms
from django.forms import Form
from .models import LedON, Device
class DownlinkForm(forms.Form):
Device_id = forms.ModelChoiceField(queryset = Device.objects.all() )
Time_intervall = forms.IntegerField()
Led1 = forms.ModelsChoiceField(queryset = LedON.objects.all() )
my models.py
from django.db import models
from app.models import *
from django import forms
from django.forms import ModelChoiceField
class LedON(models.Model):
Ledon = models.CharField(max_length = 50)
class Meta:
verbose_name = 'ledon'
def __str__(self):
return "%s" % (self.Ledon)
class DevEUIModelChoiceField(ModelChoiceField):
def label_from_instance(self, obj):
return obj.DevEUI
class LedonModelChoiceField(ModelChoiceField):
def label_from_instance(self, obj):
return obj.Ledon
Device对象正在运行,并显示ModelChoiceField
。
但我不明白为什么Ledon没有工作。
答案 0 :(得分:2)
如果这是您的实际代码,那么您有一个拼写错误,它是ModelChoiceField
,但您有ModelsChoiceField
。