[Answered ]-How can I add class attributes to Models in Django?

2👍

How about a property or method that returns an AnalysisType dependent on an attribute in the particular Analysis subclass?

class Analysis(models.Model):
    ...
    @property
    def analysis_type(self):
        return AnalysisType.objects.get(name=self.analysis_type_name)

class ColorAnalysis(Analysis):
    analysis_type_name = 'color'

class DurabilityAnalysis(Analysis):
    analysis_type_name = 'durability'

Leave a comment