3π
β
One fine way to do this is to put it inside your settings.py
file like so :
ADMIN_CONTACT = {email: 'foo@bar.com', phone: '0585522002'}
Then you can access it anywhere by importing django settings :
from django.conf import settings
from django.core.mail import EmailMessage
def send_message_to_admin(subject,message):
EmailMessage(subject,message,to=[settings.ADMIN_CONTACT['email']]).send()
Caveat :
You can replace those values only by modifying the settings.py
code.
Other solutions :
You can also use the base User
model to get all superusers and mail them, or give a look at django-constance which permits you to store constants on db side, and editable from the django-admin
.
π€Maxime B
Source:stackexchange.com