Skip to content

Instantly share code, notes, and snippets.

@gileno
Created November 8, 2011 01:20
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 gileno/1346747 to your computer and use it in GitHub Desktop.
Save gileno/1346747 to your computer and use it in GitHub Desktop.
Fields dinâmicos
from django import forms
from minhaapp.models import MeuModel
class MeuForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(MeuForm, self).__init__(*args, **kwargs)
if self.instance:
for key, value in self.instance.context():
self.fields[key] = forms.CharField(label=key, initial=value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment