-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from reactVishnu/patch@v1
Added Feature #2
- Loading branch information
Showing
11 changed files
with
244 additions
and
9 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.contrib import admin | ||
from .models import Detail | ||
# Register your models here. | ||
|
||
admin.site.register(Detail) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CoreConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'core' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Generated by Django 5.0 on 2023-12-09 11:26 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('auth', '0012_alter_user_first_name_max_length'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='User', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('password', models.CharField(max_length=128, verbose_name='password')), | ||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), | ||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), | ||
('email', models.EmailField(max_length=100, unique=True)), | ||
('name', models.CharField(max_length=255)), | ||
('is_active', models.BooleanField(default=True)), | ||
('is_staff', models.BooleanField(default=False)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), | ||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Generated by Django 5.0 on 2023-12-09 11:41 | ||
|
||
import core.models | ||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Details', | ||
fields=[ | ||
('e_id', models.AutoField(auto_created=True, primary_key=True, serialize=False)), | ||
('first_name', models.CharField(max_length=100)), | ||
('last_name', models.CharField(max_length=100)), | ||
('address', models.CharField(max_length=252)), | ||
('aadhar_no', models.CharField(max_length=12)), | ||
('pan_no', models.CharField(max_length=10)), | ||
('profile_pic', models.ImageField(blank=True, null=True, upload_to=core.models.user_image_upload_path)), | ||
('aadhar_file', models.FileField(blank=True, null=True, upload_to=core.models.user_aadhar_upload_path)), | ||
('pan_file', models.FileField(blank=True, null=True, upload_to=core.models.user_pan_upload_path)), | ||
('blood_group', models.CharField(max_length=5)), | ||
('designation', models.CharField(blank=True, max_length=200, null=True)), | ||
('employee_code', models.CharField(editable=False, max_length=255, null=True)), | ||
('date_of_birth', models.DateField(blank=True, null=True)), | ||
('current_package', models.IntegerField(blank=True, null=True)), | ||
('monthly_income', models.IntegerField(blank=True, null=True)), | ||
('gender', models.CharField(blank=True, choices=[('male', 'Male'), ('female', 'Female'), ('other', 'Other')], max_length=10, null=True)), | ||
('marital_status', models.CharField(blank=True, choices=[('married', 'Married'), ('single', 'Single'), ('divorced', 'Divorced')], max_length=10, null=True)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 5.0 on 2023-12-09 11:45 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0002_details'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameModel( | ||
old_name='Details', | ||
new_name='Detail', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 5.0 on 2023-12-09 11:55 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0003_rename_details_detail'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='detail', | ||
name='user', | ||
field=models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin | ||
from django.contrib.auth import get_user_model | ||
from django.utils import timezone | ||
|
||
|
||
# User Manager | ||
class UserManager(BaseUserManager): | ||
def create_user(self, email, password=None, **extra_fields): | ||
"""Create, save and return a new user""" | ||
if not email: | ||
raise ValueError('User must have an email address.') | ||
user = self.model(email=self.normalize_email(email), **extra_fields) | ||
user.set_password(password) | ||
user.save(using=self._db) | ||
|
||
return user | ||
|
||
def create_superuser(self, email, password=None): | ||
"""For creating a superuser or an admin user which is going to have the access for django admin panel.""" | ||
user = self.create_user(email, password) | ||
user.is_staff = True | ||
user.is_superuser = True | ||
user.save(using=self._db) | ||
|
||
return user | ||
|
||
|
||
# Create your models here. | ||
class User(AbstractBaseUser, PermissionsMixin): | ||
""" | ||
User in the system | ||
""" | ||
email = models.EmailField(max_length=100, unique=True) | ||
name = models.CharField(max_length=255) | ||
is_active = models.BooleanField(default=True) | ||
is_staff = models.BooleanField(default=False) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
|
||
USERNAME_FIELD = 'email' | ||
objects = UserManager() | ||
|
||
|
||
def user_image_upload_path(instance, filename): | ||
# Assuming the user's name is stored in a field called 'name' | ||
filename = 'profile_pic.jpeg' | ||
return f'profile/{instance.user.email}/{filename}' | ||
|
||
|
||
def user_aadhar_upload_path(instance, filename): | ||
# Assuming the user's name is stored in a field called 'name' | ||
return f'aadhar/{instance.user.email}/{filename}' | ||
|
||
|
||
def user_pan_upload_path(instance, filename): | ||
# Assuming the user's name is stored in a field called 'name' | ||
return f'pan/{instance.user.email}/{filename}' | ||
|
||
|
||
class Detail(models.Model): | ||
e_id = models.AutoField(primary_key=True, auto_created=True, serialize=False) | ||
user = models.OneToOneField(get_user_model(), on_delete=models.CASCADE, editable=False) | ||
first_name = models.CharField(max_length=100) | ||
last_name = models.CharField(max_length=100) | ||
address = models.CharField(max_length=252) | ||
aadhar_no = models.CharField(max_length=12) | ||
pan_no = models.CharField(max_length=10) | ||
profile_pic = models.ImageField(upload_to=user_image_upload_path, null=True, blank=True, ) | ||
aadhar_file = models.FileField(upload_to=user_aadhar_upload_path, null=True, blank=True, ) | ||
pan_file = models.FileField(upload_to=user_pan_upload_path, null=True, blank=True, ) | ||
blood_group = models.CharField(max_length=5) | ||
designation = models.CharField(max_length=200, null=True, blank=True) | ||
employee_code = models.CharField(max_length=255, null=True, editable=False) | ||
date_of_birth = models.DateField(null=True, blank=True) | ||
current_package = models.IntegerField(null=True, blank=True) | ||
monthly_income = models.IntegerField(null=True, blank=True) | ||
GENDER_CHOICES = [ | ||
('male', 'Male'), | ||
('female', 'Female'), | ||
('other', 'Other'), | ||
] | ||
gender = models.CharField(max_length=10, choices=GENDER_CHOICES, null=True, blank=True) | ||
MARITIAL_CHOICES = [ | ||
('married', 'Married'), | ||
('single', 'Single'), | ||
('divorced', 'Divorced') | ||
] | ||
marital_status = models.CharField(max_length=10, choices=MARITIAL_CHOICES, null=True, blank=True) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
|
||
def save(self, *args, **kwargs): | ||
self.updated_at = timezone.now() | ||
super().save(*args, **kwargs) | ||
|
||
# Set the employee_code based on e_id after saving | ||
self.employee_code = f'emp{str(self.e_id).zfill(4)}' | ||
super().save(update_fields=['employee_code'], *args, **kwargs) | ||
|
||
def __str__(self): | ||
return f'User: {self.user.name}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters