Skip to content

Instantly share code, notes, and snippets.

View dashdrum's full-sized avatar

Dan Gentry dashdrum

View GitHub Profile
@dashdrum
dashdrum / fields.py
Last active December 13, 2015 19:08 — forked from davidbgk/fields.py
Modified from the original to mirror the functionality provided by the ModelChoiceField. 1. empty_label default is set to u"---------" 2. If there is no initial value for a required field, the empty_label is prepended. What this does is override the ChoiceField's default behavior of using the first value in the choices list if the user makes no …
from django.forms import ChoiceField
''' Based on https://gist.github.com/davidbgk/651080
modified to mirror the functionality of ModelChoiceField '''
class EmptyChoiceField(ChoiceField):
def __init__(self, choices=(), empty_label=u"---------", required=True, widget=None, label=None,
initial=None, help_text=None, *args, **kwargs):
# prepend an empty label unless the field is required AND
@dashdrum
dashdrum / gist:03858d79ddfd9bba44d6
Created December 15, 2014 21:32
Formset Mixins
class FormsetMixin(object):
""" Use for a form + 1 formset """
detail_form_class = None
def get_detail_form_class(self):
"""
Returns the detail form class to use in this view
"""
return self.detail_form_class
from __future__ import unicode_literals
from django.forms import ChoiceField
''' Based on https://gist.github.com/davidbgk/651080
modified to mirror the functionality of ModelChoiceField '''
class EmptyChoiceField(ChoiceField):
def __init__(self, choices=(), empty_label="---------", required=True, widget=None, label=None,
initial=None, help_text=None, *args, **kwargs):

Keybase proof

I hereby claim:

  • I am dashdrum on github.
  • I am dashdrum (https://keybase.io/dashdrum) on keybase.
  • I have a public key ASDgh02asru5cZ6Rn9TwTka_IfA1PyHT-nfXhvVI8u7Fzgo

To claim this, I am signing this object: