[Django]-Creating Django model fields dynamically from method variables during migration

3👍

Kind of duplicate of Programmatically specifying Django model attributes

See this answer https://stackoverflow.com/a/2501419

Seems add_to_class has more logic than just using setattr:
https://github.com/django/django/blob/1eaf38fa87384fe26d1abf6e389d6df1600d4d8c/django/db/models/base.py#L324
Mainly also doing a call to cls._meta.add_field through contribute_to_class

Leave a comment