roo roo roo down the river we go...
This commit is contained in:
		
							
								
								
									
										0
									
								
								users/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								users/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										43
									
								
								users/models.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								users/models.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| from django.contrib.auth.models import AbstractUser | ||||
| from django.db import models | ||||
| from tenants.models import Tenant | ||||
|  | ||||
|  | ||||
| class User(AbstractUser): | ||||
|     """ | ||||
|     Custom User model that extends Django's AbstractUser. | ||||
|     Supports multi-tenancy by linking users to specific tenants. | ||||
|     """ | ||||
|     tenant = models.ForeignKey( | ||||
|         Tenant, | ||||
|         on_delete=models.CASCADE, | ||||
|         related_name='users', | ||||
|         null=True, | ||||
|         blank=True | ||||
|     ) | ||||
|     is_job_seeker = models.BooleanField(default=False) | ||||
|     is_employer = models.BooleanField(default=False) | ||||
|     is_tenant_admin = models.BooleanField(default=False) | ||||
|     is_global_admin = models.BooleanField(default=False) | ||||
|      | ||||
|     # Additional fields for job seekers | ||||
|     resume = models.FileField(upload_to='resumes/', null=True, blank=True) | ||||
|     bio = models.TextField(max_length=1000, blank=True) | ||||
|     phone_number = models.CharField(max_length=15, blank=True) | ||||
|      | ||||
|     # Additional fields for employers | ||||
|     company_name = models.CharField(max_length=200, blank=True) | ||||
|      | ||||
|     created_at = models.DateTimeField(auto_now_add=True) | ||||
|     updated_at = models.DateTimeField(auto_now=True) | ||||
|      | ||||
|     def __str__(self): | ||||
|         return f"{self.username} ({self.email})" | ||||
|      | ||||
|     def get_full_name(self): | ||||
|         """ | ||||
|         Return the user's full name. | ||||
|         """ | ||||
|         if self.first_name and self.last_name: | ||||
|             return f"{self.first_name} {self.last_name}" | ||||
|         return self.username | ||||
							
								
								
									
										15
									
								
								users/serializers.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								users/serializers.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| from rest_framework import serializers | ||||
| from django.contrib.auth.models import User | ||||
| from .models import User as CustomUser | ||||
|  | ||||
|  | ||||
| class UserSerializer(serializers.ModelSerializer): | ||||
|     """ | ||||
|     Serializer for the User model. | ||||
|     """ | ||||
|     class Meta: | ||||
|         model = CustomUser | ||||
|         fields = ('id', 'username', 'email', 'first_name', 'last_name', 'is_job_seeker',  | ||||
|                   'is_employer', 'is_tenant_admin', 'is_global_admin', 'bio', 'phone_number', | ||||
|                   'company_name', 'created_at', 'updated_at') | ||||
|         read_only_fields = ('id', 'created_at', 'updated_at') | ||||
							
								
								
									
										8
									
								
								users/urls.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								users/urls.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| from django.urls import path | ||||
| from . import views | ||||
|  | ||||
| urlpatterns = [ | ||||
|     path('', views.UserListView.as_view(), name='user-list'), | ||||
|     path('<int:pk>/', views.UserDetailView.as_view(), name='user-detail'), | ||||
|     path('current/', views.current_user, name='current-user'), | ||||
| ] | ||||
							
								
								
									
										33
									
								
								users/views.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								users/views.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| from django.shortcuts import render | ||||
| from rest_framework import generics, permissions | ||||
| from rest_framework.response import Response | ||||
| from rest_framework.decorators import api_view | ||||
| from .models import User | ||||
| from .serializers import UserSerializer | ||||
|  | ||||
|  | ||||
| class UserListView(generics.ListAPIView): | ||||
|     """ | ||||
|     API view to retrieve list of users. | ||||
|     """ | ||||
|     queryset = User.objects.all() | ||||
|     serializer_class = UserSerializer | ||||
|     permission_classes = [permissions.IsAuthenticated] | ||||
|  | ||||
|  | ||||
| class UserDetailView(generics.RetrieveAPIView): | ||||
|     """ | ||||
|     API view to retrieve a single user. | ||||
|     """ | ||||
|     queryset = User.objects.all() | ||||
|     serializer_class = UserSerializer | ||||
|     permission_classes = [permissions.IsAuthenticated] | ||||
|  | ||||
|  | ||||
| @api_view(['GET']) | ||||
| def current_user(request): | ||||
|     """ | ||||
|     API endpoint to retrieve the current user's profile. | ||||
|     """ | ||||
|     serializer = UserSerializer(request.user) | ||||
|     return Response(serializer.data) | ||||
		Reference in New Issue
	
	Block a user