djangodjango-settingsdjango-sites

Django settings - customize attributes per Site from admin


I'm using django sites framework.

I've a model with a OneToOneField to Site model. This way the admin users can customize each site attributes from the admin panel.

class CustomSite(models.Model):
    site = models.OneToOneField(Site)
    email_host_user = models.EmailField()
    ...

Some of these fields are actually values that should be used in the settings file, like EMAIL_HOST_USER.

How can I use these values in the settings file of the custom sites? is this the correct approach?


Solution

  • Found a solution:

    Settings are saved in the DB using this model. Then I create a custom e-mail backend that I can pass to EmailMultiAlternatives() through the 'connection' param.

    This way I don't need to store the email settings in any settings file.