Django比较表单的一个字段

时间:2018-11-05 16:41:30

标签: django-models django-forms django-templates django-views django-2.0

我有一个难题,我有一个需要输入身份证明文件的表格,但是我想要的是当公司的员工填写该字段然后提交表格时,表格会显示一条消息,指出客户确实存在,因为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 %}

0 个答案:

没有答案