django - Recent values in CharField -


i have model

class mod(model):           f = charfield(max_length=10) 

and form:

class modform(modelform):     class meta:         model = mod         fields = ('f',) 

when display form user want suggest dropdown mod.objects.all() values of 'f'. how in simplest way? tried specify widgets = {'f': select}, not editable. can use selectize.js make selectable preloading ajax values, seems long way.

models.py

class mod(models.model):   choice_1 = 'choice 1'   choice_2 = 'choice 2'   field_choices = (     (choice_1, 'the real charfield value'),     (choice_2, 'another charfield value')   )   f = models.charfield(     max_length=10,     choices=field_choices,     default=choice_1   ) 

forms.py

class modform(modelform):     class meta:         model = mod         fields = ('f',) 

end of views.py

return render(request, 'template.html', context={'mod_form': mod_form}) 

template.html

{{mod_form.as_p}} 

this extracted working code. obfuscating specific app out did not make unclear.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -