[Answered ]-Django multiple instance/inline field

2👍

Django 1.9 introduced support for the PostgreSQL field type ArrayField, which you could use for a list of strings (representing email addresses).

class Entity(models.Model):
    ...
    email_addresses = ArrayField(models.EmailField(max_length=200), blank=True)

0👍

If there is a fixed number of fields, you can do this instead:

class Entity(models.Model):
    name = models.CharField(max_length=255)
    email_1 = models.EmailField(max_length=255)
    email_2 = models.EmailField(max_length=255)
    ...
    email_n = models.EmailField(max_length=255)

But if you don’t know the number of fields in advance (or it’s not the same for every Entity) then no, you’ll have to use a separate model with a foreign key back to the Entity. (In the end, that’s almost certainly a better design anyway.)

👤mipadi

Leave a comment