1👍
✅
Your code looks correct, but I use a little bit different and it’s working for me. I don’t use the action
attribute in the form. By the way I’m using Django 4.0.7.
Below is an example:
views.py:
def items(request, slug, pk):
next = request.POST.get('next', '{% url "process" slug=slug %}')
item = Items.objects.get(item_id=pk)
if request.POST.get('start', False):
item.started = True # BooleanField 'started' (default = False, setted in the Items model)
item.save()
return HttpResponseRedirect(next)
else:
return render(request, 'items.html', {'slug':slug, 'pk':pk})
template:
<form method="post" >
{% csrf_token %}
<button type="submit" name="start" value="start" class="btn btn-warning mb-3">Start</button>
</form>
0👍
As you mentioned, you want:
The BooleanField whats i want to change it’s call "active" (true by default).
You can simply set default
option as default=True
to the field, so:
class Listing(models.Model):
active=models.BooleanField(default=True)
Source:stackexchange.com