django-rest-framework

Django Rest Framework- retrieving a related field on reverse foreign key efficiently

老子叫甜甜 提交于 2020-07-05 10:25:18
问题 I have the following models that represent a working group of users. Each working group has a leader and members: class WorkingGroup(models.Model): group_name = models.CharField(max_length=255) leader = models.ForeignKey(User, null=True, on_delete=models.SET_NULL) class WorkingGroupMember(models.Model): group = models.ForeignKey(WorkingGroup, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE) In DRF, I want to efficiently retrieve all groups (there are several

django rest framework social-auth with jwt

最后都变了- 提交于 2020-07-05 04:52:29
问题 hi im working on SPA django rest framework with jwt and angular 5 . i built login and sign up section. now im looking for a way to add social login or register to my app and have jwt support after deep search i found some module that have very unclear document(atleast to me).. this module https://github.com/st4lk/django-rest-social-auth looks ok he said use: /api/login/social/jwt_user/ and: /api/login/social/jwt/ are end point for jwt but this get me nothing when i'm using them.. we had some

django rest framework social-auth with jwt

吃可爱长大的小学妹 提交于 2020-07-05 04:52:16
问题 hi im working on SPA django rest framework with jwt and angular 5 . i built login and sign up section. now im looking for a way to add social login or register to my app and have jwt support after deep search i found some module that have very unclear document(atleast to me).. this module https://github.com/st4lk/django-rest-social-auth looks ok he said use: /api/login/social/jwt_user/ and: /api/login/social/jwt/ are end point for jwt but this get me nothing when i'm using them.. we had some

'AnonymousUser' object has no attribute 'is_admin'

ε祈祈猫儿з 提交于 2020-07-03 13:00:22
问题 I am using Django 2.2 and Python 3.6. I deployed a Django REST server using AWS EB, but I get the following error. It works fine on the local side, but an error occurs in the EB instance. As a result of my analysis, request.user is recognized normally on the local, but on the EB it is marked as an anonymous user. I am using the same code, but why does this happen? REST_FRAMEWORK = { "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination", "PAGE_SIZE": 10, "DEFAULT

`TypeError` when calling create(). You may need to make the field read-only, or override the create() method

半腔热情 提交于 2020-07-03 02:35:51
问题 Not sure what's going on here. I'm trying to perform create a new instance via Django-rest-framework. What am I doing wrong? There are a few read-only fields being submitted back. I've tried marking them as read-only via read_only_fields in the serializer, as well as specifying them as editable=False within the model's fields. Note: I would prefer to avoid specifying my own create method if possible. This should work via standard functionality as documented here when POSTing the following: {

Not Null constrained error on field handled in views.py

别等时光非礼了梦想. 提交于 2020-07-02 03:10:38
问题 I am working with django rest framework. I have Product and Review models. Review is related to Product like so; class Product(models.Model): name = models.CharField(max_length=200, null=False, blank=False) description = models.TextField(max_length=2000, null=False, blank=False) owner = models.ForeignKey(User, on_delete=models.CASCADE) slug = models.SlugField(unique=True) category = models.ForeignKey(Category, on_delete=models.CASCADE) is_featured = models.BooleanField(default=False) created=

Django get_queryset return custom variables

元气小坏坏 提交于 2020-06-29 06:41:06
问题 Using users as an example I am trying to show how many users there are. get_context_data works totally fine but get_queryset does not. I know that it's not set up properly but I've been playing around with it for quite some days and something is just not clicking.. The main goal is to use the Dajngo-Filter form and then be able to get the updated number of user count. I've only found endless documentation on how to show the "list" of users. Which I have done but no documentation on how to

Django elasticsearch DSL DRF suggetions issue

余生长醉 提交于 2020-06-29 04:58:09
问题 I am implementing Django elasticsearch DSL DRF in my project to create rest API for elasticsearch. Elastic search is working fine but having the issue in search suggestions. As per documentation if I use the suggest in URL then it gives error screen. But I don't add that then I got an incorrect response. I am attaching screenshots of my code. enter image description here enter image description here document code enter image description here view code enter image description here Code for

Serialize multiple InMemoryUploadedFile using ListField : Django REST Framework

故事扮演 提交于 2020-06-29 03:56:21
问题 How can I serialize multiple InMemoryUploadedFile using serializers.ListField() ?? code snippet #views.py @api_view(['POST', 'GET']) def create_post(request): if request.method == 'POST': altered_request_data = request.data.copy() in_memory_upload_files_list = [value for value in request.FILES.values()] altered_request_data['files'] = in_memory_upload_files_list serializer = PostSerializer(data=altered_request_data) serializer.is_valid(raise_exception=True) serializer.save() return Response

Serialize multiple InMemoryUploadedFile using ListField : Django REST Framework

不打扰是莪最后的温柔 提交于 2020-06-29 03:55:08
问题 How can I serialize multiple InMemoryUploadedFile using serializers.ListField() ?? code snippet #views.py @api_view(['POST', 'GET']) def create_post(request): if request.method == 'POST': altered_request_data = request.data.copy() in_memory_upload_files_list = [value for value in request.FILES.values()] altered_request_data['files'] = in_memory_upload_files_list serializer = PostSerializer(data=altered_request_data) serializer.is_valid(raise_exception=True) serializer.save() return Response