I need to generate a DB Model from an array of strings like this:
strings = ['String 1', 'String 2', ..., 'String N-1', 'String N']
I need a table in my DB with this shape
ORIGIN | STRING 1 | STRING 2 |...| STRING N
char | char | char |...| char
I created my Model Class like this:
class FixedCharField(models.Field):
def __init__(self, max_length, *args, **kwargs):
self.max_length = max_length
super(FixedCharField, self).__init__(max_length=max_length, *args, **kwargs)
def db_type(self):
return 'char(%s)' % self.max_length
class MyModel(models.Model):
strings = get_my_array() # aux function to generate the array
origin = FixedCharField(max_length=3)
for string in strings:
string = FixedCharField(max_length=3)
As you can see, I need each column name to have a fixed size of 3, so I used the custom FixedCharField that I found in this link Fixed Char Field
My question is, will this work? And this is the correct approach to do this?
itemvariable, hence you end up with only the last one.