Initial upload of all files

This commit is contained in:
Joe James
2018-08-22 15:44:13 -07:00
committed by GitHub
parent a8e3a58019
commit 98f87024b3
26 changed files with 267 additions and 0 deletions

BIN
samsung/db.sqlite3 Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Employee
# Register your models here.
admin.site.register(Employee)

View File

@@ -0,0 +1,5 @@
from django.apps import AppConfig
class EmployeesConfig(AppConfig):
name = 'employees'

View File

@@ -0,0 +1,23 @@
# Generated by Django 2.1 on 2018-08-21 23:31
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Employee',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=40)),
('position', models.CharField(max_length=20)),
('department', models.CharField(max_length=20)),
],
),
]

View File

@@ -0,0 +1,9 @@
from django.db import models
class Employee(models.Model):
name = models.CharField(max_length=40)
position = models.CharField(max_length=20)
department = models.CharField(max_length=20)
def __str__ (self):
return (str(self.id) + ': ' + self.name)

View File

@@ -0,0 +1,7 @@
from rest_framework import serializers
from .models import Employee
class EmployeeSerializer (serializers.ModelSerializer):
class Meta:
model = Employee
fields = ('id', 'name', 'position', 'department')

View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -0,0 +1,8 @@
# employees URLs
from employees import views
from django.conf.urls import url
urlpatterns = [
# url(r'^employees/$', views.employee_list),
# url(r'^employees/(?P<id>[0-9]+)/$', views.employee_detail),
]

View File

@@ -0,0 +1,44 @@
from django.shortcuts import get_object_or_404
from rest_framework.response import Response
from rest_framework.decorators import api_view
from .models import Employee
from .serializers import EmployeeSerializer
from rest_framework import status
@api_view(['GET', 'POST'])
def employee_list(request):
if request.method == 'GET':
all_employees = Employee.objects.all()
serializer = EmployeeSerializer(all_employees, many=True)
return Response(serializer.data)
elif request.method == 'POST':
serializer = EmployeeSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
@api_view(['GET', 'PUT', 'DELETE'])
def employee_detail(request, id):
employee = get_object_or_404(Employee, id = id)
if request.method == 'GET':
serializer = EmployeeSerializer(employee)
return Response(serializer.data)
elif request.method == 'PUT':
serializer = EmployeeSerializer(employee, data = request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status = status.HTTP_400_BAD_REQUEST)
elif request.method == 'DELETE':
employee.delete()
return Response(status=status.HTTP_204_NO_CONTENT)

15
samsung/manage.py Normal file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/env python
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'samsung.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

122
samsung/samsung/settings.py Normal file
View File

@@ -0,0 +1,122 @@
"""
Django settings for samsung project.
Generated by 'django-admin startproject' using Django 2.1.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'kvwb!ny)m(x#m=)m+!--h$p2=d@-!w3hi1=w2r%rjit#*w7l$&'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'employees.apps.EmployeesConfig',
'rest_framework',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'samsung.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'samsung.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'

10
samsung/samsung/urls.py Normal file
View File

@@ -0,0 +1,10 @@
# samsung URL Configuration
from django.contrib import admin
from django.urls import path, re_path, include
from employees import views
urlpatterns = [
path('admin/', admin.site.urls),
path('employees/', views.employee_list, name='employee_list'),
re_path(r'^employees/(?P<id>[0-9]+)/$', views.employee_detail, name='employee_detail'),
]

16
samsung/samsung/wsgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
WSGI config for samsung project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'samsung.settings')
application = get_wsgi_application()