user6220407
user6220407

Reputation:

Django Exception Value: 'module' object has no attribute 'ModelsChoiceField'

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

The Device object is working and show me the ModelChoiceField. But I don't understand why the Ledon isn't working.

Upvotes: 0

Views: 101

Answers (1)

Shang Wang
Shang Wang

Reputation: 25539

If that's your actual code, you have a typo, it's ModelChoiceField, but you had ModelsChoiceField.

Upvotes: 1

Related Questions