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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion myworld/dockerfiles/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN apk update && \
# Install requirements
RUN pip install --upgrade pip
RUN pip install Django psycopg2==2.9.3
# Create directories
# Create directories
RUN mkdir -p /root/workspace/src
COPY ./ /root/workspace/site
# Switch to project directory
Expand Down
30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3"
services:
web_service:
build:
context: ./
dockerfile: ./Dockerfile
image: workshop1_web
container_name: workshop_web_container
stdin_open: true # docker attach container_id
tty: true
ports:
- "8000:8000"
volumes:
- .:/root/workspace/site

psql-db:
image: "postgres:14"
container_name: psql-db
environment:
- PGPASSWORD=123456
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=123456
ports:
- "5432:5432"
volumes:
- db:/var/lib/postgresql/data

volumes:
db:
driver: local
Binary file modified myworld/db.sqlite3
Binary file not shown.
29 changes: 0 additions & 29 deletions myworld/docker-compose.yml

This file was deleted.

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 removed myworld/members/__pycache__/__init__.cpython-38.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 removed myworld/members/__pycache__/admin.cpython-38.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 removed myworld/members/__pycache__/apps.cpython-38.pyc
Binary file not shown.
Binary file modified myworld/members/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file added myworld/members/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file removed myworld/members/__pycache__/models.cpython-38.pyc
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 removed myworld/members/__pycache__/urls.cpython-38.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.
Binary file removed myworld/members/__pycache__/views.cpython-38.pyc
Binary file not shown.
9 changes: 7 additions & 2 deletions myworld/members/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from django.contrib import admin
from .models import Students
from .models import Students, 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", "mobile", "salary", "department")
list_filter = ("department","id")

# Register your models here.
admin.site.register(Students, DjStudentAdmin)
admin.site.register(Students, DjStudentAdmin)
admin.site.register(Employee, DjEmployeeAdmin)
1 change: 1 addition & 0 deletions myworld/members/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@


class MembersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'members'
4 changes: 2 additions & 2 deletions myworld/members/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.1 on 2022-09-15 16:33
# Generated by Django 5.1.1 on 2024-10-04 04:39

from django.db import migrations, models

Expand All @@ -14,7 +14,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Members',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('firstname', models.CharField(max_length=255)),
('lastname', models.CharField(max_length=255)),
],
Expand Down
5 changes: 3 additions & 2 deletions myworld/members/migrations/0002_students_delete_members.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.1.1 on 2022-09-15 17:56
# Generated by Django 5.1.1 on 2024-10-04 06:22

from django.db import migrations, models

Expand All @@ -13,12 +13,13 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Students',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=200)),
('last_name', models.CharField(max_length=200)),
('address', models.CharField(max_length=200)),
('roll_number', models.IntegerField()),
('mobile', models.CharField(max_length=10)),
('branch', models.CharField(choices=[('BA', 'BA'), ('B.COM', 'B.COM'), ('MBA', 'MBA'), ('CA', 'CA')], max_length=10)),
],
),
migrations.DeleteModel(
Expand Down
25 changes: 25 additions & 0 deletions myworld/members/migrations/0003_employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.1.1 on 2024-10-04 09:07

from django.db import migrations, models


class Migration(migrations.Migration):

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

operations = [
migrations.CreateModel(
name='Employee',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=200)),
('last_name', models.CharField(max_length=200)),
('address', models.CharField(max_length=200)),
('mobile', models.CharField(max_length=10)),
('salary', models.IntegerField()),
('department', models.CharField(max_length=10)),
],
),
]
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.
Binary file not shown.
11 changes: 11 additions & 0 deletions myworld/members/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,16 @@ class Students(models.Model):
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

class Employee(models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
address = models.CharField(max_length=200)
mobile = models.CharField(max_length=10)
salary = models.IntegerField()
department = models.CharField(max_length=10)

def __str__(self):
return self.first_name + " " + self.last_name
2 changes: 1 addition & 1 deletion myworld/members/templates/myfirst.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ <h1>Hello World!</h1>
<p>Welcome to my first Django project!</p>

</body>
</html>
</html>
35 changes: 35 additions & 0 deletions myworld/members/templates/student_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Display Student</title>
</head>
<body>
<h1>Student List</h1>
<div>
<table>
<thead>
<tr>
<th>Student ID</th>
<th>Student Name</th>
<th>Student Email</th>
<th>Student Phone</th>
<th>Student Address</th>
</tr>
<tbody>
{% for student in students %}
<tr>
<td>{{ student.student_id }}</td>
<td>{{ student.student_name }}</td>
<td>{{ student.student_email }}</td>
<td>{{ student.student_phone }}</td>
<td>{{ student.student_address }}</td>
</tr>
{% endfor %}
</tbody>
</thead>
</table>
</div>
</body>
</html>
2 changes: 2 additions & 0 deletions myworld/members/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
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/employee/', views.EmployeeView.as_view()),
path('rest/employee/<int:id>', views.EmployeeView.as_view()),
]
93 changes: 80 additions & 13 deletions 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
from django.shortcuts import render
import json


