Hello,
I have Forms and want to use it during @api_view.
Currently, I am getting the all data, I want it to be filtered based on the Forms.
I want to filter serializer_class.data by Forms.
class ForecastField_all(forms.Form):
flat_Ad = forms.ChoiceField(choices=flat_Adress)
flat_P = forms.ChoiceField(choices=flat_project)
flat_Stat = forms.ChoiceField(choices=flat_Status)
@api_view(['GET', 'POST'])
def all_flat(request):
mydata = models.FlatModelSqlite.objects.all()
serializer_class = serializers.FlatSerializerSqlite(mydata, many=True)
if request.method == "GET":
form_all_flat = ForecastField_all(request.GET)
if form_all_flat.is_valid():
all_fl_flatP = form_all_flat.cleaned_data['flat_P']
all_fl_flatAd = form_all_flat.cleaned_data['flat_Ad']
all_fl_flat_Stat = form_all_flat.cleaned_data['flat_Stat']
.....
html_save = "MyHome/all_flat.html"
template = loader.get_template(html_save)
context = {
'data': serializer_class.data, 'flatP': ForecastField_all()
}
return HttpResponse(template.render(context, request))