When you define your model, you can set default for each field. The default object can be called. For your dateWOCreated field dateWOCreated we can use the called date.today .
To display dates in MM/DD/YYYY format, you need to redefine the widget in your model form.
from django import forms class WorkOrderModelForm(forms.ModelForm): class Meta: model = WorkOrder widgets = { 'dateWOCreated': forms.DateInput(format="%m/%d/%Y")), }
In forms and model forms, the default analog argument is the original argument. For other fields, you may need to dynamically calculate the initial field value in the view. I gave an example below. See the Django Docs for Dynamic Initial Values for more information .
# views.py class WorkOrderModelForm(forms.ModelForm): class Meta: model = WorkOrder def my_view(request, *args, **kwargs): other_field_inital = 'foo'
Alasdair
source share