@method_decorator(csrf_exempt, name='dispatch')
Expand All @@ -15,20 +17,22 @@ def get(self, request, rolno=None, branch=None):
student_model_list = Students.objects.filter(roll_number=rolno)
elif branch:
student_model_list = Students.objects.filter(branch=branch)
else:
student_model_list = Students.objects.all()
except Students.DoesNotExist:
return JsonResponse({'status': 'failed', "students": None}, status=400)
students = []
for student in student_model_list:
data = {
"first_name" : student.first_name,
"last_name": student.last_name,
"address": student.address,
"roll_number": student.roll_number,
"mobile": student.mobile,
"branch": student.branch
}
students.append(data)
return JsonResponse({'status': 'success', "students": students}, status=200)
# students = []
# for student in student_model_list:
# data = {
# "first_name" : student.first_name,
# "last_name": student.last_name,
# "address": student.address,
# "roll_number": student.roll_number,
# "mobile": student.mobile,
# "branch": student.branch
# }
# students.append(data)
return render(request, 'student_list.html', {'students': student_model_list})

def post(self, request):
if not request.POST.get('first_name') or not request.POST.get('last_name') or not request.POST.get('address') or not request.POST.get('roll_number') or not request.POST.get('mobile'):
Expand All @@ -42,3 +46,66 @@ 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, id=None):
try:
employee_id = id or request.GET.get('id')
if not employee_id:
return JsonResponse({'status': 'failed', 'message': 'Employee ID is required'}, status=400)

employee = Employee.objects.get(id=employee_id)
employee_data = {
"first_name": employee.first_name,
"last_name": employee.last_name,
"address": employee.address,
"mobile": employee.mobile,
"salary": employee.salary,
"department": employee.department
}
return JsonResponse({'status': 'sucess', "employee": employee_data}, status=200)
except Employee.DoesNotExist:
return JsonResponse({'status': 'failed', "employee": None}, status=400)


def post(self, request):
if not request.POST.get('first_name') or not request.POST.get('last_name') or not request.POST.get('address') or not request.POST.get('mobile'):
return JsonResponse({'status': 'failed', "message" : "all fields required"}, status=500)

Employee.objects.create(
first_name= request.POST.get('first_name'),
last_name= request.POST.get('last_name'),
address= request.POST.get('address'),
mobile= request.POST.get('mobile'),
salary= request.POST.get('salary'),
department= request.POST.get('department'))
return JsonResponse({'status': 'sucess'}, status=200)

def delete(self, request, id):
try:
employee = Employee.objects.get(id=id)
employee.delete()
return JsonResponse({'status': 'success'}, status=200)
except Employee.DoesNotExist:
return JsonResponse({'status': 'failed', "employee": None}, status=400)


def put(self, request, id):
try:
employee = Employee.objects.get(id=id)
data = json.loads(request.body.decode('utf-8'))
employee.first_name = data.get('first_name', employee.first_name)
employee.last_name = data.get('last_name', employee.last_name)
employee.address = data.get('address', employee.address)
employee.mobile = data.get('mobile', employee.mobile)
employee.salary = data.get('salary', employee.salary)
employee.department = data.get('department', employee.department)
employee.save()
return JsonResponse({'status': 'success'}, status=200)
except Employee.DoesNotExist:
return JsonResponse({'status': 'failed', "employee": None}, 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 removed myworld/myworld/__pycache__/__init__.cpython-38.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 removed myworld/myworld/__pycache__/settings.cpython-38.pyc
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 removed myworld/myworld/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified myworld/myworld/__pycache__/wsgi.cpython-310.pyc
Binary file not shown.
Binary file added myworld/myworld/__pycache__/wsgi.cpython-312.pyc
Binary file not shown.
Binary file removed myworld/myworld/__pycache__/wsgi.cpython-38.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion myworld/myworld/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
"""

import os
Expand Down
Loading