Skip to content

Instantly share code, notes, and snippets.

@benregn
Created August 11, 2011 15:53
Show Gist options
  • Select an option

  • Save benregn/1139995 to your computer and use it in GitHub Desktop.

Select an option

Save benregn/1139995 to your computer and use it in GitHub Desktop.
Only show certain fields when editing in Django
class SomeForm(forms.ModelForm):
class Meta:
model = SomeModel
def __init__(self, *args, **kwargs):
super(SomeForm, self).__init__(*args, **kwargs)
if self.instance:
print "There is an instance, so were editing."
self.fields['anewfieldonlywhenediting'] = forms.CharField()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment