I am trying to create a model.Model with the columnheaders(key) and types(value). I tried it with the setattr(self,columnheader,columntype) but this seems to not work. Can i dynamically alter the table with django inbuilts or do i have to use raw sql?
Example dict:
_dict = { "column_1": models.IntegerField(),
"column_2": models.IntegerField()
}
>Solution :
You can assign this to the local variables, but I would advise against this:
_dict = {
'column_1': models.IntegerField(),
'column_2': models.IntegerField()
}
class MyModel(models.Model):
locals().update(_dict)