Questions tagged [django-rest-framework-gis]

1

votes
1

answer
338

Views

Conditions on django filter backend in django rest framework?

I am using Django filter backend on few fields which is working very good. But i want to filter fields when i get specific condition Like if user_type is basic get filter query otherwise get all objects from model. Mine code for filters is here: http_method_names = ['get'] serializer_class = SearchS...
Salman Ahmed
1

votes
2

answer
1.2k

Views

DRF Object of type 'User' is not JSON serializable

I'm trying to return the details of the current logged in user in the following way: from .serializers import UserSerializer class UserDetailsView(RetrieveAPIView):...
Ishan Khare
1

votes
3

answer
882

Views

Django-filters: multiple IDs in a single query string

Using django-filters, I see various solutions for how to submit multiple arguments of the same type in a single query string, for example for multiple IDs. They all suggest using a separate field that contains a comma-separated list of values, e.g.: http://example.com/api/cities?ids=1,2,3 Is there a...
mart1n
1

votes
1

answer
189

Views

filterset lookups for annotated fields

i have a problem to create a filterset for one of my ModelViewSets to provide filter functionality (incl. all allowed lookups e.g. in, gt, lt, ...) for annotated fields in my api. My Code looks as following: import rest_framework_filters as filters from django_filters.rest_framework import DjangoFil...
Smie85
1

votes
2

answer
307

Views

Django Rest Framework DELETE returns no content in the body

I am using Django Rest Framework and I am making a DELETE request. As opposed to POST, PUT, PATCH, which all return the state of the object post creation/modification, delete does not return anything in the body (just the 204 code). Having this information would be helpful when trying to tie respon...
Andrei Cioara
1

votes
1

answer
215

Views

Django rest-auth Token authentication

I'm trying to use axios to get information from the /rest-auth/user/ page. This is my function: export const fetchUser = () => { const token = localStorage.getItem('token'); return dispatch => { dispatch(fetchUserPending()); axios.get('http://localhost:8000/api/v1/rest-auth/user/', {headers: { 'auth...
peter176
1

votes
2

answer
248

Views

Location for Django Rest framework exception handler

The DRF Docs say that once an exception handler is set up, it needs to be defined in the settings.py as follows: REST_FRAMEWORK = { 'EXCEPTION_HANDLER': 'my_project.my_app.utils.custom_exception_handler' } My Django project layout is like this: backend settings.py connectivity_service utils Custom40...
Amistad
1

votes
3

answer
720

Views

Filtering on action decorator - Django Rest Framework

