Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 'DateField' object has no attribute 'is_hidden'

I need to put a input type date and i'm using a widget but throws this error

models.py

class Proyecto(models.Model):
    nombre = models.CharField(max_length=255)
    fecha_de_inicio = models.DateField()
    fecha_de_termino = models.DateField(blank=True, null=True)

forms.py

from django import forms
from .models import Proyecto
from django.forms.fields import DateField
class ProyectoForm(forms.ModelForm):

    def save(self, usuario=None):
        self.instance.encargado = usuario
        super(ProyectoForm,self).save()

    class Meta:
        model = Proyecto
        fields = ('nombre', 'fecha_de_inicio', 'costo', 'objetivo', 'descripcion', 'cliente', 'estado')
        widgets = {
            'fecha_de_inicio': DateField(),
        }
like image 632
user3643294 Avatar asked May 16 '14 04:05

user3643294


1 Answers

There is a problem in setting up the widgets. You cannot set the widget of a field to a form field:

widgets = {'fecha_de_inicio': DateField()}

Instead of a Datefield, you need to provide a widget, e.g. DateInput:

widgets = {'fecha_de_inicio': forms.DateInput(format='%d/%m/%Y')}
like image 151
alecxe Avatar answered Sep 22 '22 01:09

alecxe