Django ModelChoiceField queryset does not return actual values from db -


my models are:

class actiontype(models.model):       id_action_type = models.floatfield(primary_key=true)     action_name = models.charfield(max_length=15, blank=true, null=true)       class meta:         managed = false         db_table = 'action_type'  class ticketsform(models.model):     ticket_id = models.floatfield(primary_key=true)     ticket_type = models.charfield(max_length=30, blank=true, null=true)     action_type = models.charfield(max_length=15,blank=true, null=true) 

in forms have:

class bankform(forms.modelform):      action_type= forms.modelchoicefield(queryset=actiontype.objects.all(),widget=forms.radioselect)      class meta:         model = ticketsform         fields = ('ticket_type',                   'action_type',) 

when rendered html don't see actual values of actiontype.objects.all() instead see
actiontype object
actiontype object near radiobutton. can tell me mistake is.

you need define __str__ method model. example:

from django.utils.encoding import python_2_unicode_compatible  @python_2_unicode_compatible class actiontype(models.model):     id_action_type = models.floatfield(primary_key=true)     action_name = models.charfield(max_length=15, blank=true, null=true)      ...      def __str__(self)         return self.action_name 

the python_2_unicode_compatible decorator required if using python 2. see __str__ docs more info.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -