class ReportForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ReportForm, self).__init__(*args, **kwargs)
for key in self.fields.keys():
self.fields[key].widget = forms.TextInput(attrs={'class': 'form-control'})
class ReportOne(ReportForm):
class Meta:
model = models.ReportOne
exclude = ('pk', 'code', )
class ReportTwo(ReportForm):
class Meta:
model = ReportTwo
exclude = ('pk', 'code', )
class ReportForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.Meta.model = getattr(models, args[0])
self.Meta.exclude = ('pk', 'code')
super(ReportForm, self).__init__(*args, **kwargs)
for key in self.fields.keys():
self.fields[key].widget = forms.TextInput(attrs={'class': 'form-control'})
ReportForm('ReportOne')
ReportForm('ReportTwo')
class ReportForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ReportForm, self).__init__(*args, **kwargs)
for key in self.fields.keys():
self.fields[key].widget = forms.TextInput(attrs={'class': 'form-control'})
@staticmethod
def getInstance(name, *args, **kwargs):
if name == "one":
return ReportOne(*args, **kwargs)
else:
return ReportTwo(*args, **kwargs)
newform = ReportForm.getInstance("one")
newform = ReportForm.getInstance("two")