Skip to content

Commit 55813a5

Browse files
committed
REST API created
1 parent 4bc6468 commit 55813a5

24 files changed

+450
-1
lines changed

Pipfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
django = "==3.0.6"
10+
djangorestframework = "*"
11+
12+
[requires]
13+
python_version = "3.7"

Pipfile.lock

+58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
# RESTAPI
1+
# RESTAPI
2+
3+
DjangoRestFramework has beautiful view to create RestFull API.
4+
5+
This Is a sample REST API For School Student Information.
6+
7+
![Sample Picture for REST API](Sample_Picture/samplepicture1.png)
8+
9+
![Sample Picture for REST API](Sample_Picture/samplepicture2.png)

Sample_Picture/samplepicture1.png

18.5 KB
Loading

Sample_Picture/samplepicture2.png

58.4 KB
Loading

api/__init__.py

Whitespace-only changes.

api/admin.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from django.contrib import admin
2+
from .models import Student,School
3+
4+
class StudentAdmin(admin.ModelAdmin):
5+
fieldsets = (
6+
('Student Field', {
7+
'fields': ('student_name', 'student_class', 'Student_roll_no')
8+
}),
9+
('Other Field', {
10+
'fields': ('student_registration_no','student_subject','student_school_name'),
11+
}),
12+
)
13+
14+
class SchoolAdmin(admin.ModelAdmin):
15+
fieldsets = (
16+
('List Of Schools', {
17+
'fields': ['schools_list']
18+
}),
19+
)
20+
21+
admin.site.register(School, SchoolAdmin)
22+
admin.site.register(Student, StudentAdmin)
23+

api/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class ApiConfig(AppConfig):
5+
name = 'api'

api/migrations/0001_initial.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by Django 3.0.6 on 2020-05-21 06:59
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = [
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Student',
16+
fields=[
17+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('student_name', models.CharField(max_length=150)),
19+
('student_class', models.CharField(max_length=20)),
20+
('Student_roll_no', models.IntegerField()),
21+
('student_subject', models.TextField()),
22+
],
23+
),
24+
]
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Django 3.0.6 on 2020-05-21 12:07
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('api', '0001_initial'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='School',
16+
fields=[
17+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('schools', models.CharField(max_length=150)),
19+
],
20+
),
21+
migrations.AddField(
22+
model_name='student',
23+
name='school_name',
24+
field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='api.School'),
25+
),
26+
]
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.0.6 on 2020-05-21 12:13
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api', '0002_auto_20200521_1207'),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name='school',
15+
old_name='schools',
16+
new_name='schools_list',
17+
),
18+
]
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.0.6 on 2020-05-21 12:15
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api', '0003_auto_20200521_1213'),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name='student',
15+
old_name='school_name',
16+
new_name='student_school_name',
17+
),
18+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.0.6 on 2020-05-21 12:26
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api', '0004_auto_20200521_1215'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='student',
15+
name='student_registration_no',
16+
field=models.IntegerField(default=0),
17+
),
18+
]

api/migrations/__init__.py

Whitespace-only changes.

api/models.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from django.db import models
2+
3+
class School(models.Model):
4+
schools_list = models.CharField(max_length=150)
5+
6+
def __str__(self):
7+
return self.schools_list
8+
9+
10+
class Student(models.Model):
11+
student_registration_no = models.IntegerField(default=0)
12+
student_name = models.CharField(max_length=150)
13+
student_class = models.CharField(max_length=20)
14+
Student_roll_no = models.IntegerField()
15+
student_subject = models.TextField()
16+
student_school_name = models.ForeignKey(School, on_delete=models.CASCADE, default="")
17+
18+
19+
def __str__(self):
20+
return self.student_name

api/serializers.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from rest_framework import serializers
2+
from .models import Student, School
3+
4+
class StudentSerializer(serializers.HyperlinkedModelSerializer):
5+
class Meta:
6+
model = Student
7+
fields = ('student_name', 'student_registration_no', 'student_class', 'Student_roll_no', 'student_subject','student_school_name')
8+
9+
class SchoolSerializer(serializers.HyperlinkedModelSerializer):
10+
class Meta:
11+
model = School
12+
fields = ['schools_list']

api/urls.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.urls import path, include
2+
from rest_framework import routers
3+
from api.views import StudentViewSet, SchoolViewSet
4+
5+
router = routers.DefaultRouter()
6+
router.register(r'students', StudentViewSet)
7+
router.register(r'schools', SchoolViewSet)
8+
9+
urlpatterns = [
10+
path('', include(router.urls)),
11+
path('api/v1', include('rest_framework.urls', namespace='rest_framework')),
12+
]

api/views.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from rest_framework import viewsets
2+
3+
from .serializers import StudentSerializer, SchoolSerializer
4+
from .models import Student, School
5+
6+
class StudentViewSet(viewsets.ModelViewSet):
7+
queryset= Student.objects.all().order_by('Student_roll_no')
8+
serializer_class = StudentSerializer
9+
10+
class SchoolViewSet(viewsets.ModelViewSet):
11+
queryset = School.objects.all()
12+
serializer_class = SchoolSerializer

config/__init__.py

Whitespace-only changes.

config/asgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for config project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
15+
16+
application = get_asgi_application()

0 commit comments

Comments
 (0)