Generally, {% csrf_token %} is written just below the opening <form> tag. I
mean, not sure if this has anything to do with your issue. Others may confirm
as well
Regards,
Amitesh
On Thursday, 30 July, 2020, 07:26:21 am IST, Christian Seberino
<[email protected]> wrote:
Here is my template...
{% extends "html_base" %}
{% block body_elements %}
<div id = "admin_status">
<form action = "." method = "post">
<p>UPDATE STATUSES</p>
<table>
{% for e in both %}
<tr>
<td>
{{e.0.customer.first}}
{{e.0.customer.last}}
</td>
<td>
{{e.0.date|date:"Y-m-d"}}
{{e.0.time|time:"h:i A"}}
</td>
<td>{{e.1}} Completed</td>
</tr>
{% endfor %}
</table>
<p><input type = "submit" value = "UPDATE STATUSES"/></p>
</form>
<p><a href = "/admin">Go Back To Admin Page</a></p>
{% csrf_token %}
</div>
{% endblock %}
Here is the view....
def admin_status(request):
appts = [e for e in APPT.objects.all() if e.status != "Completed"]
appts = sorted(appts,
key = lambda a : a.customer.last + a.customer.first + \
str(a.date) + str(a.time))
if request.method == "POST":
form = grandmas4hire.forms.StatusForm(request.POST)
if form.is_valid(): # Need to enter more
code here when this page works...
reply = django.shortcuts.redirect("/admin_status")
else:
both = [(e, form.fields[str(e.id)]) for e in appts]
reply = django.shortcuts.render(request,
"admin_status.html",
{"both" : both})
else:
form = grandmas4hire.forms.StatusForm()
both = [(e, form[str(e.id)]) for e in appts]
reply = django.shortcuts.render(request,
"admin_status.html",
{"both" : both})
return reply
Here is the dynamic form StatusForm....
class StatusForm(django.forms.Form):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for e in grandmas4hire.models.Appointment.objects.all():
self.fields[str(e.id)] = \
django.forms.BooleanField(required = False)
(I need to make a dynamic form because I needed 1 field for each Appointment
object.)
Chris
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAG5-5i%2BJC3tOHr3T-a8D6E9Cy2yEohTZOR_Z3HWVTNUtoLnEBg%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/725525470.7515030.1596074301490%40mail.yahoo.com.