Last Updated: February 25, 2016
· voiddragon

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
        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.