This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTTP 200 OK | |
Allow: GET, POST, HEAD, OPTIONS | |
Content-Type: application/json | |
Vary: Accept | |
[ | |
{ | |
"emp_no": 10001, | |
"salary": 60117, | |
"from_date": "1986-06-26", | |
"to_date": "1987-06-26" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTTP 200 OK | |
Allow: GET, HEAD, OPTIONS | |
Content-Type: application/json | |
Vary: Accept | |
{ | |
"employees": "http://127.0.0.1:8080/api/employees/", | |
"departments": "http://127.0.0.1:8080/api/departments/", | |
"deptemp": "http://127.0.0.1:8080/api/deptemp/", | |
"deptmanager": "http://127.0.0.1:8080/api/deptmanager/", | |
"salaries": "http://127.0.0.1:8080/api/salaries/", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$python manage.py runserver 0.0.0.0:8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from . import models | |
# Register your models here. | |
admin.site.register(models.Employees) | |
admin.site.register(models.Departments) | |
admin.site.register(models.DeptEmp) | |
admin.site.register(models.DeptManager) | |
admin.site.register(models.Salaries) | |
admin.site.register(models.Titles) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from django.urls import path, include | |
from rest_framework import routers | |
from employee_app import views | |
#Use the router to dynamically create our urls | |
router = routers.DefaultRouter() | |
router.register('employees', views.EmployeeAPI) | |
router.register('departments', views.DepartmentsAPI) | |
router.register('deptemp', views.DeptEmpAPI) | |
router.register('deptmanager', views.DeptManagerAPI) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from rest_framework import viewsets | |
from .serializers import * | |
from .models import * | |
class EmployeeAPI(viewsets.ModelViewSet): | |
serializer_class = EmployeeSerializer | |
queryset = Employees.objects.all()[:5] | |
class DepartmentsAPI(viewsets.ModelViewSet): | |
serializer_class = DepartmentsSerializer | |
queryset = Departments.objects.all()[:5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import serializers | |
from .models import * | |
class EmployeeSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Employees | |
fields = "__all__" | |
class DepartmentsSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Departments | |
fields = "__all__" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSTALLED_APPS = [ | |
'django.contrib.admin', | |
'django.contrib.auth', | |
'django.contrib.contenttypes', | |
'django.contrib.sessions', | |
'django.contrib.messages', | |
'django.contrib.staticfiles', | |
'employees_app', | |
'rest_framework', | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$python manage.py makemigrations | |
$python manage.py migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Employees(models.Model): | |
emp_no = models.IntegerField(primary_key=True) | |
birth_date = models.DateField() | |
first_name = models.CharField(max_length=20) | |
last_name = models.CharField(max_length=20) | |
gender = models.CharField(max_length=1) | |
hire_date = models.DateField() | |
class Meta: | |
managed = False |
NewerOlder