Skip to content

Instantly share code, notes, and snippets.

@pielgrzym
Created June 15, 2011 13:00
Show Gist options
  • Save pielgrzym/1027029 to your computer and use it in GitHub Desktop.
Save pielgrzym/1027029 to your computer and use it in GitHub Desktop.
class MortgageForm(ModelForm):
class Meta:
model = Mortgage
def __init__(self, *args, **kwargs):
"""
Custom init method
"""
import ipdb
ipdb.set_trace()
super(MortgageForm, self).__init__(*args, **kwargs)
commentable_fields = []
if hasattr(self._meta.model, "_commentable_fields"):
commentable_fields = self._meta.model._commentable_fields
for i, field in enumerate(self.fields):
if field in commentable_fields:
cf = forms.fields.CharField(label='comment_%d' % i)
cf.is_hidden = False
self.Meta.fields.insert(i+1, cf)
class MortgageAdmin(admin.ModelAdmin):
inlines = [
# inlines here
]
form = MortgageForm
fields = [
# field list here
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment