Set Format of DateField

Hello,

I tried setting the format of a DateField using the following code:

class SetUpForm_Personal(ModelForm):
    class Meta:
        model = Account
        fields = ['prename', 'surname', 'birthdate', 'punkte']
        widgets = {
            'prename': TextInput(attrs={"class": "form-control form-group", "required:": "", "placeholder": "Vorname*", "style": "max-width: 800px; margin-left: auto; margin-right: auto;"}),
            'surname': TextInput(attrs={"class": "form-control dragArea col-md col-sm-12 form-group mb-3", "required:": "", "placeholder": "Nachname*", "style": "max-width: 800px; margin-left: auto; margin-right: auto;"}),
            'punkte': TextInput(attrs={"class": "form-control dragArea col-md col-sm-12 form-group mb-3", "required:": "", "placeholder": "Aktien Anzahl*", "style": "max-width: 800px; margin-left: auto; margin-right: auto;"}),
            'birthdate': DateField(widget=forms.DateInput(format='%d/%m/%Y', attrs={'class': 'datepicker'}), input_formats=('%d/%m/%Y', )
       
        )
        
        }
        
        labels = {
            'prename': (),
            'surname': (),
            'birthdate': (),
            'punkte': (),


        }

But Im getting this error:

'DateField' object has no attribute 'is_hidden'

How can I prevent this, is there a better solution?

It looks like the line of code for the DateField widget is incomplete, are you sure that this is precisely the code you have?

By default Django understands the date format like so: year-month-day. With hyphens and not forward slash between the numbers.

You would have to change this in settings to enable django to understand this date format.

This line needs to be added in settings.py (at the end of the script)


DATE_FORMAT = "d/m/Y"

USE_L10N should then be set to false:

USE_L10N = False

I think you are also missing a parenthesis at the end of your line.

It is isn’t illustrated very well in the documentation but here is a link:

https://docs.djangoproject.com/en/4.0/ref/settings/#date-format