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
78 changes: 75 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions dataproject/dataproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +38,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp'
]

MIDDLEWARE = [
Expand Down Expand Up @@ -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')
]
Binary file added dataproject/db.sqlite3
Binary file not shown.
Empty file added dataproject/myapp/__init__.py
Empty file.
Binary file not shown.
Binary file added dataproject/myapp/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file added dataproject/myapp/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions dataproject/myapp/admin.py
Original file line number Diff line number Diff line change
@@ -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)


6 changes: 6 additions & 0 deletions dataproject/myapp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class MyappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'myapp'
33 changes: 33 additions & 0 deletions dataproject/myapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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)),
],
),
]
Empty file.
Binary file not shown.
Binary file not shown.
21 changes: 21 additions & 0 deletions dataproject/myapp/models.py
Original file line number Diff line number Diff line change
@@ -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')
3 changes: 3 additions & 0 deletions dataproject/myapp/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions dataproject/myapp/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.
Binary file added server output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.