Я хочу настроить поле django Model в соответствии с моими потребностями и отправить данные в базу данных. Я все сделал соответственно. Но после запуска приложения я получаю хрустящую ошибку. Я не могу найти свои ошибки. Пожалуйста, помогите мне, друзья.
Models.py выглядит следующим образом
from django.db import models
from datetime import date
from configration.models import AddSite, AddDepartment, AddCategory, AddDesignation, Rate
# Create your models here.
class EmployeeRegistration(models.Model):
#Departmental Details
EmpId = models.IntegerField(verbose_name='EmpId')
Site = models.ForeignKey(AddSite,on_delete=models.CASCADE,max_length=150,verbose_name='Site')
Department =
models.ForeignKey(AddDepartment,on_delete=models.CASCADE,max_length=150,verbose_name='Department')
Category =
models.ForeignKey(AddCategory,on_delete=models.CASCADE,max_length=150,verbose_name='Category')
Designation =
models.ForeignKey(AddDesignation,on_delete=models.CASCADE,max_length=150,verbose_name='Designation')
PfAllowance = models.BooleanField(default = True)
EsiAllowance = models.BooleanField(default = True)
Uan = models.PositiveIntegerField(null = False,verbose_name='Uan')
Pf = models.PositiveIntegerField(null = True,verbose_name='Pf')
AttendenceAward = models.BooleanField(default = True)
AttendenceAllowance = models.BooleanField(default = True)
ProfesionalTax = models.BooleanField(default = False)
Rate = models.PositiveIntegerField(null = True)
# Personal Details
Name = models.CharField(max_length=150,verbose_name='Name')
Father = models.CharField(max_length=150,verbose_name='Father')
Dob = models.DateField()
Gender = models.BooleanField(default = True)
#Female = models.BooleanField(default = False)
MaritalStatus = models.BooleanField(default = True)
Address = models.CharField(max_length=200,verbose_name='Address')
Aadhar = models.PositiveIntegerField(null=True)
pan = models.CharField(max_length=10)
choices = [('Working','WORKING'),('NotWorking','NOT WORKING')]
Status = models.CharField(choices=choices,blank = False,max_length=10,verbose_name='Status')
Doj = models.DateField(default = date.today)
Doe = models.DateField(blank = True,verbose_name = 'Doe',null = True)
def __str__(self):
return '{name}'.format(name=self.Name)
views.py выглядит следующим образом
from django.shortcuts import render
from .regform import regisForm
from django.http import HttpResponse
from configration.models import AddSite, AddCategory,Rate
from .models import EmployeeRegistration
# Create your views here.
def ids():
no = EmployeeRegistration.objects.count()
if(no == None):
number = 1
return number
else:
number = no + 1
return number
def registration_view(request,*args, **kwargs):
emp_id = ids()
EmployeeId={'EmpId':emp_id}
form = regisForm(request.POST or None,initial=EmployeeId)
print(form)
if form.is_valid():
form.save()
form = regisForm()
else:
pass
context = {
'form':form,
"contact":"active"
}
return render(request,"registration.html",context)
регистрация. html выглядит следующим образом
{% extends 'profilebase.html' %}
{% load crispy_forms_tags %}
{% block content%}
<div class="content-section">
<form method="POST" enctype="multipart/form-data" action="/register/"> {% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Register
</legend>
<div class="row">
<div class="col-md-4">
{{ form.EmpId | as_crispy_field }}
</div>
</div>
<legend class="border-bottom mb-4">Departmental Details
</legend>
<div class="row">
<div class="col-md-4">
{{form.Site|as_crispy_field}}
</div>
<div class="col-md-8">
{{form.Department|as_crispy_field}}
</div>
</div>
<div class="row">
<div class="col-md-4">
{{form.Designation|as_crispy_field}}
</div>
<div class="col-md-8">
{{form.Category|as_crispy_field}}
</div>
<div class="col-md-8">
{{form.Uan|as_crispy_field}}
</div>
<div class="col-md-4">
{{form.Pf|as_crispy_field}}
</div>
<div class="col-md-12">
{{form.PfAllowance|as_crispy_field}}
{{form.EsiAllowance|as_crispy_field}}
{{form.ProfesionalTax|as_crispy_field}}
</div>
</div>
<legend class="border-bottom mb-4">Personal Details
</legend>
<div class="row">
<div class="col-md-4">
{{form.Name|as_crispy_field}}
</div>
<div class="col-md-8">
{{form.Father|as_crispy_field}}
</div>
<div class="col-md-4">
{{form.Dob|as_crispy_field}}
</div>
<div class="col-md-12">
{{form.Gender|as_crispy_field}}
<!--{{form.Male|as_crispy_field}}
{{form.Female|as_crispy_field}} -->
{{form.MaritalStatus|as_crispy_field}}
</div>
<div class="col-md-12">
{{form.Address|as_crispy_field}}
</div>
<div class="col-md-6">
{{form.Aadhar|as_crispy_field}}
</div>
<div class="col-md-6">
{{form.pan|as_crispy_field}}
</div>
<div class="col-md-4">
{{form.Status|as_crispy_field}}
</div>
<div class="col-md-4">
{{form.Doj|as_crispy_field}}
</div>
<div class="col-md-4">
{{form.Doe|as_crispy_field}}
</div>
</div>
</fieldset>
<div class="form-group">
<button class="btn btn-success btn-lg" type="Submit">Submit</button>
</div>
</form>
</div>
{% endblock content %}