Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Feature #2 #3

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added wallet_hub/core/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions wallet_hub/core/admin.py
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)
6 changes: 6 additions & 0 deletions wallet_hub/core/apps.py
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'
35 changes: 35 additions & 0 deletions wallet_hub/core/migrations/0001_initial.py
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,
},
),
]
41 changes: 41 additions & 0 deletions wallet_hub/core/migrations/0002_details.py
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)),
],
),
]
17 changes: 17 additions & 0 deletions wallet_hub/core/migrations/0003_rename_details_detail.py
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',
),
]
20 changes: 20 additions & 0 deletions wallet_hub/core/migrations/0004_alter_detail_user.py
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.
102 changes: 102 additions & 0 deletions wallet_hub/core/models.py
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}'
3 changes: 3 additions & 0 deletions wallet_hub/core/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
24 changes: 15 additions & 9 deletions wallet_hub/wallet_hub/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Django settings for wallet_hub project.
Django's settings for wallet_hub project.

Generated by 'django-admin startproject' using Django 5.0.

Expand All @@ -11,23 +11,22 @@
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-628zhv_ztevm!3#+#6=_4v%1%jx()n6@x*#@xkja230cq*=629'
SECRET_KEY = 'django-insecure-628zhv_ztevm!3#+#6=_4v%1%jx()n6@x*#@xkja230cq*=629' # noqa

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
Expand All @@ -37,6 +36,10 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'storages',
'rest_framework',
'drf_spectacular',
'core', # Core App
]

MIDDLEWARE = [
Expand Down Expand Up @@ -69,7 +72,6 @@

WSGI_APPLICATION = 'wallet_hub.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

Expand All @@ -80,7 +82,6 @@
}
}


# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators

Expand All @@ -99,7 +100,6 @@
},
]


# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/

Expand All @@ -111,13 +111,19 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

STATIC_URL = 'static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# Media Files (Which user uploads)
MEDIA_ROOT = BASE_DIR / 'static/media'
MEDIA_URL = '/media/'

# User Model for this entire application
AUTH_USER_MODEL = 'core.User'