4 changed files with 152 additions and 96 deletions
-
4apps/account/manager.py
-
31apps/account/migrations/0004_consultantuser_alter_user_user_type.py
-
208apps/account/models/groups.py
-
5apps/account/models/user.py
@ -0,0 +1,31 @@ |
|||||
|
# Generated by Django 5.2.12 on 2026-05-18 14:23 |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('account', '0003_alter_clientuser_options_and_more'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.CreateModel( |
||||
|
name='ConsultantUser', |
||||
|
fields=[ |
||||
|
], |
||||
|
options={ |
||||
|
'verbose_name': 'Consultant User', |
||||
|
'verbose_name_plural': 'Consultant Users', |
||||
|
'proxy': True, |
||||
|
'indexes': [], |
||||
|
'constraints': [], |
||||
|
}, |
||||
|
bases=('account.user',), |
||||
|
), |
||||
|
migrations.AlterField( |
||||
|
model_name='user', |
||||
|
name='user_type', |
||||
|
field=models.CharField(choices=[('professor', 'Professor'), ('client', 'Client'), ('student', 'Student'), ('admin', 'Admin'), ('super_admin', 'Super Admin'), ('consultant', 'Consultant')], default='client', help_text='Type of the user.', max_length=20, verbose_name='User Type'), |
||||
|
), |
||||
|
] |
||||
@ -1,96 +1,112 @@ |
|||||
from django.utils.translation import gettext_lazy as _ |
|
||||
from apps.account.models import User |
|
||||
from apps.account.manager import * |
|
||||
|
|
||||
from django.contrib.auth.models import Group |
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
class ProfessorUser(User): |
|
||||
objects = ProfessorUserManager() |
|
||||
|
|
||||
def save(self, *args, **kwargs): |
|
||||
self.user_type = User.UserType.PROFESSOR |
|
||||
super().save(*args, **kwargs) |
|
||||
|
|
||||
group, _ = Group.objects.get_or_create(name="Professor Group") |
|
||||
self.groups.add(group) |
|
||||
|
|
||||
class Meta: |
|
||||
proxy = True |
|
||||
verbose_name = _("Professor User") |
|
||||
verbose_name_plural = _("Professor Users") |
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
class ClientUser(User): |
|
||||
objects = ClientUserManager() |
|
||||
|
|
||||
def save(self, *args, **kwargs): |
|
||||
self.user_type = User.UserType.CLIENT |
|
||||
super().save(*args, **kwargs) |
|
||||
|
|
||||
group, _ = Group.objects.get_or_create(name="Client Group") |
|
||||
self.groups.add(group) |
|
||||
|
|
||||
|
|
||||
class Meta: |
|
||||
proxy = True |
|
||||
|
|
||||
verbose_name = _('User') |
|
||||
verbose_name_plural = _('Users') |
|
||||
ordering = ('-id',) |
|
||||
|
|
||||
|
|
||||
|
|
||||
class AdminUser(User): |
|
||||
objects = AdminUserManager() |
|
||||
|
|
||||
def save(self, *args, **kwargs): |
|
||||
self.user_type = User.UserType.ADMIN |
|
||||
super().save(*args, **kwargs) |
|
||||
|
|
||||
group, _ = Group.objects.get_or_create(name="Admin Group") |
|
||||
self.groups.add(group) |
|
||||
|
|
||||
class Meta: |
|
||||
proxy = True |
|
||||
verbose_name = _("Admin User") |
|
||||
verbose_name_plural = _("Admin Users") |
|
||||
|
|
||||
|
|
||||
|
|
||||
class SuperAdminUser(User): |
|
||||
objects = SuperAdminUserManager() |
|
||||
|
|
||||
def save(self, *args, **kwargs): |
|
||||
self.user_type = User.UserType.SUPER_ADMIN |
|
||||
self.is_staff = True |
|
||||
super().save(*args, **kwargs) |
|
||||
|
|
||||
|
|
||||
|
|
||||
class Meta: |
|
||||
proxy = True |
|
||||
verbose_name = _("Super Admin User") |
|
||||
verbose_name_plural = _("Super Admin Users") |
|
||||
|
|
||||
|
|
||||
|
|
||||
class StudentUser(User): |
|
||||
objects = StudentUserManager() |
|
||||
|
|
||||
def save(self, *args, **kwargs): |
|
||||
self.user_type = User.UserType.STUDENT |
|
||||
super().save(*args, **kwargs) |
|
||||
|
|
||||
group, _ = Group.objects.get_or_create(name="Student Group") |
|
||||
self.groups.add(group) |
|
||||
|
|
||||
class Meta: |
|
||||
proxy = True |
|
||||
verbose_name = _("Student User") |
|
||||
verbose_name_plural = _("Student Users") |
|
||||
|
from django.utils.translation import gettext_lazy as _ |
||||
|
from apps.account.models import User |
||||
|
from apps.account.manager import * |
||||
|
|
||||
|
from django.contrib.auth.models import Group |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
class ProfessorUser(User): |
||||
|
objects = ProfessorUserManager() |
||||
|
|
||||
|
def save(self, *args, **kwargs): |
||||
|
self.user_type = User.UserType.PROFESSOR |
||||
|
super().save(*args, **kwargs) |
||||
|
|
||||
|
group, _ = Group.objects.get_or_create(name="Professor Group") |
||||
|
self.groups.add(group) |
||||
|
|
||||
|
class Meta: |
||||
|
proxy = True |
||||
|
verbose_name = _("Professor User") |
||||
|
verbose_name_plural = _("Professor Users") |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
class ClientUser(User): |
||||
|
objects = ClientUserManager() |
||||
|
|
||||
|
def save(self, *args, **kwargs): |
||||
|
self.user_type = User.UserType.CLIENT |
||||
|
super().save(*args, **kwargs) |
||||
|
|
||||
|
group, _ = Group.objects.get_or_create(name="Client Group") |
||||
|
self.groups.add(group) |
||||
|
|
||||
|
|
||||
|
class Meta: |
||||
|
proxy = True |
||||
|
|
||||
|
verbose_name = _('User') |
||||
|
verbose_name_plural = _('Users') |
||||
|
ordering = ('-id',) |
||||
|
|
||||
|
|
||||
|
|
||||
|
class AdminUser(User): |
||||
|
objects = AdminUserManager() |
||||
|
|
||||
|
def save(self, *args, **kwargs): |
||||
|
self.user_type = User.UserType.ADMIN |
||||
|
super().save(*args, **kwargs) |
||||
|
|
||||
|
group, _ = Group.objects.get_or_create(name="Admin Group") |
||||
|
self.groups.add(group) |
||||
|
|
||||
|
class Meta: |
||||
|
proxy = True |
||||
|
verbose_name = _("Admin User") |
||||
|
verbose_name_plural = _("Admin Users") |
||||
|
|
||||
|
|
||||
|
|
||||
|
class SuperAdminUser(User): |
||||
|
objects = SuperAdminUserManager() |
||||
|
|
||||
|
def save(self, *args, **kwargs): |
||||
|
self.user_type = User.UserType.SUPER_ADMIN |
||||
|
self.is_staff = True |
||||
|
super().save(*args, **kwargs) |
||||
|
|
||||
|
|
||||
|
|
||||
|
class Meta: |
||||
|
proxy = True |
||||
|
verbose_name = _("Super Admin User") |
||||
|
verbose_name_plural = _("Super Admin Users") |
||||
|
|
||||
|
|
||||
|
|
||||
|
class StudentUser(User): |
||||
|
objects = StudentUserManager() |
||||
|
|
||||
|
def save(self, *args, **kwargs): |
||||
|
self.user_type = User.UserType.STUDENT |
||||
|
super().save(*args, **kwargs) |
||||
|
|
||||
|
group, _ = Group.objects.get_or_create(name="Student Group") |
||||
|
self.groups.add(group) |
||||
|
|
||||
|
class Meta: |
||||
|
proxy = True |
||||
|
verbose_name = _("Student User") |
||||
|
verbose_name_plural = _("Student Users") |
||||
|
|
||||
|
|
||||
|
class ConsultantUser(User): |
||||
|
objects = ConsultantUserManager() |
||||
|
|
||||
|
def save(self, *args, **kwargs): |
||||
|
self.user_type = User.UserType.CONSULTANT |
||||
|
super().save(*args, **kwargs) |
||||
|
|
||||
|
group, _ = Group.objects.get_or_create(name="Consultant Group") |
||||
|
self.groups.add(group) |
||||
|
|
||||
|
class Meta: |
||||
|
proxy = True |
||||
|
verbose_name = _("Consultant User") |
||||
|
verbose_name_plural = _("Consultant Users") |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue