django-rest-framework

Django ForeignKey field required despite blank=True and null=True

匆匆过客 提交于 2021-01-04 05:31:00
问题 I am using Django REST Framework and I have a MyNodel with a related MyOtherModel in a many-to-one relationship: models.ForeignKey(MyModel, related_name="my_other_models", blank=True, null=True) Although blank=True, null=True , when I try to post a MyModel JSON without a my_other_models field I get a "this field is required" error. 回答1: In your serializer, you need to add required=False . field = MyModelSerializer(required=False) 来源: https://stackoverflow.com/questions/40237969/django

Django - missing 1 required positional argument: 'request'

五迷三道 提交于 2021-01-02 06:42:31
问题 I'm getting the error get_indiceComercioVarejista() missing 1 required positional argument: 'request' when trying to access the method get_indiceComercioVarejista. I don't know what it's wrong with it. views: from django.http import JsonResponse from django.shortcuts import render, HttpResponse import requests import pandas as pd from rest_framework.views import APIView from rest_framework.response import Response class ChartData(APIView): authentication_classes = [] permission_classes = []

How can I flatten a foreignkey object with django-rest-framework-(gis)

血红的双手。 提交于 2021-01-02 06:34:41
问题 I have searched long and far for a solution that is up to date and specific to my problem but have yet not found a solution or a clear documentation on what I really need to do in order to flatten a relationship to become geojson compliant. This question is almost identical to mine, however the solutions or answers does not solve the problem and still produces invalid GeoJSON. django-rest-framework-gis related field Related Set serializer geo_field as PointField from another model - Django

Django-rest-auth (dj-rest-auth) custom user registration

拜拜、爱过 提交于 2021-01-02 03:29:19
问题 I'm using dj-rest-auth (https://dj-rest-auth.readthedocs.io/en/latest/) and trying to implement a custom registration form. When I'm trying to register a new user I have the base form. I've seen with the older version (https://django-rest-auth.readthedocs.io/en/latest/) that if you use password1 and password2, you don't have to retype all the code. serializers.py from rest_framework import serializers from dj_rest_auth.registration.serializers import RegisterSerializer class

Django-rest-auth (dj-rest-auth) custom user registration

断了今生、忘了曾经 提交于 2021-01-02 03:28:43
问题 I'm using dj-rest-auth (https://dj-rest-auth.readthedocs.io/en/latest/) and trying to implement a custom registration form. When I'm trying to register a new user I have the base form. I've seen with the older version (https://django-rest-auth.readthedocs.io/en/latest/) that if you use password1 and password2, you don't have to retype all the code. serializers.py from rest_framework import serializers from dj_rest_auth.registration.serializers import RegisterSerializer class

DRF - Paginated response - append list of all ids

一曲冷凌霜 提交于 2021-01-01 20:34:57
问题 I have a "next object" feature on my website but I use pagination. I would like add "ids" field that contains ids of all objects filtered and sorteded into the paginated response. Everything that I tried returns only a list of current page ids. class StandardResultsSetPagination(PageNumberPagination): page_size = 20 page_size_query_param = 'page_size' max_page_size = 20 def get_paginated_response(self, data, list_of_ids): return Response(OrderedDict([ ('count', self.page.paginator.count), (

django ImportError: cannot import name list_route

久未见 提交于 2021-01-01 02:34:38
问题 Im trying to add a new endpoint by marking it with @list_route but when i try to import if : from rest_framework.decorators import list_route It cant find it. Do i need to install something for this to work (I'm new to django)? 回答1: The list_route decorator is present in version 3.1.3. See: https://github.com/tomchristie/django-rest-framework/blob/3.1.3/rest_framework/decorators.py Follow the instructions on https://github.com/tomchristie/django-rest-framework to install Django REST Framework

django ImportError: cannot import name list_route

风格不统一 提交于 2021-01-01 02:32:27
问题 Im trying to add a new endpoint by marking it with @list_route but when i try to import if : from rest_framework.decorators import list_route It cant find it. Do i need to install something for this to work (I'm new to django)? 回答1: The list_route decorator is present in version 3.1.3. See: https://github.com/tomchristie/django-rest-framework/blob/3.1.3/rest_framework/decorators.py Follow the instructions on https://github.com/tomchristie/django-rest-framework to install Django REST Framework

django ImportError: cannot import name list_route

余生颓废 提交于 2021-01-01 02:32:08
问题 Im trying to add a new endpoint by marking it with @list_route but when i try to import if : from rest_framework.decorators import list_route It cant find it. Do i need to install something for this to work (I'm new to django)? 回答1: The list_route decorator is present in version 3.1.3. See: https://github.com/tomchristie/django-rest-framework/blob/3.1.3/rest_framework/decorators.py Follow the instructions on https://github.com/tomchristie/django-rest-framework to install Django REST Framework

DRF Viewset remove permission for detail route

荒凉一梦 提交于 2020-12-30 08:30:03
问题 I have a basic Viewset: class UsersViewSet(viewsets.ModelViewSet): permission_classes = (OnlyStaff,) queryset = User.objects.all() serializer_class = UserSerializer It is bind to the /api/users/ endpoint. I want to create a user profile page, so I need only a particular user, so I can retrieve it from /api/users/<id>/ , but the problem is that I want /api/users/<id>/ to be allowed to anyone, but /api/users/ to keep its permission OnlyStaff , so no one can have access to the full list of users