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.)
- [Answered ]-How to display the post user created with {% if user.is_authenticated == post.author %}?
- [Answered ]-Django setting many_to_many object while doing a bulk_create
- [Answered ]-Match file path in url regex
- [Answered ]-How to decide dynamic work flow for a set of model?
- [Answered ]-How to generate a responsive PDF with Django?
Source:stackexchange.com