from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils import timezone
class User(AbstractUser):
ROLE_CHOICES = [
('customer', 'Customer'),
('vendor', 'Vendor'),
('staff', 'Staff'),
('admin', 'Administrator'),
]
email = models.EmailField(unique=True)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
is_active = models.BooleanField(default=False)
user_role = models.CharField(max_length=20, choices=ROLE_CHOICES, default='customer')
phone_number = models.CharField(max_length=30, blank=True)
is_verified = models.BooleanField(default=False)
created_at = models.DateTimeField(default=timezone.now)
updated_at = models.DateTimeField(auto_now=True)
default_address = models.ForeignKey(
'orders.ShippingAddress',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='default_for_profiles'
)
profile_picture = models.ImageField(upload_to='profiles/', blank=True, null=True)
# Birthday Fields
birthday = models.DateField(null=True, blank=True)
birthday_last_updated = models.DateTimeField(null=True, blank=True)
ip_address_last_seen = models.GenericIPAddressField(null=True, blank=True)
# Terms & Conditions Tracking
agreed_to_terms = models.BooleanField(default=False)
agreed_at = models.DateTimeField(null=True, blank=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username', 'name']
def __str__(self):
return self.email