Prepopulating Forms with get values in Django
def get_initial(self):
if self.request.GET:
initial = {'district': self.request.GET.get('district', None),
'housing_type': self.request.GET.get('housing_type', None),
'sign': self.request.GET.get('sign', None),
'budget': self.request.GET.get('budget', None)}
return initial
else:
return super(ProjectListView, self).get_initial()
For this form I wanted to set the initial values on the search form to the GET variables, this was on a ListView/FormMixin.
Written by Gerald Goh
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#