initial commit
This commit is contained in:
commit
ce809235e5
34 changed files with 736 additions and 0 deletions
55
phonebook/models.py
Normal file
55
phonebook/models.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.core.validators import RegexValidator
|
||||
|
||||
|
||||
# Create your models here.
|
||||
class PhonebookEntry(models.Model):
|
||||
first_name = models.CharField(max_length=255)
|
||||
last_name = models.CharField(max_length=255)
|
||||
|
||||
enabled = models.BooleanField(default=True)
|
||||
blocked = models.BooleanField(default=False)
|
||||
favourite = models.BooleanField(default=False)
|
||||
vip = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = _("Phonebook Entries")
|
||||
ordering = ["first_name", "last_name"]
|
||||
|
||||
|
||||
class PhonebookNumber(models.Model):
|
||||
class ContactTypes(models.TextChoices):
|
||||
SIP = "SIP", _("SIP")
|
||||
MOBILE = "MOBILE", _("Mobile")
|
||||
FIXED = "FIXED", _("Fixed")
|
||||
HOME = "HOME", _("Home")
|
||||
BUSINESS = "BUSINESS", _("Business")
|
||||
EXTENSION = "EXTENSION", _("Extension")
|
||||
|
||||
number = models.CharField(
|
||||
max_length=255,
|
||||
validators=[
|
||||
RegexValidator(
|
||||
regex="^\+[0-9]+$",
|
||||
message="Phone number must be entered in the format: +999999999",
|
||||
)
|
||||
],
|
||||
)
|
||||
type = models.CharField(
|
||||
max_length=20, choices=ContactTypes, default=ContactTypes.SIP
|
||||
)
|
||||
|
||||
contact = models.ForeignKey(
|
||||
PhonebookEntry, on_delete=models.CASCADE, related_name="numbers"
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.number} ({self.contact.first_name} {self.contact.last_name}, {self.type.title()})"
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = _("Phonebook Numbers")
|
||||
ordering = ["number"]
|
Loading…
Add table
Add a link
Reference in a new issue