I am trying to avoid repeating the list of fields and model specifier in both a form and a (class based) view.
This answer suggested defining a "meta class" that has the field list in it, and inheriting that class in both the form and the view.
It works fine for the form, but the following code inheriting the list and target model into the view results in this error:
TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()'
I'm at a loss to see how this change causes that error.
forms.py:
class ScenarioFormInfo:
model = Scenario
fields = ['scenario_name', 'description', 'game_type',
'scenario_size', 'weather', 'battle_type', 'attacker',
'suitable_for_axis_vs_AI', 'suitable_for_allies_vs_AI',
'playtested_H2H', 'suitable_for_H2H',
'scenario_file', 'preview']
class ScenarioForm(forms.ModelForm):
Meta = ScenarioFormInfo
views.py:
class ScenarioUpload(generic.CreateView, forms.ScenarioFormInfo):
form_class = ScenarioForm
# model = Scenario
# fields = ['scenario_name', 'description', 'game_type',
# 'scenario_size', 'weather', 'battle_type', 'attacker',
# 'suitable_for_axis_vs_AI', 'suitable_for_allies_vs_AI',
# 'suitable_for_H2H', 'playtested_H2H',
# 'scenario_file', 'preview']