parent
9993f2f132
commit
480d7501be
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,8 +1,8 @@ |
||||
from django.contrib import admin |
||||
|
||||
from .models import BaseUser,Role |
||||
from .models import BaseUser |
||||
|
||||
# Register your models here. |
||||
|
||||
admin.site.register(BaseUser) |
||||
admin.site.register(Role) |
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,43 +1,41 @@ |
||||
from django.db import models |
||||
from django.contrib.auth.models import AbstractUser |
||||
from django.dispatch import receiver |
||||
from django.db.models.signals import post_save |
||||
from django.db import models |
||||
|
||||
class BaseUser(AbstractUser): |
||||
# Additional fields to extend the default user model |
||||
|
||||
# Profile-related fields |
||||
image = models.ImageField(upload_to='user_profiles/', blank=True, null=True) |
||||
bio = models.TextField(blank=True, null=True) |
||||
address = models.TextField(blank=True, null=True) |
||||
contact_number = models.CharField(max_length=15, blank=True, null=True) |
||||
citizenship = models.CharField(max_length=100, blank=True, null=True) |
||||
certificate = models.FileField(upload_to='certificates/', blank=True, null=True) |
||||
|
||||
# Verification and status |
||||
is_verified = models.BooleanField(default=False) |
||||
|
||||
class Role(models.Model): |
||||
role = models.CharField(max_length=20) |
||||
role_desc = models.TextField() |
||||
# Financial or business-related fields |
||||
price = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) |
||||
ratings = models.DecimalField(max_digits=3, decimal_places=2, default=0.00) |
||||
|
||||
def __str__(self): |
||||
return self.role |
||||
# Role and other identifiers |
||||
role = models.CharField( |
||||
max_length=50, |
||||
choices=[('CLIENT', 'CLIENT'), ('ADMIN', 'ADMIN'), ('SERVICE_PROVIDER', 'SERVICE_PROVIDER')], |
||||
default='CLIENT' |
||||
) |
||||
|
||||
class BaseUser(AbstractUser): |
||||
username = None |
||||
image = models.ImageField(null=True, blank=True) |
||||
bio = models.TextField(null=True, blank=True) |
||||
address = models.CharField(null=True, blank=True, max_length=50) |
||||
contact_number = models.CharField(unique=True, max_length=15, null=True, blank=True) |
||||
email = models.EmailField(unique=True) |
||||
citizenship = models.FileField(upload_to='uploads/citizenship', null=True, blank=True) |
||||
certificate = models.FileField(upload_to='uploads/certificates', blank=True, null=True) |
||||
#is_activated = models.BooleanField(default=False) |
||||
token = models.CharField(max_length=64,blank=True,null=True) |
||||
is_verified = models.BooleanField(default=False) |
||||
price = models.DecimalField(max_digits=9999, decimal_places=2, null=True, blank=True) |
||||
ratings = models.IntegerField(default=1) |
||||
role = models.ForeignKey('Role', on_delete=models.SET_NULL, related_name="users", null=True, blank=True) |
||||
# Time-related fields |
||||
member_since = models.DateTimeField(auto_now_add=True) |
||||
profile_updated = models.DateTimeField(auto_now=True) |
||||
|
||||
USERNAME_FIELD = "email" |
||||
REQUIRED_FIELDS = ["image", "contact_number", "bio", "address", "citizenship", "certificate", "price", "password"] |
||||
# Token field for verification or authentication purposes |
||||
token = models.CharField(max_length=256, blank=True, null=True) |
||||
|
||||
def __str__(self): |
||||
return self.email |
||||
return self.username |
||||
|
||||
@receiver(post_save, sender=AbstractUser) |
||||
def user_to_inactive(sender, instance, created, update_fields, **kwargs): |
||||
if created: |
||||
instance.is_active = False |
||||
class Meta: |
||||
verbose_name = 'Base User' |
||||
verbose_name_plural = 'Base Users' |
||||
|
Loading…
Reference in new issue