Skip to content

Instantly share code, notes, and snippets.

@jakul
Created August 11, 2011 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakul/1139175 to your computer and use it in GitHub Desktop.
Save jakul/1139175 to your computer and use it in GitHub Desktop.
Introspection rules example
class RegexField(CharField):
def __init__(self, regex=None, *args, **kwargs):
self.regex = regex
super(CharField,self).__init__(*args, **kwargs)
def formfield(self, **kwargs):
from django import forms
defaults = {
'form_class': forms.RegexField,
'regex': self.regex,
}
defaults.update(kwargs)
return super(CharField, self).formfield(**defaults)
# South introspection rules
from south.modelsinspector import add_introspection_rules
rules = [
(
# Which classes this rule applies to
(RegexField,),
# Rules to recover positional args
[],
# Rules to recover named args
{
"regex": ["regex", {'default':None}],
},
),
]
add_introspection_rules(rules, ['^tariffx\.fields\.RegexField',])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment