我有一个难题,我有一个需要输入身份证明文件的表格,但是我想要的是当公司的员工填写该字段然后提交表格时,表格会显示一条消息,指出客户确实存在,因为IDENTITY DOCUMENT已在系统中注册。我正在使用GenericViews。
CustomerForm(forms.ModelForm)类:
class Meta:
model = CustomerData
fields = [
'name',
'last_name',
'dni',
'phone_number',
'address',
'age',
'birth_date',
'civil_status',
]
labels = {
'name': 'Nombre',
'last_name': 'Apellidos',
'dni': 'DNI',
'phone_number': 'Telefono',
'address': 'Direccion',
'age': 'Edad',
'birth_date': 'Fecha de Nacimiento',
'civil_status': 'Estado Civil',
}
widgets = {
'name': forms.TextInput(attrs={'class' : 'form-control'}),
'last_name':forms.TextInput(attrs={'class' : 'form-control'}),
'dni':forms.TextInput(attrs={'class' : 'form-control'}),
'phone_number':forms.TextInput(attrs={'class' : 'form-control'}),
'address':forms.Textarea(attrs={'class' : 'form-control'}),
'age':forms.NumberInput(attrs={'class' : 'form-control'}),
'birth_date':forms.DateInput(attrs={'class' : 'form-control'}),
'civil_status':forms.TextInput(attrs={'class' : 'form-control'}),
}
Class CustomerData(models.Model): “” 个人资料模型。
Proxy model that extend the base data
with other informarion.
"""
name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
dni = models.CharField(max_length=8)
phone_number = models.CharField(max_length=20, blank=True)
address = models.TextField()
age = models.PositiveIntegerField(default=18)
birth_date = models.DateField()
civil_status = models.CharField(max_length=1)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
class Meta:
verbose_name_plural = "Customer Data"
def __str__(self):
""" Return username """
return self.name + " " + self.last_name
class RegisterNewCustomer(CreateView):
model = CustomerData
form_class = CustomerForm
template_name = 'customers/customers_form.html'
success_url = reverse_lazy('customers:customers_list')
class CustomersList(ListView):
model=CustomerData
template_name = 'customers/customers_list.html'
class CustomerUpdate(UpdateView):
model = CustomerData
form_class = CustomerForm
template_name = 'customers/customers_form.html'
success_url = reverse_lazy('customers:customers_list')
class CustomerDelete(DeleteView):
model = CustomerData
template_name = 'customers/customers_delete.html'
success_url = reverse_lazy('customers:customers_list')
{% extends 'base.html' %}
{% block content %}
<form method = "post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit"> Guardar </button>
</form>
{% endblock %}