Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file modified myworld/members/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added myworld/members/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified myworld/members/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file added myworld/members/__pycache__/admin.cpython-312.pyc
Binary file not shown.
Binary file modified myworld/members/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file added myworld/members/__pycache__/apps.cpython-312.pyc
Binary file not shown.
Binary file modified myworld/members/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file modified myworld/members/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file added myworld/members/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified myworld/members/__pycache__/views.cpython-310.pyc
Binary file not shown.
Binary file added myworld/members/__pycache__/views.cpython-312.pyc
Binary file not shown.
8 changes: 7 additions & 1 deletion myworld/members/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from django.contrib import admin
from .models import Students
from .models import Employee

class DjStudentAdmin(admin.ModelAdmin):
list_display = ("first_name", "last_name", "address", "roll_number", "mobile", "branch")
list_filter = ("branch",)

class DjEmployeeAdmin(admin.ModelAdmin):
list_display = ("first_name", "last_name", "address", "emp_id", "mobile", "role","salary")
list_filter = ("role",)

# Register your models here.
admin.site.register(Students, DjStudentAdmin)
admin.site.register(Students, DjStudentAdmin)
admin.site.register(Employee, DjEmployeeAdmin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.1.1 on 2024-10-03 16:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('members', '0002_students_delete_members'),
]

operations = [
migrations.RemoveField(
model_name='students',
name='id',
),
migrations.AddField(
model_name='students',
name='branch',
field=models.CharField(choices=[('BA', 'BA'), ('B.COM', 'B.COM'), ('MBA', 'MBA'), ('CA', 'CA')], default=1, max_length=10),
preserve_default=False,
),
migrations.AlterField(
model_name='students',
name='roll_number',
field=models.AutoField(primary_key=True, serialize=False),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 5.1.1 on 2024-10-04 05:29

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('members', '0003_remove_students_id_students_branch_and_more'),
]

operations = [
migrations.CreateModel(
name='Employee',
fields=[
('first_name', models.CharField(max_length=200)),
('last_name', models.CharField(max_length=200)),
('address', models.CharField(max_length=200)),
('emp_id', models.IntegerField(primary_key=True, serialize=False)),
('salary', models.CharField(max_length=10)),
('mobile', models.CharField(max_length=10)),
('role', models.CharField(choices=[('HR', 'HR'), ('Devloper', 'Devloper'), ('Team_Lead', 'TeamLead'), ('Tester', 'Tester')], max_length=10)),
],
),
migrations.AlterField(
model_name='students',
name='roll_number',
field=models.IntegerField(primary_key=True, serialize=False),
),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified myworld/members/migrations/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file not shown.
23 changes: 21 additions & 2 deletions myworld/members/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,33 @@
("CA", "CA"),
)

EMP_ROLES=(
("HR","HR"),
("Devloper","Devloper"),
("Team_Lead","TeamLead"),
("Tester","Tester"),
)

# Create your models here.
class Students(models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
address = models.CharField(max_length=200)
roll_number = models.IntegerField()
roll_number = models.IntegerField(primary_key=True)
mobile = models.CharField(max_length=10)
branch = models.CharField(max_length=10, choices=BRANCH_CHOICES)

def __str__(self):
return self.first_name + " " + self.last_name
return self.first_name + " " + self.last_name

class Employee(models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
address = models.CharField(max_length=200)
emp_id = models.IntegerField(primary_key=True)
salary = models.CharField(max_length=10)
mobile = models.CharField(max_length=10)
role = models.CharField(max_length=10, choices=EMP_ROLES)

def __str__(self):
return self.first_name + " " + self.last_name
10 changes: 6 additions & 4 deletions myworld/members/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from . import views

urlpatterns = [
path('rest/student/<int:rolno>', views.StudentView.as_view()),
path('rest/student/', views.StudentView.as_view()),
path('rest/student/<str:branch>', views.StudentView.as_view()),
]
path('rest/student/<int:rolno>/', views.StudentView.as_view()),
path('rest/student/', views.StudentView.as_view()),
path('rest/student/branch/<str:branch>/', views.StudentView.as_view()), # For specific branch
path('rest/employee/<int:emp_id>/', views.EmployeeView.as_view()),
path('rest/employee/', views.EmployeeView.as_view())
]
66 changes: 65 additions & 1 deletion myworld/members/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.views import View
from .models import Students
from .models import Students,Employee
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator
import json



@method_decorator(csrf_exempt, name='dispatch')
Expand Down Expand Up @@ -42,3 +44,65 @@ def post(self, request):
mobile= request.POST.get('mobile'),
branch= request.POST.get('branch'))
return JsonResponse({'status': 'sucess'}, status=200)
@method_decorator(csrf_exempt, name='dispatch')
class EmployeeView(View):
def get(self, request, emp_id=None, role=None):
employee_model_list = []
if emp_id:
employee_model_list = Employee.objects.filter(emp_id=emp_id)
elif role:
employee_model_list = Employee.objects.filter(role=role)
else:
employee_model_list = Employee.objects.all()

employees = [
{
"first_name": emp.first_name,
"last_name": emp.last_name,
"address": emp.address,
"emp_id": emp.emp_id,
"salary": emp.salary,
"mobile": emp.mobile,
"role": emp.role
}
for emp in employee_model_list
]

return JsonResponse({'status': 'success', "employees": employees}, status=200)

def post(self, request):
data = json.loads(request.body) # Expecting JSON data
required_fields = ['first_name', 'last_name', 'address', 'emp_id', 'mobile', 'role']

if not all(data.get(field) for field in required_fields):
return JsonResponse({'status': 'failed', "message": "all fields required"}, status=400)

Employee.objects.create(
first_name=data['first_name'],
last_name=data['last_name'],
address=data['address'],
emp_id=data['emp_id'],
salary=data.get('salary'),
mobile=data['mobile'],
role=data['role']
)
return JsonResponse({'status': 'success'}, status=201)

def delete(self, request, emp_id):
try:
employee = Employee.objects.get(emp_id=emp_id)
employee.delete()
return JsonResponse({'status': 'success', 'message': 'Employee deleted.'}, status=204)
except Employee.DoesNotExist:
return JsonResponse({'status': 'failed', 'message': 'Employee not found.'}, status=404)

def put(self, request, emp_id):
data = json.loads(request.body) # Expecting JSON data
try:
employee = Employee.objects.get(emp_id=emp_id)
if 'salary' in data:
employee.salary = data['salary']
employee.save()
return JsonResponse({'status': 'success', 'message': 'Employee updated.'}, status=200)
except Employee.DoesNotExist:
return JsonResponse({'status': 'failed', 'message': 'Employee not found.'}, status=404)
Binary file modified myworld/myworld/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added myworld/myworld/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified myworld/myworld/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file modified myworld/myworld/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file added myworld/myworld/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified myworld/myworld/__pycache__/wsgi.cpython-310.pyc
Binary file not shown.
Loading