I have a Model with 100 identical fields named field_1
, field_2
, and so on.
Is there a method to define these fields in a cycle (just to avoid writing and maintaining 100 rows)?
That is, now I have to name each field separately:
class MyModel(models.Model):
field_1 = models.CharField(...)
field_2 = models.CharField(...)
field_3 = models.CharField(...)
field_4 = models.CharField(...)
field_5 = models.CharField(...)
...
I would like something like:
class MyModel(models.Model):
for i in range(1, 101):
eval("field_%d = models.CharField(...)"%i)
but, of course, I do not like eval
.
Any hint?
NOTE I need such a model because I'm doing a two-step importation from CSV/Excel: first, I put Excel rows into this table, then process the table and import data in the actual application (where I'm using ForeignKeys, as suggested)