开发者

Calendar input like admin application Django

Using the django admin application for a date it displays Today | CalendarSymbol. I am using a datefield in开发者_高级运维 my form and I thought it would do this for me how would i go about doing this? As i would normally use the jquery datepicker plugin is this the way to go?

Thanks in Advance,

Dean


Usually I do something like this:

class CalendarWidget(forms.TextInput):
    class Media:
        css = {
            'all': ('datepicker.css',)
        }
        js = ('datepicker.js')

    def __init__(self, attrs={}):
        super(CalendarWidget, self).__init__(
            attrs={'class': 'datepicker', 
                   'size': '14', 
                   'readonly':'readonly'})

class ToDoForm(forms.ModelForm):
    class Meta:
        model = yourModel
    your_date_field = forms.DateTimeField(widget=CalendarWidget)

Finally in your template, something like this:

$(".datepicker").datepicker();

I hope it helps.


I used the admin like widget in the end was easy to implement plus no external libraries.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