I am trying to filter data using a decorator action on Django Rest Framework, it works perfect if I use the global queryset (get_queryset() function) but I need to use it in a separate function. I am using django-filter to perform it. This is the code. My view: class ShippingAPI(viewsets.ModelViewSe...
Jeremias Enriquez
1

votes
1

answer
52

Views

Django all auth: How to override the confirmation email url

What I want to do is to override confirmation email url in templates/account/email/email_confirmation_message.txt. I want to change this part To confirm this is correct, go to {{ activate_url }} to something like http://localhost:8080/confirm_email/{{ key }} However, I couldn't figure out where {{...
Ooto
1

votes
1

answer
25

Views

Django Rest Framework: pass user from view to serializer

I have such view for user change password: class ChangePasswordView(generics.UpdateAPIView): serializer_class = ChangePasswordSerializer permission_classes = [IsAuthenticated] def put(self, request, *args, **kwargs): data = request.data.copy() data['user'] = self.request.user serializer = self.get_s...
PotatoBox
0

votes
3

answer
456

Views

Registered URLs in a router not working

I am attempting to have several views in a router that is used in a url, and the urls don't seem to work at all. I followed the instructions on http://www.django-rest-framework.org/api-guide/routers/, but my code doesn't appear to work. My intention is to be able to access the views through these ur...
Jack Cole
0

votes
0

answer
5

Views

cannot import name 'URLPatternsTestCase' from 'rest_framework.test' , can anybody please tell me how to fix this error

cannot import name 'URLPatternsTestCase' from 'rest_framework.test' from django.conf.urls import include, url from rest_framework.test import APITestCase, URLPatternsTestCase from readEstateApi import views from django.core.urlresolvers import reverse class AccountTests(APITestCase, URLPatternsTestC...
Raja Paul
0

votes
0

answer
21

Views

Reduce number of queries made to render list of items with same in-line editable field

While rendering a table of items, if the value for field X is not defined, it is rendered as a select element. Django makes a query for each select element and these can add up and cause delays in large tables. What is the best way to reduce the number of queries? views.py from rest_framework impor...
silverstripes
1

votes
1

answer
709

Views

check_object_permissions with CreateAPIView

CommentCreate is a CreateAPIView used to post comments on another 'report' model. I need to block anyone who is not the author of the report, or who is not in an assigned group of people who are allowed to post a comment, from using this endpoint to create comments. class CommentCreate(generics.Crea...
denvaar
0

votes
1

answer
17

Views

Encountered unknown tag 'load'.?

I want to add some custom-template-tags.But, {% load userfilters %} => 'load' tag is not working. settings.py # project/settings.py TEMPLATES = [ { 'BACKEND': 'django.template.backends.jinja2.Jinja2', 'DIRS': [ os.path.join(BASE_DIR, 'html/jinja2'), ], 'APP_DIRS': True, 'OPTIONS': { 'environment': '...
user10827542
1

votes
1

answer
678

Views

How to search from many fields?

I have custom filter to my viewset: class OrderFilter(django_filters.rest_framework.FilterSet): username = django_filters.CharFilter(name='user__username', lookup_expr='icontains') client_name = django_filters.CharFilter(name='user__first_name', lookup_expr='icontains') class Meta: model = Order exc...
Nips
1

votes
1

answer
689

Views

How to replace or edit the lookup parameter in a django rest framework Router?

I have set up a Django Rest Framework ModelViewSet for a Product model. The Product has a uuid4 primary key field. The API list views are working, but I can't access the detail views using the default router, I guess because the uuid4 primary key doesn't fit the pk integer regex the router expects?...
Escher
1

votes
2

answer
332

Views

Django Rest Serializers: Return data of related field

I created models which are Contracts and ContractItems. ContractItems table contains a foreign key attribute of Contracts table. I need to return Contracts with their relevant ContractItems. I implemented a serializer like it. class ContractSerializer(ModelSerializer): class Meta: model = Contract...
1

votes
3

answer
1.2k

Views

Django SECRET KEY error

I'm building a little Django REST API. I've configured a separate settings module for local and production but I'm having an annoying error which is: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty. This error doesn't make sense because I have the SECRET_KEY var...
Albert Diaz
1

votes
2

answer
105

Views

Django datetime format different from DRF serializer datetime format

I am trying to understand why this is happening. I have a Django DateTime field and Django Rest Framework serializer that uses the field. I am trying to compare the dates for both of them and get the following results from JSON endpoint and model result: DRF: 2018-12-21T19:17:59.353368Z Model field:...
Gasim
1

votes
4

answer
57

Views

Django Rest Framework: How to associate the object with the user when posting the object

I'm new to creating REST API so I might misunderstand something. I'm creating REST API using Django Rest Framework. And I'm trying to create an object and send it from my mobile app. However, API returns 400. I think it still cannot associate the object with the request user and I'm wondering how to...
Ooto
1

votes
0

answer
46

Views

Sort and set REST API data into a new list

I'm trying to create a report table based from an API, but the API currently is not sorted as I wanted it to be and I'm not sure how to rearrange it. Here's an example of how the API that look like this : [ { 'task': { 'id': 2, 'name': 'Texturing', }, 'assign_to': { 'id': 1, 'official_name': 'Roy Ha...
M.Izzat
1

votes
1

answer
41

Views

Nested Relationship Serializer Rest Framework Not Displaying Properly

I'm trying to display the attributes in the Disease Model and Evidence Model, but the attributes that is displayed on the end link are only those attributes that are present in the Rule Model. Models.py :- class Rule(models.Model): disease = models.ForeignKey(Disease, default=0,related_name='DRules'...
mutedeuphonies
1

votes
1

answer
12

Views

Django should I manage users in a separate startapp?

In Django 2.2, if I plan to make authentication its own service in the future and serve requests through DRF, should I put my User model in a separate app from my regular 'functional apps'? There's no way each app should contain its own implementation of auth, right? Project_Root |--app_auth |--app_...
HashRocketSyntax
0

votes
2

answer
11

Views

how to receive username with token by django rest authetication?

I am using django Django=2.1.7 and rest framework djangorestframework=3.9.2 This is my url for login path('rest-auth/login', include('rest_auth.urls')), When I enter username and password I got the token from rest API. But I want my user detail like name, id etc to show in my react components. Pleas...
imsaiful
1

votes
0

answer
401

Views

Unable to send Activation Email with Djoser in Django Rest Framework

am trying to send activation email when a user get registered . when post request is called the content of email is shown in console but it is not send to user email. Django setting : EMAIL_USE_TLS=True EMAIL_HOST='smtp.gmail.com' EMAIL_HOST_USER= EMAIL_HOST_PASSWORD= EMAIL_PORT=587 EMAIL_BACKEND =...
Bishnu Sharma
1

votes
0

answer
24

Views

Minor Issue: Where is the better place to put User.objects.create_user in DRF?

Recently, I have reviewed my previous codes in Django thoroughly line by line. And I've got a minor issue. I have a preference to put ORM method to VIEW, not serializer. For example, I would like to make User.objects.create_user into APIView class like below. class SignUp(APIView): def post(self, re...
namwoo
1

votes
0

answer
203

Views

Converting a table from html file to pdf using xhtml2pdf

Hi guys I am having a problem using xhtml2pdf. I am following a tutorial and it worked (note: the data in the tutorial is hardcoded). So I change a bit of the code from the tutorial so I can fetch data from a database using django-rest-framework. When I run the project there were no errors but I typ...
Eak321
1

votes
1

answer
325

Views

Authenticating into Wordpress from an Android WebView

I'm currently working on a hobby project that has 3 main components: an Android app, a Django-rest-framework based backend, a Wordpress frontend The Android app authenticates against the REST API, and also supports logging in with Facebook. There are some sections of the WP frontend I'd like to in...
alxrcs
1

votes
1

answer
64

Views

how to get url link on the response of get() method

I am trying to upload and get a response to an image using DRF api. the images are uploaded on the specified location but what i want is to get the link of the image so that i can click on it and could see the image when i get the response. if anyone could help me rectify this problem I would reall...
abhinavsharma1494
1

votes
1

answer
377

Views

Django Rest Framework - automatically annotate queryset

I use one Serializer in many different places in my project. I need to use one annotation but the problem is that I don't want to annotate it in all views so I would like to do universal annotation in the Serializer itself. It is possible? Now I need to do this before every serialization: City.objec...
Milano
1

votes
2

answer
321

Views

How to map to request.post json key to model serialializer field in django?

I am newbie in djnago-rest-framework. I am leaning about creating instance with serializer in DRF. Let suppose I have models who look like this (models.py) : from django.db import models class Reporter(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_lengt...
Amit
1

votes
2

answer
369

Views

DRF testing Model Serializer - Django Restframework

I am testing my Serializer model in django restframework with APITestCase. this is my structure : class Usertest(APITestCase): def test_userprofile_create(self): user = User.objects.create(username='asghar', password='4411652A', email='[email protected]',) profile = UserProfile.objects.create(fullname=...
taghiss
1

votes
0

answer
398

Views

VueJS Authentication with Django REST Key

I can retrieve a key after logging in through my Django REST API, but then I am wondering how I should store that key. I'm not really using Django, but I imagine I have to store the cookie myself then or something. I'm using Axios for VueJS to interact with the API. I am using django rest auth to ge...
Florin
1

votes
2

answer
697

Views

django rest api with jwt authentication is asking for csrf token

I am new to django rest api framework. I am using JWT token based authentication for the rest api with the following setting - REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', 'rest_framework.authentication.TokenAuthentication',...
Bharath R S
1

votes
1

answer
49

Views

Django Restframework _ update user model with special custom token?

in DRF i have a some custom action that will do something to user model.user instances are all in state of is_active = False.Im trying to make something that turns the user to is_active = True. i made some a token model that has OneToOne to my user model.the function im trying to make is : if token...
taghiss
1

votes
2

answer
24

Views

How to add my logic when I access the `ListAPIView`?

I use the BannerListAPIView when access the banner list: class BannerListAPIView(ListAPIView): serializer_class = WebsiteBannerSerializer permission_classes = [] queryset = WebsiteBanner.objects.all() But I want to add my logic when access this ListAPIView, such as I want to record the remote_ip. H...
qg_java_17137
1

votes
0

answer
17

Views

How to implicitly pass user from a request to corresponding serializer?

I have a following code: class Article(models.Model): ... owner = models.ForeignKey(User, on_delete=models.CASCADE) class ArticleSerializer(serializers.ModelSerializer): class Meta: model = Article fields = ('id', 'title', 'content', 'owner') extra_kwargs = { 'owner': {'write_only': True}, } class A...
user3324314
1

votes
1

answer
411

Views

Best security practices for React + Django

I'm currently working on a project that uses Django API server and a NodeJS server running React. In development we're running Django on port 8000 and NodeJS on port 8080, and currently React is responsible for rendering the page and interacting with Django API, which provides data for React. In ord...
Fong Tinyik
1

votes
1

answer
48

Views

POST or PUT when sending data with Fetch API to check on server

I'm writing a quiz app, where the frontend GETs a question from the server database using Fetch API, then sends both question and answer again via Fetch API to django on the server, which then is supposed to check against the data base if the answer is correct or not. As of now the checking doesn't...
Val Melev

View additional questions