I have this Datetime field in Django
update_date = models.DateField()
But I want the Calen开发者_如何转开发dar to pop up. In docs, they say to write this
class CalendarWidget(forms.TextInput):
class Media:
css = {
'all': ('pretty.css',)
}
js = ('animations.js', 'actions.js')
Now I have a few problems:
- Where to declare this class and how to use it
- I don't have pretty.css , animation.css , how can get it
- Do I need to do programming for it??
The files 'pretty.css', 'animations.js' and 'actions.js' are not included with Django, this code in the docs is an example only. It is your duty to write the code for fancier widgets - personally I like jQuery widgets (see the reference links bellow). From the docs:
Which JavaScript toolkit? Many JavaScript toolkits exist, and many of them include widgets (such as calendar widgets) that can be used to enhance your application. Django has deliberately avoided blessing any one JavaScript toolkit. Each toolkit has its own relative strengths and weaknesses - use whichever toolkit suits your requirements. Django is able to integrate with any JavaScript toolkit.
Supposing you got all the css and js defined for your fancy widget, in the ModelForm you have to override the field widget like this:
class SomeForm(forms.ModelForm):
...
update_date = forms.CharField(widget=CalendarWidget)
...
Don't forget to display the form media at the template header.
Look these answers:
- What's the cleanest, simplest-to-get running datepicker in Django?
- https://groups.google.com/group/django-users/browse_thread/thread/8bd4675ba642ebcb?pli=1
精彩评论