django-rest-framework

How to build a json REST API in django (without Django REST framework)

我与影子孤独终老i 提交于 2020-06-25 17:08:32
问题 Preface I have a django project. I've wired it up so it serves a bunch of views for a bunch of models. Now I want to add an endpoint which just dumps a good fraction of the database out as json. The way I would assume you do this is add a URL to a view class / method which returns a HTTPResponseObject full of json. Unfortunately, after quite a bit of googling, all I can find are references to Django REST framework. This is the sort of thing you would think Django would provide internally not

How to build a json REST API in django (without Django REST framework)

你。 提交于 2020-06-25 17:07:41
问题 Preface I have a django project. I've wired it up so it serves a bunch of views for a bunch of models. Now I want to add an endpoint which just dumps a good fraction of the database out as json. The way I would assume you do this is add a URL to a view class / method which returns a HTTPResponseObject full of json. Unfortunately, after quite a bit of googling, all I can find are references to Django REST framework. This is the sort of thing you would think Django would provide internally not

DRF YASG Customizing

主宰稳场 提交于 2020-06-25 04:50:05
问题 I'm trying to customize my api documentation buuild with yasg. First off, I would like to determine the naming of my own sections, and what endpoints should be included in this section. It seems that the naming of sections is based on the first prefix not belonging to the longest common prefix e.g.: if we have the urls api/v1/message and api/v1/test than the sections will be named message and test. Is there a way for me to determine A custom naming for this section? Furthermore, the

last_login field is not updated when authenticating using Tokenauthentication in Django Rest Framework

…衆ロ難τιáo~ 提交于 2020-06-24 06:06:13
问题 I'm working in a project which relies in a Django User model and TokenAuthentication under DjangoRestFramework I was requested to get last login datetime for each user and I've realized that this field is not getting updated when I call the authentication REST endpoint. Is this a known fact? Am I missing something I must do in order to get that field updated each time the token authentication is called? Thanks 回答1: Well, at the end I inherited from the REST Framework TokenAuthentication,

Django Rest Framework Custom Register View (RegisterView) failing to return token + user data

允我心安 提交于 2020-06-17 12:32:43
问题 I'm using allauth and rest_auth in my django rest framework app. When registering an user a token (key) is returned, what I'm trying to achieve is to return the token + user data after registration. To do so I've the following serializer: from rest_framework import serializers from rest_framework.response import Response from allauth.account import app_settings as allauth_settings from allauth.utils import email_address_exists from allauth.account.adapter import get_adapter from allauth

how to change serialized JSON structure django rest framwork

為{幸葍}努か 提交于 2020-06-17 09:31:11
问题 I'm wondering if it possible to change structure of my JSON that im sedinding out. currenyly it looks like this: { "para_subject": { "discipline": "MATAN" }, "para_room": { "room": "210" }, "para_professor": { "user": { "username": "yyyy", "email": "yyyy.yyyy@gmail.com", "first_name": "yyyy", "last_name": "yyy" }, "middle_name": "xxxxxx" }, } what is the best way to change it to this: { "discipline": "MATAN", "room": "210", "para_professor": { "username": "yyyy", "email": "yyyy.yyyy@gmail.com

how to change serialized JSON structure django rest framwork

这一生的挚爱 提交于 2020-06-17 09:30:25
问题 I'm wondering if it possible to change structure of my JSON that im sedinding out. currenyly it looks like this: { "para_subject": { "discipline": "MATAN" }, "para_room": { "room": "210" }, "para_professor": { "user": { "username": "yyyy", "email": "yyyy.yyyy@gmail.com", "first_name": "yyyy", "last_name": "yyy" }, "middle_name": "xxxxxx" }, } what is the best way to change it to this: { "discipline": "MATAN", "room": "210", "para_professor": { "username": "yyyy", "email": "yyyy.yyyy@gmail.com

Django users being created with cleartext passwords

纵饮孤独 提交于 2020-06-16 21:21:08
问题 I hav ean issue in my django app where newly created users are being set up with cleartext passwords. This is the failing test. def test_create_valid_user_success(self): """Test creating user with valid user is successful""" payload = { 'email': 'test@email.com', 'password': 'testpass', 'name': 'Test Name' } res = self.client.post(CREATE_USER_URL, payload) self.assertEqual(res.status_code, status.HTTP_201_CREATED) user = get_user_model().objects.get(**res.data) print(user.password) # Comes

Django users being created with cleartext passwords

♀尐吖头ヾ 提交于 2020-06-16 21:19:41
问题 I hav ean issue in my django app where newly created users are being set up with cleartext passwords. This is the failing test. def test_create_valid_user_success(self): """Test creating user with valid user is successful""" payload = { 'email': 'test@email.com', 'password': 'testpass', 'name': 'Test Name' } res = self.client.post(CREATE_USER_URL, payload) self.assertEqual(res.status_code, status.HTTP_201_CREATED) user = get_user_model().objects.get(**res.data) print(user.password) # Comes

Reformat Django REST Framework Serializer to get Output

只谈情不闲聊 提交于 2020-06-16 03:35:10
问题 I am trying to get data in a particular format but i'm not able to get the desired output. My Model: class Category(models.Model): name = models.CharField(max_length=40) class Expense(models.Model): category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="category_name") description = models.CharField(max_length=200) total_amount = models.IntegerField() class Expense_Details(models.Model): expense = models.ForeignKey(Expense, on_delete=models.CASCADE, related_name=