django-rest-framework

Vue js Django Rest Framework With JWT user authentication (getting anonymous user ) simplejwt

大兔子大兔子 提交于 2021-01-29 11:13:49
问题 I got the token.But it is not possible to get data this user. which URL to get data . token work. //simplejwt simplejwt class CustomerRetrieveView(generics.RetrieveAPIView): queryset = Customer.objects.all() permission_classes=(IsAuthenticated,) def get(self,request): ???here correct????? queryset=Customer.objects.get(id=request.user) serializer=CustomerSerializer(queryset) return Response(serializer.data) url ??here correct????? path('customers/????<int:id>???', views.CustomerRetrieveView.as

How to protect the Django media url?

女生的网名这么多〃 提交于 2021-01-29 09:49:36
问题 In my code I know how to protect my endpoint url . I can do simply like this class ApprovalViewSet(mixins.RetrieveModelMixin, mixins.UpdateModelMixin, mixins.ListModelMixin, GenericViewSet): permission_classes = (IsAdminUser,) queryset = User.objects.all() serializer_class = ApprovalSerializer Problem: However, my challenging task is I need to change /media url every time since it is sensitive files. And my files are stored in AWS S3 Questions: 1. How to protect the /media url in Django 2. My

Django one to many get all underlying records

一世执手 提交于 2021-01-29 09:18:51
问题 I'am creating a django application with a database including the following tables: I created the models as following: class Group(models.Model): id = models.AutoField(primary_key=True, editable=False) text = models.CharField(db_column='Text', max_length=4000) class Meta: db_table = 'Group' class Filters(models.Model): id = models.AutoField(primary_key=True, editable=False) text = models.CharField(db_column='Text', max_length=4000) group_id = models.ForeignKey(Group, on_delete=models.CASCADE,

django-rest-framework: Handling business logic and what to return?

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 09:18:22
问题 In my API a one can submit "Parent" with 1 child. This is the common use case. You always enter at least one child when entering parent. This is the same on the UI. There can be the case where the user will want to enter a duplicate parent, eg. it already exists in the system. In that case, in the UI, the user gets to choose if he indeed wants to add a duplicate or if he wants to add the child to one of the existing "duplicate" records. I hope this was clear enough. My question is how I can

Django annotate returning unexpected Sum value

﹥>﹥吖頭↗ 提交于 2021-01-29 08:55:53
问题 These are my models: class Consume(models.Model): amount = models.FloatField(default=1) entry_for = models.ForeignKey( Person, on_delete=models.SET_NULL, related_name='consume_entry_for', ) class Purchase(models.Model): amount = models.DecimalField( max_digits=6, decimal_places=2, default=0.00 ) entry_for = models.ForeignKey( Person, on_delete=models.CASCADE, related_name='ledger_entry_for', ) and this is my query: person_wise_total = Person.objects.annotate( total_purchase=Coalesce(Sum(

AttributeError: 'list' object has no attribute 'order_by'

六月ゝ 毕业季﹏ 提交于 2021-01-29 08:11:14
问题 I was trying to combine two queryset objects by itertools chain python predefine function and filter this with order_by . but i'm getting an AttributeError : 'list' object has no attribute 'order_by' . If anybody could figure out where i'm doing thing wrong then would be much appreciated. thank you so much in advance. views.py : try: qs = Conversation.objects.filter( Q(chat__from_user=user) & Q(chat__to_user=to_user)) qs_2 = Conversation.objects.filter( Q(chat__from_user=to_user) & Q(chat__to

How to add extra field in model serializer?

 ̄綄美尐妖づ 提交于 2021-01-29 07:40:25
问题 I am very new to django rest framework. I have two models ModelA and ModelB. I have a ModelB searilzer to display all the fields in get request. Because of some reasons ModelA and ModelB are not related by FK but ModelA.objects.get(modelB.field1=modelA.pk) this will return single data. class ModelASerailzer(serializers.ModelSerializer): class Meta: model = ModelA fields = ['f1','f2'] class ModelBSerailzer(serializers.ModelSerializer): # I want to do something like this here extra_field =

Cross-Origin Request Blocked - Using Axios and Django REST

家住魔仙堡 提交于 2021-01-29 05:05:24
问题 I am trying to make a GET request in my application that is being served locally (port 8080) using on a node server. I am using Axios to make the request to a django REST server that is also being served locally (port 8000). My request looks like: axios.get('http://127.0.0.1:8000/recipes/',{headers: {"Access-Control-Allow-Origin": "*"}}) On the Django side, I've included these in my middleware MIDDLEWARE = [ 'django.middleware.common.CommonMiddleware', 'corsheaders.middleware.CorsMiddleware',

Django rest framework custom Response middleware

强颜欢笑 提交于 2021-01-29 03:53:25
问题 I use Django Rest Framework with rest_auth (/login, /logout/, /register...) I have a Middleware, normally triggered by user_logged_in or user_logged_out signals. In my Middleware, I want to use Response object from Rest framework. My middleware.py from django.contrib.sessions.models import Session from django.contrib.auth import logout from django.contrib.auth.models import AnonymousUser from rest_framework.response import Response from rest_framework import status class

Djanog with React how to reset user password by sending user an email

风流意气都作罢 提交于 2021-01-29 02:27:58
问题 I am using Django with React, I am implementing a method to reset user password when users forget their password. My basic idea is to: 1) Users give their email address 2) Send an email to their email adress with the link to reset their password(with SendGrid api) 3) Users type in new password to reset their password below is my serializers, views, urls and React code //views.py class PasswordResetConfirmSerializer(serializers.Serializer): new_password1 = serializers.CharField(max_length=128)