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 django.contrib import admin |
||||||
|
|
||||||
from .models import BaseUser,Role |
from .models import BaseUser |
||||||
|
|
||||||
# Register your models here. |
# Register your models here. |
||||||
|
|
||||||
admin.site.register(BaseUser) |
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.contrib.auth.models import AbstractUser |
||||||
from django.dispatch import receiver |
from django.db import models |
||||||
from django.db.models.signals import post_save |
|
||||||
|
|
||||||
|
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): |
# Financial or business-related fields |
||||||
role = models.CharField(max_length=20) |
price = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) |
||||||
role_desc = models.TextField() |
ratings = models.DecimalField(max_digits=3, decimal_places=2, default=0.00) |
||||||
|
|
||||||
def __str__(self): |
# Role and other identifiers |
||||||
return self.role |
role = models.CharField( |
||||||
|
max_length=50, |
||||||
|
choices=[('CLIENT', 'CLIENT'), ('ADMIN', 'ADMIN'), ('SERVICE_PROVIDER', 'SERVICE_PROVIDER')], |
||||||
|
default='CLIENT' |
||||||
|
) |
||||||
|
|
||||||
class BaseUser(AbstractUser): |
# Time-related fields |
||||||
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) |
|
||||||
member_since = models.DateTimeField(auto_now_add=True) |
member_since = models.DateTimeField(auto_now_add=True) |
||||||
profile_updated = models.DateTimeField(auto_now=True) |
profile_updated = models.DateTimeField(auto_now=True) |
||||||
|
|
||||||
USERNAME_FIELD = "email" |
# Token field for verification or authentication purposes |
||||||
REQUIRED_FIELDS = ["image", "contact_number", "bio", "address", "citizenship", "certificate", "price", "password"] |
token = models.CharField(max_length=256, blank=True, null=True) |
||||||
|
|
||||||
def __str__(self): |
def __str__(self): |
||||||
return self.email |
return self.username |
||||||
|
|
||||||
@receiver(post_save, sender=AbstractUser) |
class Meta: |
||||||
def user_to_inactive(sender, instance, created, update_fields, **kwargs): |
verbose_name = 'Base User' |
||||||
if created: |
verbose_name_plural = 'Base Users' |
||||||
instance.is_active = False |
|
||||||
|
Loading…
Reference in new issue