python - Django ModelChoiceField to_field_name is not working -


i have following models , i'm trying use django modelform's modelchoicefield solve problem quickly

class games(model):    code = charfield()  # gta, abc, etc..    name = charfield()  # grand tourismo, bbb ccc , etc..    unique_together(code, name)  class settings(model):    gamecode = charfield(). #didn't use foreign key because of internal reasons can't use games model somewhere outside    username = charfield()    ...  class gamecodechoicefield(modelchoicefield):     def label_from_instance(self, obj):          return obj.name  class settingsform(forms.modelform):    gamecode = gamecodechoicefield(queryset=none,required=false)     class meta:         model = settings         fields = ['username']      def __init__(self, *args, **kwargs):         super(settingsform, self).__init__(*args, **kwargs)          self.fields['gamecode'].queryset = games.objects.filter(game=game, isactive=true)         self.fields['gamecode'].to_field_name = 'code' 

now, when try save settingsform, i'm getting gamecode = 'gamecode object' instead of code gta..

please help. edited.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -