def index(request):
game_data = GameDataEntry()
update_progress = ProjectProgressEntry()
work_hours = WorkHoursEntry()
if request.method == "GET":
form = RecordSearchForm(data=request.GET)
if form.is_game is True:
query = request.GET.get('entry_date')
object_list = game_data.objects.filter(entry_date=query)
return HttpResponse(object_list, content_type='text/plain')
if form.is_work is True:
query = request.GET.get('entry_date')
object_list = work_hours.objects.filter(entry_date=query)
return HttpResponse(object_list, content_type='text/plain')
if form.is_Progress is True:
query = request.GET.get('entry_date')
object_list = update_progress.objects.filter(entry_date=query)
return HttpResponse(object_list, content_type='text/plain')
else:
form = RecordSearchForm()
return render(request, 'index.html', context={'form': form})
This is my Form class
class RecordSearchForm(forms.Form):
is_Progress = forms.BooleanField(widget=forms.CheckboxInput(
attrs={'class': 'form-check-input', "id": "is_progress_update", "type": 'checkbox'}))
is_game = forms.BooleanField(widget=forms.CheckboxInput(
attrs={'class': 'form-check-input', "id": "is_game_update", "type": "checkbox"}))
is_work = forms.BooleanField(widget=forms.CheckboxInput(
attrs={'class': 'form-check-input', "id": "is_work_entry", "type": "checkbox"}))
game_name = forms.ModelChoiceField(widget=forms.Select(
attrs={'class': 'form-control', "id": "game_name"}), queryset=Games.objects.all())
entry_date = forms.DateField(widget=forms.DateInput(
attrs={'class': 'form-control', "id": "date_entry", "type": "date"}))
I am trying to make a search function to get the records based on the date of the entry for the models that are either game development, finished updates, or work hours but it's saying that is_game is not an attribute of my form but it's clearly there. can anyone tell me what I'm doing wrong or what I've missed
You can get the attributes from the .cleaned_data
[Django-doc] after validating the form, so:
def index(request):
game_data = GameDataEntry()
update_progress = ProjectProgressEntry()
work_hours = WorkHoursEntry()
form = RecordSearchForm(data=request.GET)
if form.is_valid():
result = form.cleaned_data
query = result['entry_date']
if result['is_game']:
object_list = game_data.objects.filter(entry_date=query)
return HttpResponse(object_list, content_type='text/plain')
if result['is_work']:
object_list = work_hours.objects.filter(entry_date=query)
return HttpResponse(object_list, content_type='text/plain')
if result['is_Progress']:
object_list = update_progress.objects.filter(entry_date=query)
return HttpResponse(object_list, content_type='text/plain')
else:
form = RecordSearchForm()
return render(request, 'index.html', context={'form': form})