Last active
September 19, 2019 17:19
-
-
Save clint74/0a4500bb957885eeccad10b2aa0d699c to your computer and use it in GitHub Desktop.
Revisions
-
clint74 revised this gist
Sep 19, 2019 . 2 changed files with 16 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ from django.urls import include, path from rest_framework import routers #from crud.api import views #router = routers.DefaultRouter() #router.register(r'clientes', views.ClienteViewSet) #router.register(r'funcionarios', views.FuncionarioViewSet) urlpatterns = [ #path('api/v1/', include(router.urls)), path('api-auth/', include('rest_framework.urls', namespace='rest_framework')) ] This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,15 @@ from django.contrib import admin from django.urls import include, path, re_path from rest_framework import routers from crud.api import views router = routers.DefaultRouter() router.register(r'clientes', views.ClienteViewSet) router.register(r'funcionarios', views.FuncionarioViewSet) urlpatterns = [ re_path(r'^admin/', admin.site.urls), path('api/v1/', include(router.urls)), # url(r'^api/', include('crud.api.urls')) ] -
ivanantunes created this gist
Sep 19, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ from django.contrib import admin from .models import Cliente, Funcionario admin.site.register(Cliente) admin.site.register(Funcionario) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ from django.db import models class Cliente (models.Model): name = models.CharField(max_length=32) password = models.CharField(max_length=16,default="") cpf = models.CharField(max_length=11) cardID = models.CharField(max_length=8) class Funcionario (models.Model): user = models.CharField(max_length=32) password = models.CharField(max_length=16) cardID = models.CharField(max_length=8) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ from django.contrib.auth.models import User, Group from rest_framework import serializers from .models import Cliente, Funcionario class ClienteSerializer(serializers.ModelSerializer): class Meta: model = Cliente fields = ['id', 'name', 'cpf', 'password', 'cardID'] extra_kwargs = { 'password' : {'write_only': True, 'required': True}, 'name': {'required': True}, 'cpf': {'required': True}, 'cardID': {'required': True} } def create_cliente(self, validate_data): cliente = Cliente.objects.create_cliente(**validate_data) return cliente class FuncionarioSerializer(serializers.ModelSerializer): model = Funcionario fields = ['id', 'user', 'password','cardID'] extra_kwargs = { 'password' : {'write_only': True, 'required': True}, 'user': {'required': True}, 'cardID': {'required': True} } def create_funcioanrio(self, validate_data): funcionario = Funcionario.objects.create_funcioanrio(**validate_data) return funcionario This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ from django.urls import include, path from rest_framework import routers from crud.api import views router = routers.DefaultRouter() router.register(r'clientes', views.ClienteViewSet) router.register(r'funcionarios', views.FuncionarioViewSet) urlpatterns = [ path('api/v1/', include(router.urls)), path('api-auth/', include('rest_framework.urls', namespace='rest_framework')) ] This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ from django.contrib.auth.models import User, Group from rest_framework import viewsets from .serializers import ClienteSerializer, FuncionarioSerializer from .models import Cliente, Funcionario class ClienteViewSet(viewsets.ModelViewSet): queryset = Cliente.objects.all() serializer_class = ClienteSerializer class FuncionarioViewSet(viewsets.ModelViewSet): queryset = Funcionario.objects.all() serializer_class = FuncionarioSerializer This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,134 @@ """ Django settings for crud project. Generated by 'django-admin startproject' using Django 2.2.5. For more information on this file, see https://docs.djangoproject.com/en/2.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.2/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.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'ez5a-wzm&^zn*q&*p^_k6*)xm22w-4vn4h%5sp_%5x20ce3jv_' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'corsheaders', 'crud.api', ] 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', 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', ] CORS_ORIGIN_WHITELIST = [ "http://localhost:4200" ] REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', 'PAGE_SIZE': 10 } ROOT_URLCONF = 'crud.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 = 'crud.wsgi.application' # Database # https://docs.djangoproject.com/en/2.2/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.2/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.2/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.2/howto/static-files/ STATIC_URL = '/static/' This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^api/', include('crud.api.urls')) ]