i have eror and i dont know what is mistake
html:
{% load static %}
{% load crispy_forms_tags %}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link href="{% static 'css/stylesheet.css' %}" rel="stylesheet">
<title>{{ title }}</title>
</head>
<body>
<div class="myForm">
<form method='POST' action=''>{% csrf_token %}
<div class="row">
<div class='col-sm-6'>
<div class="form-row">
<div class="form-group col-md-6">
{{ form.invoice_date|as_crispy_field }}
{{ form.name|as_crispy_field }}
</div>
<div class="form-group col-md-6">
{{ form.invoice_number|as_crispy_field }}
{{ form.phone_number|as_crispy_field }}
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
{{ form.line_one|as_crispy_field }}
</div>
<div class="form-group col-md-2">
{{ form.line_one_quantity|as_crispy_field }}
</div>
<div class="form-group col-md-2">
{{ form.line_one_unit_price|as_crispy_field }}
</div>
<div class="form-group col-md-2">
{{ form.line_one_total_price|as_crispy_field }}
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
{{ form.line_two|as_crispy_field }}
</div>
<div class="form-group col-md-2">
{{ form.line_two_quantity|as_crispy_field }}
</div>
<div class="form-group col-md-2">
{{ form.line_two_unit_price|as_crispy_field }}
</div>
<div class="form-group col-md-2">
{{ form.line_two_total_price|as_crispy_field }}
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
{{ form.invoice_type|as_crispy_field }}
</div>
<div class="form-group col-md-12">
{{ form.total|as_crispy_field }}
</div>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<!-- <input type="submit" value='Submit'/> -->
</div>
</div>
</form>
</div><!-- End myform -->
</body>
</html>
models.py:
from django.db import models
class Invoice(models.Model):
comments = models.TextField(max_length=3000, default='', blank=True, null=True)
invoice_number = models.IntegerField(blank=True, null=True)
invoice_date = models.DateField(auto_now_add=False, auto_now=False, blank=True, null=True)
name = models.CharField('Customer Name', max_length=120, default='', blank=True, null=True)
line_one = models.CharField('Line 1', max_length=120, default='', blank=True, null=True)
line_one_quantity = models.IntegerField('Quantity', default=0, blank=True, null=True)
line_one_unit_price = models.IntegerField('Unit Price (D)', default=0, blank=True, null=True)
line_one_total_price = models.IntegerField('Line Total (D)', default=0, blank=True, null=True)
line_two = models.CharField('Line 2', max_length=120, default='', blank=True, null=True)
line_two_quantity = models.IntegerField('Quantity', default=0, blank=True, null=True)
line_two_unit_price = models.IntegerField('Unit Price (D)', default=0, blank=True, null=True)
line_two_total_price = models.IntegerField('Line Total (D)', default=0, blank=True, null=True)
line_three = models.CharField('Line 3', max_length=120, default='', blank=True, null=True)
line_three_quantity = models.IntegerField('Quantity', default=0, blank=True, null=True)
line_three_unit_price = models.IntegerField('Unit Price (D)', default=0, blank=True, null=True)
line_three_total_price = models.IntegerField('Line Total (D)', default=0, blank=True, null=True)
line_four = models.CharField('Line 4', max_length=120, default='', blank=True, null=True)
line_four_quantity = models.IntegerField('Quantity', default=0, blank=True, null=True)
line_four_unit_price = models.IntegerField('Unit Price (D)', default=0, blank=True, null=True)
line_four_total_price = models.IntegerField('Line Total (D)', default=0, blank=True, null=True)
line_five = models.CharField('Line 5', max_length=120, default='', blank=True, null=True)
line_five_quantity = models.IntegerField('Quantity', default=0, blank=True, null=True)
line_five_unit_price = models.IntegerField('Unit Price (D)', default=0, blank=True, null=True)
line_five_total_price = models.IntegerField('Line Total (D)', default=0, blank=True, null=True)
phone_number = models.CharField(max_length=120, default='', blank=True, null=True)
total = models.IntegerField(default='0', blank=True, null=True)
balance = models.IntegerField(default='0', blank=True, null=True)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
last_updated = models.DateTimeField(auto_now_add=False, auto_now=True, blank=True)
paid = models.BooleanField(default=False)
invoice_type_choice = (
('Receipt', 'Receipt'),
('Proforma Invoice', 'Proforma Invoice'),
('Invoice', 'Invoice'),
)
invoice_type = models.CharField(max_length=50, default='', blank=True, null=True, choices=invoice_type_choice)
def __str__(self):
return self.name
def __unicode__(self):
return self.invoice_number
forms.py:
from django import forms
from .models import Invoice
class InvoiceForm(forms.ModelForm):
class Meta:
model = Invoice
fields = ['name', 'phone_number', 'invoice_date',
'line_one', 'line_one_quantity', 'line_one_unit_price', 'line_one_total_price',
'total', 'paid', 'invoice_type'
]
views.py:
from django.shortcuts import render , redirect
from .forms import InvoiceForm
from .models import *
def home(request):
title = 'صورت حساب'
context = {
"title": title,
}
return render(request, "home.html",context)
def add_invoice(request):
form = InvoiceForm(request.POST or None)
if form.is_valid():
form.save()
return redirect('/add_invoice')
context = {
"form": form,
"title": "New Invoice",
}
return render(request, "add_invoice.html", context)
def list_invoice(request):
title = 'List of Invoices'
queryset = Invoice.objects.all()
context = {
"title": title,
"queryset": queryset,
}
return render(request, "list_invoice.html", context)