MY HTML CODE ===
Это мой html код для добавления оператора в базу данных
{% extends 'Adminside/master.html' %}
{% block content %}
<div class="col-md-12">
<!-- general form elements -->
<div class="card card-primary">
<div class="card-header">
<h3 class="card-title">Add Operator</h3>
</div>
<!-- /.card-header -->
<!-- form start -->
<form role="form" action="{% url 'addoperator' %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="card-body">
<div class="form-group">
<label for="exampleInputEmail1">Name</label>
<input type="text" class="form-control" id="exampleInputname" name="name" placeholder="Enter Your Name">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" name="email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" name="password" placeholder="Password">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Address</label>
<input type="text" class="form-control" id="exampleInputaddress" name="address" placeholder="Enter Your Address">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Phone Number</label>
<input type="text" class="form-control" id="exampleInputnumber" name="number" placeholder="Enter Your Phone Number">
</div>
<div class="col-sm-6">
<!-- radio -->
<div class="form-group clearfix">
<div class="icheck-primary d-inline">
<input type="radio" id="radioPrimary1" name="gender" value="Male" checked="">
<label for="radioPrimary1">
Male
</label>
</div>
<div class="icheck-primary d-inline">
<input type="radio" id="radioPrimary2" value="Female" name="gender">
<label for="radioPrimary2">
Female
</label>
</div>
<div class="icheck-primary d-inline">
<input type="radio" id="radioPrimary3" disabled="">
Gender
</label>
</div>
</div>
</div>
<div class="form-group">
<label for="exampleInputFile">Image Upload</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="userimage" class="form-control" required>
</div>
</div>
</div>
<div class="form-group">
<label for="exampleInputFile">Document Upload</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="document" class="form-control" required>
</div>
</div>
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
<!-- /.card -->
</div>
<!-- /.card -->
</div>
{% endblock %}
МОЙ КОД ПРОСМОТРА =====
Это мой код просмотров для ввода данных
def addoperator(request):
if request.method=="POST":
opera = User.objects.create_user(
username=request.POST['name'],
email=request.POST['email'],
password=request.POST['password']
)
s=Operator()
s.user=opera
s.phonenumber=request.POST['number']
s.gender=request.POST['gender']
s.address=request.POST['address']
s.picture=request.FILES['userimage']
s.document=request.FILES['document']
s.save()
return render(request,'Adminside/addoperators.html')
else:
return render(request,'Adminside/addoperators.html')
МОЙ КОД МОДЕЛЕЙ ===
class Operator(models.Model):
# This field is required.
user = models.OneToOneField(User,on_delete=models.CASCADE,blank=True,default='')
# These fields are optional
gender=models.CharField(max_length=200,default='')
phonenumber=models.CharField(max_length=200,blank=True)
address=models.CharField(max_length=200,blank=True)
picture = models.ImageField(upload_to='operator/', blank=True)
document = models.ImageField(upload_to='operator/', blank=True)
status=models.CharField(max_length=100,default='PENDING')
def isActive(self):
if self.status=="ACTIVE":
return True
else:
return False
def isDisable(self):
if self.status=="DISABLE":
return True
else:
return False
МОЯ ОШИБКА ПРИ РАБОТЕ НА ЭТОМ
OperationalError at /addoperator
table Adminside_operator has no column named user_id
Request Method: POST
Request URL: http://127.0.0.1:8000/addoperator
Django Version: 2.2.4
Exception Type: OperationalError
Exception Value:
table Adminside_operator has no column named user_id
Exception Location: C:\Users\lenovo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 383
Python Executable: C:\Users\lenovo\AppData\Local\Programs\Python\Python37-32\python.exe
Python Version: 3.7.4
Python Path:
Это основная ошибка, из-за которой я застрял на этой штуке, и в этой модели кода я заботился только о пользовательском поле, но выдает ошибку о user_id, которую я не понимаю, откуда она взялась, любая помощь будет буду признателен ...... Спасибо