I have been developing some Django app and there's some duplicated code for different Models. I'd like to create a generic table template and pass the Model class, a list of model instances, and Form classes to it so it can render the page and generate the forms to add/delete elements. Then create some generic add/delete views to work with this Forms.
Which would be the correct part to define the configuration of the template for every different Model? Would it be right if I just create some class static variables and functions like:
class Test(models.Model):
# Model
name = models.CharField(max_length=20)
description = models.TextField(blank=True)
# Template configuration
title = "Test"
table_columns = ['name', ] # Columns I want to show in the table
def get_columns(self):
return [self.name, ]
Or is there some cleaner way to define this kind of things in Django?
EDIT: Seems like some of the information I want to use to configure the Template already has a name and should go inside model.Meta, like verbose_name or verbose_name_plural.