HTML5 Placeholder from FormField label
This allows for easy generation of HTML5 placeholders based on a form_field's label. Use like so: {% form_placeholder form.username %}
- forms
- html5
- form_field
This allows for easy generation of HTML5 placeholders based on a form_field's label. Use like so: {% form_placeholder form.username %}
Use this snippet to list all errors in a form. The message will be shown in a boostrap-type alert which can be 'closed' using a dismiss button. The **field label** and the **error** will be listed. e.g. > * Name: This field is required > * Email: Please enter a valid email
showing all the errors at the top of the page
Daniel Roseman's snippet, updated will all fixes mentioned in the comments of the first version + some other things to make it work under Django 1.4. South, and dumpdata are working. There's an ugly int(....) at the validate function in order to cast each value as an integer before comparing it to default choices : I needed this, but if you're storing strings values, just remove the int(......) wrapper. ------------------------------------- Orginal readme Usually you want to store multiple choices as a manytomany link to another table. Sometimes however it is useful to store them in the model itself. This field implements a model field and an accompanying formfield to store multiple choices as a comma-separated list of values, using the normal CHOICES attribute. You'll need to set maxlength long enough to cope with the maximum number of choices, plus a comma for each. The normal get_FOO_display() method returns a comma-delimited string of the expanded values of the selected choices. The formfield takes an optional max_choices parameter to validate a maximum number of choices.
A Django 1.4 wizard mixin for use cases with a wizard step on the frontpage of your site -- with a request path of `'/'`. Just define the name of the step (e.g. `root_step = 'landing_page'`) and it does the setup and redirection automatically.
If you read the docstring and the example you should get a clue what this Code does. I didn't want a big function everytime that handles every specific form, formset combinations so this how i can add/edit Models with specific Forms given to the magic_handle_inlineformsets function. It also works for Forms without innline_formsets.
Out of the box, Django e-mail fields for both database models and forms only accept plain e-mail addresses. For example, `[email protected]` is accepted. On the other hand, full e-mail addresses which include a human-readable name, for example the following address fails validation in Django: Joe Hacker <[email protected]> This package adds support for validating full e-mail addresses. **Database model example** from django import models from full_email.models import FullEmailField class MyModel(models.Model): email = FullEmailField() **Forms example** from django import forms from full_email.formfields import FullEmailField class MyForm(forms.Form): email = FullEmailField(label='E-mail address') I maintain this code in a [GitHub gist](https://gist.github.com/1505228). It includes some unit tests as well.
Template filter to mark-up individual form fields. Usage : In template - {% load form_custom %} then for a form field - {{ form.field|form_row:"default" }} for default wrapper or - {{ form.field|form_row:"lbl_cls=some_class_name&reqd=no" }} to pass option args seperated by & Optional args are :- wrapper_cls - override default field wrapper div class name error_cls - override default field error div class name lbl_cls - override default label_tag div class name label - yes/no default is yes - output label_tag reqd - yes/no default is yes - marks up required fields as bold with label ending with * See code for all default args.
Improved for BootStrap details: http://twitter.github.com/bootstrap/ Using: class AnyForm(forms.Form, CustomForm): pass Template: <form> {{ form.render_errors }} {{ form.as_div }} </form>
As it took me a save option name instead of its value. This field are solves this rare problem.
**Your model:** class TicketItem(models.Model): hours = models.DecimalField(decimal_places=2, max_digits=6) day = models.DateField() order = models.ForeignKey(Order) tickets = models.ManyToManyField(Ticket) Now you want to auto save m2m fields in your forms.TicketItemCreateForm: 1. inherit from m2mForm-Class 2. define m2m_field(s) **Example:** class TicketItemCreateForm(m2mForm): m2m_field = 'tickets' class Meta: model = models.TicketItem
A simple way to add fields to an existing form, demonstrated using `django-registration`.
**Description** A filestorage system that + is whitlisted, + changes the file name and targeting directory to put the file in - with respect to (runtime) instance information. + replaces files if they exists with the same name. Kudos to [jedie](http://djangosnippets.org/users/jedie/) - http://djangosnippets.org/snippets/977/
You just use standart django query terms, for example: <form> <input class="field_text filter_from" type="text" name="cost__gte" placeholder="from" value="{% if request.GET.cost__gte %}{{ request.GET.cost__gte }}{% endif %}"> <input class="field_text filter_to" type="text" name="cost__lte" placeholder="to" value="{% if request.GET.cost__lte %}{{ request.GET.cost__lte }}{% endif %}"> </form> model: class Object(models.Model): cost = models.IntergerField() objects = ObjectManager()
These decorators can be used to make some model/form fields readonly. **Sample usage:** # Use this decorator on form with readonly fields.` @modelform_with_readonly_fields` class FooAdminForm(forms.ModelForm):` ... # This decorator shoud be used to protect selected fields ` # from modification after initial save.` @has_readonly_fields` class Foo(models.Model):` read_only_fields = ('name', )` ... **Result** will be the same as shown in this post: [Readonly field](http://stackoverflow.com/questions/324477/in-a-django-form-how-to-make-a-field-readonly-or-disabled-so-that-it-cannot-be/1424453#1424453) and [Readonly model field](http://www.djangozen.com/blog/read-only-fields-in-models)
141 snippets posted so far.