mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-02-03 13:14:28 +03:00
Fix code formatting
This commit is contained in:
parent
2833600aec
commit
fa9a8cfe7b
|
@ -7,8 +7,8 @@ if settings.DEBUG:
|
|||
else:
|
||||
router = SimpleRouter()
|
||||
|
||||
router.register('users', UserViewSet)
|
||||
router.register("users", UserViewSet)
|
||||
|
||||
|
||||
app_name = 'api'
|
||||
app_name = "api"
|
||||
urlpatterns = router.urls
|
||||
|
|
|
@ -308,13 +308,11 @@ STATICFILES_FINDERS += ["compressor.finders.CompressorFinder"]
|
|||
# -------------------------------------------------------------------------------
|
||||
# django-rest-framework - https://www.django-rest-framework.org/api-guide/settings/
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
'rest_framework.authentication.SessionAuthentication',
|
||||
'rest_framework.authentication.TokenAuthentication',
|
||||
"DEFAULT_AUTHENTICATION_CLASSES": (
|
||||
"rest_framework.authentication.SessionAuthentication",
|
||||
"rest_framework.authentication.TokenAuthentication",
|
||||
),
|
||||
'DEFAULT_PERMISSION_CLASSES': (
|
||||
'rest_framework.permissions.IsAuthenticated',
|
||||
)
|
||||
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
|
||||
}
|
||||
{%- endif %}
|
||||
# Your stuff...
|
||||
|
|
|
@ -24,9 +24,10 @@ urlpatterns = [
|
|||
# API URLS
|
||||
urlpatterns += [
|
||||
# API base url
|
||||
path("api/", include('config.api_router')),
|
||||
path("api/", include("config.api_router")),
|
||||
# DRF auth token
|
||||
path("auth-token/", obtain_auth_token)]
|
||||
path("auth-token/", obtain_auth_token),
|
||||
]
|
||||
{%- endif %}
|
||||
|
||||
if settings.DEBUG:
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
from rest_framework import serializers
|
||||
from {{ cookiecutter.project_slug }}.users.models import User
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['username', 'email', 'name', 'url']
|
||||
fields = ["username", "email", "name", "url"]
|
||||
|
||||
extra_kwargs = {
|
||||
'url': {'view_name': 'api:user-detail', 'lookup_field': 'username'}
|
||||
"url": {"view_name": "api:user-detail", "lookup_field": "username"}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,20 +5,20 @@ from rest_framework.mixins import RetrieveModelMixin, ListModelMixin, UpdateMode
|
|||
from rest_framework.response import Response
|
||||
from rest_framework.viewsets import GenericViewSet
|
||||
|
||||
|
||||
from .serializers import UserSerializer
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class UserViewSet(RetrieveModelMixin, ListModelMixin, UpdateModelMixin, GenericViewSet):
|
||||
serializer_class = UserSerializer
|
||||
queryset = User.objects.all()
|
||||
lookup_field = 'username'
|
||||
lookup_field = "username"
|
||||
|
||||
def get_queryset(self, *args, **kwargs):
|
||||
return self.queryset.filter(id=self.request.user.id)
|
||||
|
||||
@action(detail=False, methods=['GET'])
|
||||
@action(detail=False, methods=["GET"])
|
||||
def me(self, request):
|
||||
serializer = UserSerializer(request.user, context={'request': request})
|
||||
serializer = UserSerializer(request.user, context={"request": request})
|
||||
return Response(status=status.HTTP_200_OK, data=serializer.data)
|
||||
|
|
Loading…
Reference in New Issue
Block a user