diff --git a/back_latienda/routers.py b/back_latienda/routers.py new file mode 100644 index 0000000..fe78d68 --- /dev/null +++ b/back_latienda/routers.py @@ -0,0 +1,13 @@ +from rest_framework import routers + +from companies.views import CompanyViewSet +from products.views import ProductViewSet +from history.views import HistorySyncViewSet +from stats.views import StatsLogViewSet + + +router = routers.DefaultRouter() +router.register('companies', CompanyViewSet) +router.register('products', ProductViewSet) +router.register('history', HistorySyncViewSet) +router.register('stats', StatsLogViewSet) diff --git a/back_latienda/settings/base.py b/back_latienda/settings/base.py index f388324..fb637a7 100644 --- a/back_latienda/settings/base.py +++ b/back_latienda/settings/base.py @@ -40,6 +40,11 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', + # 3rd party + 'rest_framework', + 'django_filters', + + # local apps 'core', 'geo', 'companies', @@ -103,6 +108,16 @@ AUTH_PASSWORD_VALIDATORS = [ AUTH_USER_MODEL = 'core.CustomUser' +# DRF Options +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.IsAuthenticatedOrReadOnly', + ], + 'DEFAULT_AUTHENTICATION_CLASSES': [ + 'rest_framework_simplejwt.authentication.JWTAuthentication', + ], + 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'] +} # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ diff --git a/back_latienda/urls.py b/back_latienda/urls.py index 9149eac..3da56bd 100644 --- a/back_latienda/urls.py +++ b/back_latienda/urls.py @@ -14,11 +14,14 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include from django.conf.urls.static import static from django.conf import settings +from .routers import router + urlpatterns = [ path('admin/', admin.site.urls), + path('api/v1/', include(router.urls)), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)