i know it's not best practice (i guess caching better way) saw in code django model values saved global variables in django_app/shared.py:
vals = mymodel.objects.values_list('id', flat=true) choices = [(x,x) x in vals] in django/forms.py
from shared import choices class myform(forms.form): choice = forms.multiplechoicefield(choices, default='') ... in django/views.py:
def my_view(request): .... form = myform(request.get) .... i'm running app using wsgi behind nginx. now, problem see if made changes in model not reflected in form on view. options stay same. getting cached because uwsgi process spawns across multiple requests. not it. please help.
update: expected turned out nginx. restarted nginx , changes reflected. now, because not updated without nginx restart, mean have stayed forever? understanding choices updated new uwsgi process created. btw, use uwsgi conf file configuration.
thanks in advance!
instead of doing that, can use modelchoicefield.
class myform(forms.form): choice = forms.modelchoicefield(queryset=mymodel.objects.all()) ... this yield below in template:
<select id="id_field" name="field"> <option value="obj1.id">object1</option> <option value="obj2.id">object2</option> ... </select>
Comments
Post a Comment