سؤال

I am creating a Django application in which users can have multiple emails including a primary one. In Django, the SQL user table has a single CharField to store a single email address.

My current plan is to create a new model called say "EmailAddress" and then link this model to the User model via a foreign key, thus allowing for multiple emails. The primary email address of a user is stored in the email column of the user table.

However, I was wondering if there was a more efficient and reliable way to do this. I am currently storing the primary email address twice, which I feel could compromise data integrity.

Thank you.

هل كانت مفيدة؟

المحلول

Your plan sounds completely reasonable. In most scenarios, I would agree with @Hoff's answer, however, adding repeating fields as he suggests is just flat-out the wrong approach. Since the foreign key will be on EmailAddress, you could get by without creating a custom profile in this scenario, though for pretty much every other scenario a custom profile would be the way to go.

نصائح أخرى

The question is pretty old, but you can use this extension https://github.com/scott2b/django-multimail . It supports more emails and handles validation as well.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top