Login

Tag "widget"

Snippet List

Add a CSS class to every field indicating what kind of field it is

The admin site uses a CSS class for each kind of field so that they can be styled easily. This snippet gives ModelForms a similar feature. See also: [James Bennett's explanation of formfield_callback](http://stackoverflow.com/questions/660929/how-do-you-change-the-default-widget-for-all-django-date-fields-in-a-modelform/661171#661171)

  • css
  • field
  • widget
  • modelform
  • callback
Read More

Use JQuery Calendar in ModelForm

The important code really is just setting up the base site to use jquery and then using the javascript function to show the calendar on a widget with the .vDateField class set. The DateField modeltype automatically gets the css class .vDateField when using ModelForms.

  • jquery
  • calendar
  • widget
  • modelform
Read More

NoneWidget

Sometime may be useful to disable the HTML output from formfield to template.

  • widgets
  • widget
Read More

Select Dropdown Widget with jQueryUI

This widget can be imported in your forms.py file and used like so: formfield = forms.ModelChoiceField(widget=SelectDropdownWidget, queryset=Model.objects.all()) The javascript is provided by [filament group's Scott and his jQueryUI Selectmenu](http://www.filamentgroup.com/lab/jquery_ui_selectmenu_an_aria_accessible_plugin_for_styling_a_html_select/). In addition to the javascript you will need [jQuery (the latest release is fine) and jQuery UI](http://jqueryui.com/). The convenient thing is that this widget will style to match whichever jQuery UI you've 'rolled' or selected, making it highly customizable! Hopefully this helps others who wanted a nice widget with jQuery and were sad to find there were no nice default options, enjoy! :)

  • dropdown
  • jquery
  • select
  • widget
  • jqueryui
Read More

Multiple Select Widget with jQueryUI

This widget can be imported in your forms.py file and used like so: formfield = forms.ModelMultipleChoiceField(widget=MultiSelectWidget, queryset=Model.objects.all()) The javascript is provided by [Michael's Multiselect](http://github.com/michael/multiselect/tree/next). In addition to the javascript you will need [jQuery (the latest release is fine) and jQuery UI](http://jqueryui.com/). The convenient thing is that this widget will style to match whichever jQuery UI you've 'rolled' or selected, making it highly customizable! Hopefully this helps others who wanted a nice widget with jQuery and were sad to find there were no nice default options, enjoy! :)

  • jquery
  • widget
  • multiple select
  • multiselect
  • jqueryui
Read More

Django Jalali Calendar Widget

This is a simple calendar widget in Django 1.2 for Jalali Calendar usages. It actually sends a Gregorian value to server, so if you need further manipulations, you can use [GNU Jalali Calendar](http://home.gna.org/jalali-calendar/). You should also have [JalaliJSCalendar](http://farhadi.ir/works/jalalijscalendar) set up in your project. Also posted on: [Django Jalali Calendar Widget](http://texscribbles.blogspot.com/2010/06/django-jalali-calendar-widget.html)

  • calendar
  • widget
  • jalali
  • farsi
  • persian
Read More

Widget for CommaSeparatedIntegerField with pre-defined choices

Widget for editing CommaSeparatedIntegerField with a set of checkboxes. Each checkbox corresponds to single integer value. So, choices should be pre-defined for widget. **Example** Assume, we need a registration form for some event with time frame for 3 days, starting at Monday. User can select any of 3 days, so we need to show 3 checkboxes. Here's the basic example for such form: class EventRegistrationForm(forms.Form): days = forms.CharField(widget=NumbersSelectionWidget( ['Mon', 'Tue', 'Wed'], range(1, 4)))

  • forms
  • widget
  • comma-separated
Read More

ISBN model field: displays 10- and 13-digit variants and external links

Requires [PyISBN](http://pypi.python.org/pypi/pyisbn/0.5.2). Use like so: class Book(models.Model): title = models.TextField() isbn = ISBNField() ... the link in the widget can be changed to amazon, borders, you name it. If the DB version is a 13-digit ISBN, the display box contains the 10-digit, labeled; and vice-versa.

  • django
  • model
  • python
  • widget
  • modelfield
  • isbn
  • books
Read More

SelectDateWidget with format: day, month, year

This is the same as [django.forms.extras.widgets.SelectDateWidget](http://code.djangoproject.com/browser/django/trunk/django/forms/extras/widgets.py#L16) but changing the order of the rendered select boxes to: day, month, year.

  • date
  • widgets
  • widget
  • year
  • month
  • selectdatewidget
  • dates
  • day
Read More

Ajax auto-filtered Foreign Key Field

Say you have a ModelChoiceField and you want the choices to depend on the value of another field in the form... that's what these bits are for. They need to be used in conjunction with the Ajax views from: [code.google.com/p/django-ajax-filtered-fields/](http://code.google.com/p/django-ajax-filtered-fields/) See my blog for full details: [anentropic.wordpress.com](http://anentropic.wordpress.com) ...um, this is work in progress and the explanatory blog post is not up yet...

  • ajax
  • widget
Read More

django-mptt enabled replacement for SelectBox.js

This snippet is used in conjunction with the code in [#1779](http://www.djangosnippets.org/snippets/1779/) to make an mptt-enabled version of the FilteredSelectMultiple widget. See my blog for full details: [http://anentropic.wordpress.com](http://anentropic.wordpress.com/2009/11/05/more-django-mptt-goodness-filteredselectmultiple-m2m-widget/)

  • widget
  • mptt
Read More

78 snippets posted so far.