SelectDateWidget dosent work

84 views
Skip to first unread message

shahab emami

unread,
Apr 24, 2017, 8:26:20 PM4/24/17
to Django users
hello
i have a birth date filed in my  model this:


                                     birth_date   = models.DateField (blank=True,null=True)

my forms.py i have this:


class ProfileForm(ModelForm):
    birth_date= forms.DateField(widget=forms.SelectDateWidget)
    class Meta:
        model = Member
        exclude = ()


then i expect a dropdownlist for birth_date in template but it is only a regular input


i always work with function base view but now I am working with class base view for first time.


then i have to say i think this is the problem . i mean i can see result of SelectDateWidget  in function base view but in class base view NO.


I want to create inline formset according to this tutorial:


https://medium.com/@adandan01/django-inline-formsets-example-mybook-420cc4b6225d


I only add one filed to parent field because i want to save birth_date of user. then i user SelectDateWidget in

forms.py but it dosent work anymore .

 It seems nobody had this problem before because i couldn't find my answer from the internet ond Stack Overflow.


can you help me please?







Melvyn Sopacua

unread,
Apr 25, 2017, 1:38:39 PM4/25/17
to django...@googlegroups.com

On Monday 24 April 2017 17:26:20 shahab emami wrote:

 

> class ProfileForm(ModelForm):

> birth_date= forms.DateField(widget=forms.SelectDateWidget)

> class Meta:

> model = Member

> exclude = ()

>

>

> then i expect a dropdownlist for birth_date in template but it is only

> a regular input

 

Did you set the form_class attribute?

--

Melvyn Sopacua

kenton Fletcher

unread,
Apr 25, 2017, 4:58:52 PM4/25/17
to Django users

This is the way I use a SelectDateWidget in my forms.py.

 
from django.forms import ModelForm, SelectDateWidget


class ProfileForm(ModelForm):
 

    class Meta:

        widget ={' birth_date': SelectDateWidget() }

        model = Member

        fields = '__all__'

        exclude = ()


 

Matthew Pava

unread,
Apr 25, 2017, 5:45:48 PM4/25/17
to django...@googlegroups.com

Widget should be plural:

widgets ={' birth_date': SelectDateWidget() }

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/48d44fc3-7dff-4d9a-bba9-849106a4f978%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages