Lets say I have this model.py:
class Order(models.Model):
delivery = models.BooleanField()
I have this form.py:
class OrderForm(ModelForm):
class Meta:
model = Order
fields = ["delivery"]
And I have this views.py:
def get_order(request):
if request.method == "POST":
form = OrderForm(request.POST)
if form.is_valid():
order_instance = Order(form.cleaned_data["delivery"])
order_instance.save()
return HttpResponseRedirect("/end")
else:
form = OrderForm()
return render(request, "forms/test.html", {"form": form})
And the HTML page show form page.
With this code my program will tell me that he is not happy because I am giving "null" to "delivery" field because Django automatically create a "id" field for each model so he want me to give him the "id" and the "delivery" fields.
The "id" field is supposed to auto increment though. It is my primary key. But with form it doesn't seem to work. Is there a way to only specify the delivery and let the auto increment do the job for the id ?