Форма Django всегда возвращает false:

Я пытаюсь обновить запись. Но form.save() возвращает false. И я не могу разобраться в ситуации.

Views.py

def update(request, id):
customer = Customer.objects.get(id=id)
if request.method == "POST":
    form = customerForm(request.POST, instance=customer)
    if form.is_valid():
        form.save()
        return redirect("/")
    else:
        return render(request, 'index.html')
else:
    form = customerForm()
return render(request, 'edit.html', {'customer': customer})

models.py

from django.db import models
from django.db import connections

# Create your models here.


class Customer(models.Model):
    # id = models.CharField(max_length=100)
    customer_name = models.CharField(max_length=256)
    phone = models.CharField(max_length=256)
    address = models.CharField(max_length=256)
    city = models.CharField(max_length=256)
    email = models.EmailField()
    product_company = models.CharField(max_length=256)
    product_brand = models.CharField(max_length=256)
    product_model = models.CharField(max_length=256)
    imei = models.CharField(max_length=20)
    reported_issue = models.CharField(max_length=256)
    possible_solution = models.CharField(max_length=256)
    actual_solution = models.CharField(max_length=256)
    estimated_time = models.CharField(max_length=256)
    actual_time = models.CharField(max_length=256)
    current_status = models.CharField(max_length=256)
    additional_notes = models.CharField(max_length=256)
    date_created = models.CharField(max_length=256)
    date_updated = models.CharField(max_length=256)


class Meta:
    db_table = "datagrid"

forms.py

from django import forms
from django.forms import fields, widgets
from customerDetails.models import Customer


class customerForm(forms.ModelForm):
    class Meta:
        model = Customer
        fields = ['id', 'customer_name', 'phone', 'address', 'city', 'email', 'product_company', 'product_brand', 'product_model', 'imei', 'reported_issue',
                  'possible_solution', 'actual_solution', 'estimated_time', 'actual_time', 'current_status', 'additional_notes', 'date_created', 'date_updated']
        widgets = {'customer_name': forms.TextInput(attrs={'class': 'form-control'}),
                   'phone': forms.TextInput(attrs={'class': 'form-control'}),
                   'address': forms.TextInput(attrs={'class': 'form-control'}),
                   'city': forms.TextInput(attrs={'class': 'form-control'}),
                   'email': forms.EmailInput(attrs={'class': 'form-control'}),
                   'product_company': forms.TextInput(attrs={'class': 'form-control'}),
                   'product_brand': forms.TextInput(attrs={'class': 'form-control'}),
                   'product_model': forms.TextInput(attrs={'class': 'form-control'}),
                   'imei': forms.TextInput(attrs={'class': 'form-control'}),
                   'reported_issue': forms.TextInput(attrs={'class': 'form-control'}),
                   'possible_solution': forms.TextInput(attrs={'class': 'form-control'}),
                   'actual_solution': forms.TextInput(attrs={'class': 'form-control'}),
                   'estimated_time': forms.TextInput(attrs={'class': 'form-control'}),
                   'actual_time': forms.TextInput(attrs={'class': 'form-control'}),
                   'current_status': forms.TextInput(attrs={'class': 'form-control'}),
                   'additional_notes': forms.TextInput(attrs={'class': 'form-control'}),
                   'date_created': forms.TextInput(attrs={'class': 'form-control'}),
                   'date_updated': forms.TextInput(attrs={'class': 'form-control'})
                   }

edit.html

Вернуться на верх