Bisher gibt es eine ChoiceField Abfrage die funktioniert:
form:
Code: Alles auswählen
class ProtokollFilter_Gruppe(forms.Form):
auswahl = forms.ChoiceField(label='', choices=[("Halbjahr",'aktuelles Halbjahr'),('Woche','Woche'), ("Schuljahr",'aktuelles Schuljahr'), ('heute','heute'), ("all",'Alle Aufgaben'),("next",'nächstes Halbjahr'), ])
Code: Alles auswählen
<form action="{% url 'gruppe_uebersicht' gruppe_id %}" method="POST">
{% csrf_token %}
<h2 style= "text-align: left;"> Zeitraum:
<button type="button">
{{form_filter.auswahl}}
</button type="button">
<button type="button">
<input name="filter" type="submit" value="anwenden">
</button type="button">
</h2>
</form>
Code: Alles auswählen
def gruppe_uebersicht(req, gruppe_id):
...
form_filter = ProtokollFilter_Gruppe
...
if req.method == 'POST':
auswahl = form_filter(req.POST)
filter = auswahl.fields['auswahl'].choices
auswahl_liste = dict(filter)
if auswahl.is_valid():
auswahl = auswahl.cleaned_data['auswahl']
protokoll_zeitraum = protokoll_zeit_filter(protokoll_gruppe, auswahl)
wahl = auswahl_liste[auswahl]
else:
wahl = "aktuelles Halbjahr"
...
context={'wahl': wahl, 'form_filter': form_filter,}
return render(req, 'lehrer/gruppe_uebersicht.html', context)
form:
Code: Alles auswählen
class Start_Datum(forms.Form):
aufgaben_seit = forms.DateField(label="", widget = forms.SelectDateWidget())
Code: Alles auswählen
<form action="{% url 'gruppe_uebersicht' gruppe_id %}" method="POST">
{% csrf_token %}
<h2 style= "text-align: left;"> Zeitraum:
<button type="button">
{{{{startdatum}}}}
</button type="button">
<button type="button">
<input name="filter" type="submit" value="anwenden">
</button type="button">
</h2>
</form>
Code: Alles auswählen
start_filter = Start_Datum
startdatum = start_filter(req.Post)
if startdatum.is_valid():
startdatum = startdatum.cleaned_data['aufgaben_seit']
print(startdatum)
Code: Alles auswählen
startdatum = start_filter(req.Post)
Das Datumfeld wird angezeigt aber wenn ich "anwenden" anklicke, kommt der Fehler:
Code: Alles auswählen
'WSGIRequest' object has no attribute 'Post'
Request Method: POST
Request URL: http://localhost:8000/gruppe_uebersicht/2/
Django Version: 5.0.7
Exception Type: AttributeError
Exception Value:
'WSGIRequest' object has no attribute 'Post'
Exception Location: D:\Dropbox\RechentrainerApp\rechentrainer.app\accounts\views.py, line 509, in gruppe_uebersicht
Raised during: accounts.views.gruppe_uebersicht
Python Executable: C:\Users\Pit\AppData\Local\Programs\Python\Python310\python.exe
Python Version: 3.10.1
Python Path:
['D:\\Dropbox\\RechentrainerApp\\rechentrainer.app',
'C:\\Users\\Pit\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
'C:\\Users\\Pit\\AppData\\Local\\Programs\\Python\\Python310\\DLLs',
'C:\\Users\\Pit\\AppData\\Local\\Programs\\Python\\Python310\\lib',
'C:\\Users\\Pit\\AppData\\Local\\Programs\\Python\\Python310',
'C:\\Users\\Pit\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages']
Server time: Sun, 02 Mar 2025 16:30:48 +0100
Traceback Switch to copy-and-paste view
C:\Users\Pit\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\exception.py, line 55, in inner
response = get_response(request)
…
Code: Alles auswählen
Variable Value
csrfmiddlewaretoken
'DEOEvnIXaF7kY80pe3NzhqHv5eUbJvi8NQle1yAiJtbPqlNxcuVOMIocOrRKwfIb'
aufgaben_seit_day
'1'
aufgaben_seit_month
'1'
aufgaben_seit_year
'2025'
filter
'anwenden'