[Django]-Set Django ModelForm visible fields at runtime?

4👍

from django.forms import ModelForm
from wherever import Customer
def formClassFactory(model,fields):
  ff = fields
  mm = model
  class formClass(ModelForm):
    class Meta:
      model  = mm
      fields = ff
  return formClass
form_class = formClassFactory( ('first_name','last_name') )

Leave a comment