Here's the python code to produce an admin related widget with the edit and delete link also.
* [RelatedFieldWidgetWrapper](http://djangosnippets.org/snippets/2562)
* [related-widget-wrapper.html](http://djangosnippets.org/snippets/2563)
* [related-widget-wrapper.js](http://djangosnippets.org/snippets/2564)
* [RelatedWidgetWrapperAdmin](http://djangosnippets.org/snippets/2565)
Here's the python code to produce an admin related widget with the edit and delete link also.
* [RelatedFieldWidgetWrapper](http://djangosnippets.org/snippets/2562)
* [related-widget-wrapper.html](http://djangosnippets.org/snippets/2563)
* [related-widget-wrapper.js](http://djangosnippets.org/snippets/2564)
* [RelatedWidgetWrapperAdmin](http://djangosnippets.org/snippets/2565)
Here's the python code to produce an admin related widget with the edit and delete link also.
* [RelatedFieldWidgetWrapper](http://djangosnippets.org/snippets/2562)
* [related-widget-wrapper.html](http://djangosnippets.org/snippets/2563)
* [related-widget-wrapper.js](http://djangosnippets.org/snippets/2564)
* [RelatedWidgetWrapperAdmin](http://djangosnippets.org/snippets/2565)
Here's the python code to produce an admin related widget with the edit and delete link also.
* [RelatedFieldWidgetWrapper](http://djangosnippets.org/snippets/2562)
* [related-widget-wrapper.html](http://djangosnippets.org/snippets/2563)
* [related-widget-wrapper.js](http://djangosnippets.org/snippets/2564)
* [RelatedWidgetWrapperAdmin](http://djangosnippets.org/snippets/2565)
This math captcha field and widget was inspired by Justin Quick's django-math-captcha, but I wanted to make it into one form field and not have anything in settings.py. I removed the division and modulo operators to avoid people having to input fractions, and just randomly select the operator.
It leverages Django's built-in MultiValueField to set up the hidden hashed answer to compare the user's input to instead of rendering strings for the fields like django-math-captcha does.
Unit tests soon to follow, but this is used in production at: http://btaylorweb.com/. Enjoy!
This snippet uses the admin FilterSelectMultiple widget in normal forms.
Earlier I tried this without the **internationalization javascript** and failed, so I looked around the web and found couple of posts, they worked but suggest many customizations.
I learnt from them that they had this *jsi18n* javascript included. I included it with mine and it worked.
I have written a [detailed post](http://www.rohanjain.in/coding/2011/06/20/django-using-admin-horizontal-filter-in-forms/) about this.
HTML allows an option in a <select> to be disabled. In other words it will appear in the list of choices but won't be selectable. This is done by adding a 'disabled' attribute to the <option> tag, for example:
`<option value="" disabled="disabled">Disabled option</option>`
This code subclasses the regular Django Select widget, overriding the render_option method to allow disabling options.
Example of usage:
class FruitForm(forms.Form):
choices = (('apples', 'Apples'),
('oranges', 'Oranges'),
('bananas', {'label': 'Bananas',
'disabled': True}), # Yes, we have no bananas
('grobblefruit', 'Grobblefruit'))
fruit = forms.ChoiceField(choices=choices, widget=SelectWithDisabled())
A simple model ColorField that allows picking from a predefined list (currently picked up from settings.py
The widget displays as a row of coloured SPAN's with the hex code inside. Simply click to choose a color.
(requires jQuery in the page assigned to it's normal $ shortcut. Easy to change this is you don't use jQuery in this way)
This makes a 100x100 thumbnail of the image for the image field and shows it in the admin form
combination of http://djangosnippets.org/snippets/955/ and http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/
This function mangles a generated form class to remove the Hold down "Control", or "Command"... messages from the help text. This is really a dirty hack awaiting a proper solution to [Django ticket 9321](http://code.djangoproject.com/ticket/9321).
This function can be useful for forms in the admin interface that use custom widgets. Basic usage:
class MyModelForm(forms.ModelForm):
class Meta:
model = MyModel
class MyAdmin(admin.ModelAdmin):
form = remove_holddown(MyModelForm, ('field1', 'field2'))
Feet and Inches Widget/Field allows users to enter a value in feet, inches and fractional inches and have that value stored as a decimal in your database of choice.
I have this code broken out into separate files, but you can always combine to suit your needs. I have designated file delineation with a single line comment and the name of the file as referenced in the import statements.
The INCH_DECIMALS and INCH_FRACTION constants may be modified to allow smaller increments. My needs for this implementation only required accuracy to 1/16.
Hope this helps someone learn how to use the MultiWidget and MultiValueFields!
Happy Coding.
I basically mixed both BRCPFField and BRCNPJField to create a widget that validates either an CPF or an CNPJ. The doc strings are not localized. So you probably have to hardcode it yourself.
This widget will produce a select box with the range of dates that you input.
**Usage:**
`widget=SelectDateWidget('2010-12-15', '2010-12-20')`
**Output:**
`<select>
<option value="2010-12-15">Wed January 01, 2010</option>
<option value="2010-12-16">Thu January 02, 2010</option>
<option value="2010-12-17">Fri January 03, 2010</option>
<option value="2010-12-18">Sat January 04, 2010</option>
<option value="2010-12-19">Sun January 05, 2010</option>
<option value="2010-12-20">Mon January 06, 2010</option>
</select>`
**UPDATE: Now works in Django 1.4**
Based on luc_j:s snippet (http://djangosnippets.org/snippets/2108/) to show values in ManyToManyFields in the admin. This snippets does that, but also links each value to its corresponding admin change page.
To use, just set the raw_id_fields to the value you want, and let your form inherit from ImproveRawIdFieldsForm.