djangosnippets.org: Latest snippets tagged with 'newforms'https://djangosnippets.org/tags/newforms/2012-05-04T06:03:10.000027-05:00Removing old ImageFields and FileFields when updating through admin
2012-05-04T06:03:10.000027-05:00alejandro.alonsohttps://djangosnippets.org/snippets/2742/<p>Example:</p>
<p>admin.site.register(YourCoolModel, CustomModelAdmin)</p>
Freely redistributableRadioSelectWithHelpText
2010-08-14T11:10:40.898785-05:00moxyparkhttps://djangosnippets.org/snippets/2146/<p>A Django form widget which displays help text for individual items in a set of radio buttons.</p>
<p>It overrides the RadioSelect widget, adding a small bit of HTML after each <input> element, with the help text for each item.</p>
<p>It was developed for a Django Dash project I'm working on …</p>
Freely redistributableDynamically adding forms to a formset with jQuery
2009-03-22T05:10:08.420131-05:00elo80kahttps://djangosnippets.org/snippets/1389/<p>I recently worked on an application, where I had to provide a way for users to search for objects based on user-defined properties attached to these objects. I decided to model the search form using a formset, and I thought it'd be a good idea to allow users dynamically add …</p>
Freely redistributableCustom admin widgets by field type
2009-03-10T12:04:49.210800-05:00dgouldinhttps://djangosnippets.org/snippets/1361/<p>There are probably ways to improve the implementation, but this was something I came up with when I wanted to change the default size of all of my CharField admin fields. Now all I have to do in my ModelAdmin class is:</p>
<p>form = get_admin_form(model)</p>
<p>or subclass BaseAdminForm if I …</p>
Freely redistributableFormalchemy hack for newforms-based form validation
2009-01-19T14:40:40.150724-06:00erobhttps://djangosnippets.org/snippets/1291/<p>Very simple proof-of-concept that uses the django.forms library (newforms) for validation,
and formalchemy for saving the model instance using sqlalchemy.</p>
<p>it can be used like this (pseudo-code):</p>
<p>if form.is_valid():
form.save(session=Session, app_label='Contact')</p>
<p>Feel free to improve the concept. Ideally, either use formalchemy or django.forms
but not both like this example. ;-)</p>
Freely redistributableShowOnly widget for froms
2008-11-13T09:19:40.687580-06:00alexmeiselhttps://djangosnippets.org/snippets/1185/<p>This form widget allows you to just display data in a rendered form, not giving the user the opportunity to change it. The initial data will just be carried through the form and showed to the user.</p>
<p>In combination with snipped <a href="http://www.djangosnippets.org/snippets/1184/">1184</a> you can make this even tamper safe. ;-)</p>
Freely redistributableTamper safe HiddenFields
2008-11-13T09:04:12.185779-06:00alexmeiselhttps://djangosnippets.org/snippets/1184/<p>This snippet prevents people from tampering with the data in hidden form fields. This is something you usually want unless you have some Javascript Vodoo going on on the browser side.</p>
<p>For the people scratching their heads:</p>
<p>This form class will dynamically create a clean function for every passed additional …</p>
Freely redistributableRendering a form by looping through its fields in a template
2008-09-14T16:54:06.724955-05:00simonhttps://djangosnippets.org/snippets/1057/<p>See also <a href="http://groups.google.com/group/django-developers/browse_thread/thread/ead13c9424b279a2">this thread</a>. I'm an idiot; this snippet has now been updated to show how you do this without re-inventing the wheel.</p>
Freely redistributableInteger Currency Input
2008-09-04T23:24:10.323928-05:00jgeewaxhttps://djangosnippets.org/snippets/1023/<p>This accepts values such as $1,000,000 and stores them to the database as integers. It also re-renders them to the screen using the django.contrib.humanize.intcomma method which takes 1000000 and turns it into 1,000,000. Useful for large currency fields where the decimals aren't really necessary.</p>
Freely redistributableUsing Akismet/TypePad AntiSpam with Django's new comments framework
2008-08-27T18:27:54.252749-05:00sciyoshihttps://djangosnippets.org/snippets/1006/<p>See the description in the blog entry at <a href="http://sciyoshi.com/blog/2008/aug/27/using-akismet-djangos-new-comments-framework/">http://sciyoshi.com/blog/2008/aug/27/using-akismet-djangos-new-comments-framework/</a>
</p>
Freely redistributableAutomatic stripping textual form fields
2008-08-10T07:55:14.842205-05:00nail.xxhttps://djangosnippets.org/snippets/956/<p>Here is a class decorator that allows not to bother with stripping leading and trailing white space from user input provided via forms. This could be a temporary solution for an issue addressed in the ticket <a href="http://code.djangoproject.com/ticket/6362">#6362</a>.</p>
<p>The documentation is provided in the form of doctest. The decorator works …</p>
Freely redistributableisUnique validator for newforms
2008-07-28T14:49:52.623881-05:00clamothehttps://djangosnippets.org/snippets/923/<p>This is a generic unique field value validator for use with newforms. ( It's handy to plug into newforms-admin.)</p>
<p>Example, with newforms-admin:</p>
<p>`
class LinkAdminForm( ModelForm ):
def clean_url( self ):
return isUnique( self.instance, 'url', self.cleaned_data['url'])</p>
<p>class LinkAdmin( ModelAdmin ):
form = LinkAdminForm</p>
<p>site.register( Link, LinkAdmin )
`</p>
Freely redistributablechange a widget attribute in ModelForm without define the field
2008-07-25T07:01:21.451388-05:00jediehttps://djangosnippets.org/snippets/916/<p>I will change a model form widget attribute without define the complete field. Because many "meta" information are defined in the model (e.g. the help_text) and i don't want to repeat this.</p>
<p>I found a solution: Add/change the widget attribute in the <strong>init</strong>, see example code.</p>
Freely redistributableCredit Card With Newforms
2008-07-23T20:56:23.966492-05:00MasonMhttps://djangosnippets.org/snippets/907/<p>Alternative version of newform code for handling credit cards. Unlike the other two credit-card snippets (http://www.djangosnippets.org/snippets/764/ and http://www.djangosnippets.org/snippets/830/), this uses two drop-down boxes instead of text fields for the expiration date, which is a bit friendlier. It doesn't do as much checking as snippet #764 since we rely on the …</p>
Freely redistributableCustom color field with Javascript color picker
2008-07-21T13:31:45.056470-05:00seanlhttps://djangosnippets.org/snippets/900/<p>A custom model field 'ColorField' which stores a hex color value like '#FFFFFF' and shows a Javascript color picker in the admin rather than a raw text field. It is written to work with the current trunk (i.e. after newforms-admin merge).</p>
<p>You'll need the ColorPicker2.js file found at <a href="http://www.mattkruse.com/javascript/colorpicker/combined_compact_source.html">www.mattkruse.com</a> (his …</p>
Freely redistributable