hln
hln

Reputation: 1106

Dynamic ModelMultipleChoiceField

I have a data table that contain different job genres and their ids. I wnat all the genres to show as a mMltipleChoiceField in broswer , so i tried

 keyword=forms.ModelMultipleChoiceField(required=False, queryset=JobGenre.objects.all())

it wont show job genres , instead it shows "JobGenre.object" in all the options.what should i do in this case?

the error i got from select a jobgenre:´and i must selected at least one option, it seems like required=False doesn't work neither

  ValueError at /register/
  Cannot assign "[<JobGenre: rengøring>]": "Worker.keyword" must be a "JobGenre" instance.


 Request Method:

 POST
 Request URL:

 http://127.0.0.1:8000/register/



 Django Version:

  1.4.3

Exception Type:

ValueError

 Exception Value:

 Cannot assign "[<JobGenre: rengøring>]": "Worker.keyword" must be a "JobGenre" instance. 


 Exception Location:

 C:\Python27\lib\site-packages\django\db\models\fields\related.py in __set__, line 366



 Python Executable:

 C:\Python27\python.exe



 Python Version:

 2.7.3

Upvotes: 0

Views: 288

Answers (1)

Akshar Raaj
Akshar Raaj

Reputation: 15211

Do you have a __unicode__ defined on JobGenre?

class JobGenre(models.Model):

    name = models.CharField()

    def __unicode__(self):
        return self.name

Upvotes: 2

Related Questions