34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from django.db import models
|
|
|
|
# Create your models here.
|
|
|
|
from django.utils import timezone
|
|
from phonenumber_field.modelfields import PhoneNumberField
|
|
|
|
class TimeInfoBase(models.Model):
|
|
|
|
created = models.DateTimeField(default=timezone.now)
|
|
last_modified = models.DateTimeField(default=timezone.now)
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
def save(self, *args, **kwargs):
|
|
if not kwargs.pop("skip_last_modified", False) and not hasattr(self, "skip_last_modified"):
|
|
self.last_modified = timezone.now()
|
|
if kwargs.get("update_fields") is not None:
|
|
kwargs["update_fields"] = list({*kwargs["update_fields"], "last_modified"})
|
|
|
|
super().save(*args, **kwargs)
|
|
|
|
# Create your models here.
|
|
class Contact(TimeInfoBase):
|
|
email = models.EmailField(max_length=128)
|
|
name = models.CharField(max_length=128)
|
|
contacted = models.BooleanField(default=False)
|
|
phone_number = PhoneNumberField()
|
|
|
|
street = models.CharField(max_length=128)
|
|
zip_code = models.CharField(max_length=9)
|
|
state = models.CharField(max_length=25)
|
|
city = models.CharField(max_length=128) |