I have a form to add new data to my database, but this form overwrites the existing data in my table. I want to add a new tuple and keep old tuples in my database's table
forms.py
class StudentForm(forms.ModelForm):
class Meta:
model = student
fields = ('First_Name', 'Last_Name', 'Birthday', 'Phone', 'Mobile', 'STNO',
'Father_Name', 'Father_Job', 'Father_Phone', 'ID_Code',
'National_ID', 'Address', 'Study_Field', 'Probation')
views.py
def add_student(request):
if request.method == "POST":
form = StudentForm(request.POST)
if form.is_valid():
new_student = form.save(commit=True)
new_student.author = request.user
new_student.save()
return redirect('../')
else:
form = StudentForm()
return render(request, 'school_manager/students/new_student.html', {'form': form})
models.py
class student(models.Model):
id = models.IntegerField(default=1,null=False,primary_key=True)
First_Name = models.CharField("First Name ", max_length=100,null=True)
Last_Name = models.CharField("Last Name ",max_length=100,null=True)
Birthday = models.CharField("Birthday ",max_length=10,null=True)
Phone = models.CharField("Phone ",max_length=20,null=True)
Mobile = models.CharField("Mobile ",max_length=20,null=True)
STNO = models.CharField("STNO ",max_length=10,null=True)
Father_Name = models.CharField("Father Name ",max_length=100,null=True)
Father_Job = models.CharField("Father Job ",max_length=100,null=True)
Father_Phone = models.CharField("Father Phone ",max_length=20,null=True)
ID_Code = models.CharField("ID Code ",max_length=10,null=True)
National_ID = models.CharField("National ID ",max_length=10,null=True)
Address = models.CharField("Address ",max_length=200,null=True)
Study_Field = models.CharField("Study Field ",max_length=100,null=True)
Probation = models.BooleanField("Probation ",default=True)
def __STR__ (self):
return self.STNO