I have a model where some fields could be repeated between 0 and 5 times for the same object.
models.py
:
class FusionTableLayer(models.Model):
layer_name = models.SlugField(max_length=50)
condition1 = models.CharField('SQL Query Conditions', max_length=100, blank=True)
condition2 = models.CharField('SQL Query Conditions', max_length=100, blank=True)
condition3 = models.CharField('SQL Query Conditions', max_length=100, blank=True)
condition4 = models.CharField('SQL Query Conditions', max_length=100, blank=True)
condition5 = models.CharField('SQL Query Conditions', max_length=100, blank=True)
option1 = models.CharField('SQL Query Conditions', max_length=100, blank=True)
option2 = models.CharField('SQL Query Conditions', max_length=100, blank=True)
option3 = models.CharField('SQL Query Conditions', max_length=100, blank=True)
option4 = models.CharField('SQL Query Conditions', max_length=100, blank=True)
option5 = models.CharField('SQL Query Conditions', max_length=100, blank=True)
option6 = models.CharField('SQL Query Conditions', max_length=100, blank=True)
...etc
My question is it better to create a second model with the fields that could be duplicated and use a ForeignKey
to link them?
models.py
:
class EzApp(models.Model):
layer_name = models.SlugField(max_length=50)
class EzAppOptions(models.Model):
app = models.ForeignKey(EzApp)
condition = models.CharField('SQL Query Conditions', max_length=100, blank=True)
option = models.CharField('SQL Query Conditions', max_length=100, blank=True
I know it looks neat like this, but I found it more complicated to adapt forms, views and template to works with a second models with ForeignKey
relationship. For instance, I have to manage two different formsets in the same view. What would be the best practice in this case?