def getModel(cls, django_app): """ Returns an Entity model linked to a specified application. Args: - django_app: Name of the application where the generated model will be installed. """ fields = cls.fields fields.update({'save': cls.getSaveMethod()}) return create_model(cls.model_name, fields=fields, app_label=django_app)
def getModel(cls, ValueClass): """ Returns an abstract BaseSubValue model linked to a specified application and its Value model. Args: - ValueClass: the Value model that the sub-attribute will be linked to """ fields = {'base_value': models.ForeignKey(ValueClass)} opts = {'abstract': True} return create_model(cls.model_name, fields=fields, options=opts, app_label=ValueClass._meta.app_label)
def getModel(cls, EntityClass, extra_fields={}): """ Returns an Attribute Model linked to a specified application and its Entity Model. Args: - EntityClass: the Entity model that the attribute will be linked to - extra_fields (optional): other fields to be added to the Attribute model """ fields = {'definition': models.CharField(max_length=64), 'entity': models.ForeignKey(EntityClass), 'date_created': models.DateField(auto_now_add=True), '__unicode__': lambda self: self.definition} fields.update(extra_fields) return create_model(cls.model_name, fields=fields, app_label=EntityClass._meta.app_label)
def getModel(cls, EntityClass, AttributeClass, extra_fields={}): """ Returns a Value Model linked to a specified application, its Entity model and its Attribute model. Args: - EntityClass: the Entity model that the attribute will be linked to - AttributeClass: the Attribute model that the attribute will be linked to - extra_fields (optional): other fields to be added to the Value model """ fields = {'attribute': models.ForeignKey(AttributeClass), 'entity': models.ForeignKey(EntityClass), 'date_created': models.DateField(auto_now_add=True), 'subvalue': cls.getSubValueProperty(), '__unicode__': lambda self: str(self.subvalue)} fields.update(extra_fields) return create_model(cls.model_name, fields=fields, app_label=EntityClass._meta.app_label)