from django.db import models
class Promise(models):
title = models.CharField(max_length=300)
description = models.TextField(blank=True)
made_on = models.DateField()
表格:
from django import forms
from django.forms import ModelForm
from .models import Promise
class DateInput(forms.DateInput):
input_type = 'date'
class PromiseForm(ModelForm):
class Meta:
model = Promise
fields = ['title', 'description', 'made_on']
widgets = {
'made_on': DateInput(),
}
我的观点:
class PromiseCreateView(CreateView):
model = Promise
form_class = PromiseForm
from django.contrib.admin.widgets import AdminDateWidget
class AddInterview(forms.ModelForm):
class Meta:
model = models.Interview
fields = ['candidate', 'date', 'position', 'question_set']
date = forms.DateField(widget=AdminDateWidget())
模板:
<form method="post">
<div class="form-group">
{% csrf_token %}
\{\{ form.media }}
\{\{ form.as_p }}
<p>Note: Date format is yyyy-mm-dd</p>
</div>
from .models import Hello
from django import forms
from bootstrap_datepicker_plus import DatePickerInput
class CreateForm(forms.ModelForm):
class Meta:
model = Hello
fields =[
"Date",
]
widgets = {
'Date': DatePickerInput(),
}