django-rest-framework

ProgrammingError at /admin/order/order/ relation “order_order” does not exist LINE 1: SELECT COUNT(*) AS “__count” FROM “order_order”

此生再无相见时 提交于 2021-02-11 12:32:23
问题 I'm working with django rest framework and I have a app named order. I wanted to change my order logic and I changed order app's models. but when I want to open order and order_item models in admin panel I have this error: ProgrammingError at /admin/order/order/ relation "order_order" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "order_order" and also when i run migrate command it doesn't migrate well and doesn't create the order and OrderItem tabels in the database. I'm using

Pass a custom param in URL with a ModelViewSet

大兔子大兔子 提交于 2021-02-11 12:27:15
问题 What's the best way of passing a param using a ModelViewSet ? Forexample achieving something like this : http://127.0.0.1:8000/api/v1/financing-settings/template/?param=block Below is the approach I was using but found out I have set the param in the body section, but it's not what I want : class TemplateView(ModelViewSet): """ViewSet for Saving Block/ Step template.""" def list(self, request, *args, **kwargs): """Get list of Block/Steps with is_process_template is equal to True.""" param =

405 “Method POST is not allowed” in Django REST framework

半城伤御伤魂 提交于 2021-02-10 19:53:52
问题 I'm using Django REST framework to implement Get, Post api methods, and I got GET to work properly. However, when sending a post request, it's showing 405 error below. What am I missing here? 405 Method Not Allowed {"detail":"Method \"POST\" not allowed."} Sending this body via post method { "title": "abc" "artist": "abc" } I have api/urls.py from django.contrib import admin from django.urls import path, re_path, include urlpatterns = [ path('admin/', admin.site.urls), re_path('api/(?P

Django REST Framework Deep Dive - Where is it determined that an enpoint needs an auth token

独自空忆成欢 提交于 2021-02-10 18:41:52
问题 general django question for those who are more experienced than myself, I'm reading through the code posted for a tutorial on thinkster.io: https://github.com/howardderekl/conduit-django/tree/master/conduit/apps There's an endpoint pertaining to the User model authenticion/models.py that requires an Authorization header for it to return user information defined here in authentication/views.py : class UserRetrieveUpdateAPIView(RetrieveUpdateAPIView): permission_classes = (IsAuthenticated,)

Django REST Framework Deep Dive - Where is it determined that an enpoint needs an auth token

烂漫一生 提交于 2021-02-10 18:41:43
问题 general django question for those who are more experienced than myself, I'm reading through the code posted for a tutorial on thinkster.io: https://github.com/howardderekl/conduit-django/tree/master/conduit/apps There's an endpoint pertaining to the User model authenticion/models.py that requires an Authorization header for it to return user information defined here in authentication/views.py : class UserRetrieveUpdateAPIView(RetrieveUpdateAPIView): permission_classes = (IsAuthenticated,)

How do I get the Django login api to work after extending the user object?

独自空忆成欢 提交于 2021-02-10 18:15:37
问题 I've followed the documentation here to extend my user class, but now my login tests fail. I'm assuming this is due to the extended class not being linked correctly back to the django view that deals with auth. r = self.client.post('/login/', {'username': 'test@test.com', 'password': 'test'}) returns b'\n<!doctype html>\n<html lang="en">\n<head>\n <title>Not Found</title>\n</head>\n<body>\n <h1>Not Found</h1><p>The requested resource was not found on this server.</p>\n</body>\n</html>\n' I've

ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured - Scraper

旧巷老猫 提交于 2021-02-10 17:02:45
问题 When I try to run my scraper in Django I get the following error. This happened when I tried to put the scraped data into the database using the built-in Django models. traceback and error: /usr/bin/python3.6 /home/xxxxxx/Desktop/project/teo/movierater/scrap.py Traceback (most recent call last): File "/home/xxxxxx/Desktop/project/teo/movierater/scrap.py", line 7, in <module> from teo.movierater.api.models import * File "/home/xxxxxx/Desktop/project/teo/movierater/api/models.py", line 3, in

django forms post request raising an error on __init__ method

怎甘沉沦 提交于 2021-02-10 15:57:16
问题 I have a django form which takes a paramater from the view to initialize the MultipleChoiceField based on the user instance. The form is working fine when loading the template. when i submit the form the init method in the form raising an error. My Model models.py from django.db import models from django.contrib.auth.models import User class Group(models.Model): group_name = models.CharField('Group name', max_length=50) def __str__(self): return self.group_name class GroupMembers(models.Model

django forms post request raising an error on __init__ method

假如想象 提交于 2021-02-10 15:55:00
问题 I have a django form which takes a paramater from the view to initialize the MultipleChoiceField based on the user instance. The form is working fine when loading the template. when i submit the form the init method in the form raising an error. My Model models.py from django.db import models from django.contrib.auth.models import User class Group(models.Model): group_name = models.CharField('Group name', max_length=50) def __str__(self): return self.group_name class GroupMembers(models.Model

Django REST Framework NOT NULL constraint failed

旧街凉风 提交于 2021-02-10 14:56:19
问题 when I try to create a new Post by posting the following JSON: { "text": "test", "location": 1 } I get the following error: NOT NULL constraint failed: grapevineapp_post.location_id models.py: class Location(models.Model): name = models.CharField(max_length=80) created = models.DateTimeField(auto_now_add=True) def __str__(self): return self.name class Post(models.Model): text = models.CharField(max_length=512) owner = models.ForeignKey('auth.User', related_name='posts', on_delete=models