diff --git a/README.md b/README.md index 4b0e63d4..c38e5c03 100644 --- a/README.md +++ b/README.md @@ -5,25 +5,97 @@ To develop a Django application to store and retrieve data from a database using ## Entity Relationship Diagram -Include your ER diagram here +![image](https://github.com/jabezs2005/django-orm-app/assets/147473463/4624c801-d2f9-4474-ae14-726068645b53) + + + ## DESIGN STEPS ### STEP 1: +Make new folder and give it a name and fork the folder from repository. ### STEP 2: +Now inside this folder create a folder called "django-orm-app" ### STEP 3: +Now navigate to dataproject folder. + +### STEP 4: +Now create a app called myapp + +### STEP 5: +Now apply all migrations + +### STEP 6: +now write the necessary code for models.py and admin.py + +### STEP 7: +Now create a superuser with global user.name and global user.email and mail.id as admin@example.com and a password. -Write your own steps +#### STEP 8: +Now run the server and naviagte the admin page + +### STEP 9: +Now add 10 employees id. ## PROGRAM Include your code here +### models.py + + write the following code in models.py + ```from django.db import models +from django.contrib import admin + + +# Create your models here. +class Student (models.Model): + referencenumber=models.CharField(max_length=20,help_text="reference number") + name=models.CharField(max_length=100) + age=models.IntegerField() + email=models.EmailField() + + +class StudentAdmin(admin.ModelAdmin): + list_display=('referencenumber','name','age','email') + + + +class Employee (models.Model): + emp_id=models.CharField(primary_key=True,max_length=4,help_text='Employee ID') + ename=models.CharField(max_length=50) + post=models.CharField(max_length=20) + salary=models.IntegerField() + + +class EmployeeAdmin(admin.ModelAdmin): + list_display=('emp_id','ename','post','salary') +``` + +write the following code in admin.py + +``` +from django.contrib import admin +from .models import Student,StudentAdmin,Employee,EmployeeAdmin + + +# Register your models here. +admin.site.register(Student,StudentAdmin) +admin.site.register(Employee,EmployeeAdmin) + +``` ## OUTPUT -Include the screenshot of your admin page. +### Server Output: + + +![django server output](https://github.com/jabezs2005/django-orm-app/assets/147473463/f672e449-02bc-4834-97d2-7c0201621150) + ## RESULT + +Successfully created the django-orm-app. + diff --git a/dataproject/dataproject/__pycache__/__init__.cpython-311.pyc b/dataproject/dataproject/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..3d0a367d Binary files /dev/null and b/dataproject/dataproject/__pycache__/__init__.cpython-311.pyc differ diff --git a/dataproject/dataproject/__pycache__/settings.cpython-311.pyc b/dataproject/dataproject/__pycache__/settings.cpython-311.pyc new file mode 100644 index 00000000..bd9c93aa Binary files /dev/null and b/dataproject/dataproject/__pycache__/settings.cpython-311.pyc differ diff --git a/dataproject/dataproject/__pycache__/urls.cpython-311.pyc b/dataproject/dataproject/__pycache__/urls.cpython-311.pyc new file mode 100644 index 00000000..ff8920df Binary files /dev/null and b/dataproject/dataproject/__pycache__/urls.cpython-311.pyc differ diff --git a/dataproject/dataproject/__pycache__/wsgi.cpython-311.pyc b/dataproject/dataproject/__pycache__/wsgi.cpython-311.pyc new file mode 100644 index 00000000..7a268e7f Binary files /dev/null and b/dataproject/dataproject/__pycache__/wsgi.cpython-311.pyc differ diff --git a/dataproject/dataproject/settings.py b/dataproject/dataproject/settings.py index 0f429541..db28c904 100644 --- a/dataproject/dataproject/settings.py +++ b/dataproject/dataproject/settings.py @@ -11,6 +11,7 @@ """ from pathlib import Path +import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -37,6 +38,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'myapp' ] MIDDLEWARE = [ @@ -118,3 +120,6 @@ # https://docs.djangoproject.com/en/3.1/howto/static-files/ STATIC_URL = '/static/' +STATICFILES_DIRS=[ + os.path.join(BASE_DIR,'static') +] diff --git a/dataproject/db.sqlite3 b/dataproject/db.sqlite3 new file mode 100644 index 00000000..960662dc Binary files /dev/null and b/dataproject/db.sqlite3 differ diff --git a/dataproject/myapp/__init__.py b/dataproject/myapp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/dataproject/myapp/__pycache__/__init__.cpython-311.pyc b/dataproject/myapp/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..0b67ccee Binary files /dev/null and b/dataproject/myapp/__pycache__/__init__.cpython-311.pyc differ diff --git a/dataproject/myapp/__pycache__/admin.cpython-311.pyc b/dataproject/myapp/__pycache__/admin.cpython-311.pyc new file mode 100644 index 00000000..1f6b6f29 Binary files /dev/null and b/dataproject/myapp/__pycache__/admin.cpython-311.pyc differ diff --git a/dataproject/myapp/__pycache__/apps.cpython-311.pyc b/dataproject/myapp/__pycache__/apps.cpython-311.pyc new file mode 100644 index 00000000..a1c2ea3b Binary files /dev/null and b/dataproject/myapp/__pycache__/apps.cpython-311.pyc differ diff --git a/dataproject/myapp/__pycache__/models.cpython-311.pyc b/dataproject/myapp/__pycache__/models.cpython-311.pyc new file mode 100644 index 00000000..874f793e Binary files /dev/null and b/dataproject/myapp/__pycache__/models.cpython-311.pyc differ diff --git a/dataproject/myapp/admin.py b/dataproject/myapp/admin.py new file mode 100644 index 00000000..8fcc90b2 --- /dev/null +++ b/dataproject/myapp/admin.py @@ -0,0 +1,9 @@ +from django.contrib import admin +from .models import Student,StudentAdmin,Employee,EmployeeAdmin + + +# Register your models here. +admin.site.register(Student,StudentAdmin) +admin.site.register(Employee,EmployeeAdmin) + + diff --git a/dataproject/myapp/apps.py b/dataproject/myapp/apps.py new file mode 100644 index 00000000..c34fb20e --- /dev/null +++ b/dataproject/myapp/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class MyappConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'myapp' diff --git a/dataproject/myapp/migrations/0001_initial.py b/dataproject/myapp/migrations/0001_initial.py new file mode 100644 index 00000000..23ac62ca --- /dev/null +++ b/dataproject/myapp/migrations/0001_initial.py @@ -0,0 +1,33 @@ +# Generated by Django 3.2.5 on 2023-10-31 03:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Employee', + fields=[ + ('emp_id', models.CharField(help_text='Employee ID', max_length=4, primary_key=True, serialize=False)), + ('ename', models.CharField(max_length=50)), + ('post', models.CharField(max_length=20)), + ('salary', models.IntegerField()), + ], + ), + migrations.CreateModel( + name='Student', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('referencenumber', models.CharField(help_text='reference number', max_length=20)), + ('name', models.CharField(max_length=100)), + ('age', models.IntegerField()), + ('email', models.EmailField(max_length=254)), + ], + ), + ] diff --git a/dataproject/myapp/migrations/__init__.py b/dataproject/myapp/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/dataproject/myapp/migrations/__pycache__/0001_initial.cpython-311.pyc b/dataproject/myapp/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 00000000..d006579f Binary files /dev/null and b/dataproject/myapp/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/dataproject/myapp/migrations/__pycache__/__init__.cpython-311.pyc b/dataproject/myapp/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..9966349d Binary files /dev/null and b/dataproject/myapp/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/dataproject/myapp/models.py b/dataproject/myapp/models.py new file mode 100644 index 00000000..a47291f5 --- /dev/null +++ b/dataproject/myapp/models.py @@ -0,0 +1,21 @@ +from django.db import models +from django.contrib import admin + +# Create your models here. +class Student (models.Model): + referencenumber=models.CharField(max_length=20,help_text="reference number") + name=models.CharField(max_length=100) + age=models.IntegerField() + email=models.EmailField() +class StudentAdmin(admin.ModelAdmin): + list_display=('referencenumber','name','age','email') + +class Employee (models.Model): + emp_id=models.CharField(primary_key=True,max_length=4,help_text='Employee ID') + ename=models.CharField(max_length=50) + post=models.CharField(max_length=20) + salary=models.IntegerField() + + +class EmployeeAdmin(admin.ModelAdmin): + list_display=('emp_id','ename','post','salary') diff --git a/dataproject/myapp/tests.py b/dataproject/myapp/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/dataproject/myapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/dataproject/myapp/views.py b/dataproject/myapp/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/dataproject/myapp/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/server output.png b/server output.png new file mode 100644 index 00000000..6ba16a2e Binary files /dev/null and b/server output.png differ