What's the cleanest, simplest-to-get running datepicker in Django?

前端 未结 11 1576
-上瘾入骨i
-上瘾入骨i 2020-12-04 09:37

I love the Thauber Schedule datepicker, but it\'s a datetime picker and I can\'t get it to just do dates. Any recommendations for nice looking datepickers that come with ins

11条回答
  •  鱼传尺愫
    2020-12-04 09:48

    Following is what I do, no external dependencies at all.:

    models.py:

    from django.db import models
    
    
    class Promise(models):
        title = models.CharField(max_length=300)
        description = models.TextField(blank=True)
        made_on = models.DateField()
    

    forms.py:

    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(),
            }
    

    my view:

    class PromiseCreateView(CreateView):
        model = Promise
        form_class = PromiseForm
    

    And my template:

    {% csrf_token %} {{ form.as_p }}

    The date picker looks like this:

提交回复
热议问题