I’m wanting to make it so when I click my apply now button it redirects to my application page and it pre-selects the property from a drop-down list. What is the best and most optimal way to accomplish this action? I’ve tried adding the property ID to the session but I wasn’t able to pre-select the property from the drop-down box.
My form
class ApplicationForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ApplicationForm, self).__init__(*args, **kwargs)
self.fields['property'].queryset = Property.objects.filter(is_active=True)
class Meta:
model = Application
fields = '__all__'
exclude = {
'application_date'
}
widgets = {
'requested_move_in_date': DateInput(),
}
labels = {
'requested_move_in_date': 'Requested Move-in Date'
}
Property Detail View
class PropertyDetailView(DetailView):
model = Property
def get_context_data(self, **kwargs):
context = super(PropertyDetailView, self).get_context_data(**kwargs)
self.request.session['property_ID'] = self.object.pk
return context
Application View (GET method)
else:
person_form = PersonForm(prefix='person')
current_address_form = AddressForm(prefix='current_address')
previous_address_form = AddressForm(prefix='previous_address')
employment_form = EmploymentForm(prefix='employment')
application_form = ApplicationForm(prefix='application')
if "property_ID" in request.session:
propertyid = request.session.get("property_ID")
print(propertyid)
#application_form.fields
del request.session["property_ID"]
return render(request, 'base/application.html', {'person': person_form,
'current_address': current_address_form,
'previous_address': previous_address_form,
'employment': employment_form,
'application': application_form
})