Wednesday, November 13, 2013

Re: Widget isn't sticking?

Try:

expiry_date = forms.DateField(widget=CalendarWidget())

On Tuesday, November 12, 2013 5:41:27 PM UTC-8, Lachlan Musicman wrote:
Hola,

I've set up a CalendarWidget as per the docs
https://docs.djangoproject.com/en/1.6/topics/forms/media/ and can see
correct results in the shell:


forms.py
---------

class CalendarWidget(forms.TextInput):
    class Media:
        css = {
            'all': (settings.STATIC_URL + 'css/datepicker.css',)
        }
        js = (settings.STATIC_URL + 'js/bootstrap-datepicker.js',)

...

class CarrierWizardForm1(forms.Form):
    part_numbers = forms.ModelChoiceField(queryset=PartNumber.objects.all())
    expiry_date = forms.DateField(widget=CalendarWidget)


shell
-------

>>> from inventory import forms
>>> w = forms.CalendarWidget()
>>> print(w.media)
<link href="/static/css/datepicker.css" type="text/css" media="all"
rel="stylesheet" />
<script type="text/javascript"
src="/static/js/bootstrap-datepicker.js"></script>
>>> f = forms.CarrierWizardForm1()
>>> print(f.media)
<link href="/static/css/datepicker.css" type="text/css" media="all"
rel="stylesheet" />
<script type="text/javascript"
src="/static/js/bootstrap-datepicker.js"></script>


But in the browser I'm not seeing the new widget.

What am I doing wrong? Do I have to explicitly pull the assets into
the template in question?
Am I meant to be explicitly referring to the widget in the template?

I note that using the built in SelectDateWidget works fine:

from django.forms.extras.widgets import SelectDateWidget
class CarrierWizardForm1(forms.Form):
    part_numbers = forms.ModelChoiceField(queryset=PartNumber.objects.all())
    #expiry_date = forms.DateField(widget=CalendarWidget)
    expiry_date = forms.DateField(widget=SelectDateWidget)


Cheers
L.


--
From this perspective it is natural that anarchism be marked by
spontaneity, differentiation, and experimentation that it be marked by
an expressed affinity with chaos, if chaos is understood to be what
lies outside or beyond the dominant game or system. Because of the
resistance to definition and categorisation, the anarchist principle
has been variously interpreted as, rather than an articulated
position, "a moral attitude, an emotional climate, or even a mood".
This mood hangs in dramatic tension between utopian hope or dystopian
nihilism...
-----
http://zuihitsu.org/godspeed-you-black-emperor-and-the-politics-of-chaos

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/24f84c8e-f8bc-4dc0-a519-b1c3d4740d9b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate