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})
这是我的表单类
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"}))
我正在尝试制作一个搜索功能,以根据游戏开发、完成更新或工作时间模型的输入日期获取记录,但它说 is_game 不是我的表单的属性,但它显然在那里。有人能告诉我我做错了什么或者我错过了什么吗
验证表单后,您可以从[Django-doc]中获取属性,因此:
.cleaned_data