21 lines
885 B
Python
21 lines
885 B
Python
import os
|
|
from twilio.rest import Client
|
|
from django.db import models
|
|
from mobile_phone.validators.swedishmobile import SwedishTelephoneValidator
|
|
from user_profile.models import User_Profile
|
|
|
|
class Phone_Swedish(models.Model):
|
|
profile = models.ForeignKey(User_Profile, on_delete=models.CASCADE, related_name="mobilephone_swe")
|
|
about = models.CharField("about this phone", max_length=20)
|
|
mobile_number = models.CharField("phone number", max_length=12, validators=[SwedishTelephoneValidator,], unique=True)
|
|
|
|
def send_sms(self, message):
|
|
account_sid = os.environ["PUCKOPRUTT_TWILIO_SID"]
|
|
auth_token = os.environ["PUCKOPRUTT_TWILIO_TOKEN"]
|
|
client = Client(account_sid, auth_token)
|
|
|
|
return client.messages.create(
|
|
body=message,
|
|
from_=os.environ["PUCKOPRUTT_TWILIO_PHONENR"],
|
|
to=self.mobile_number
|
|
) |