json-api

Serialize an array of models using active_model_serializers

删除回忆录丶 提交于 2019-12-18 12:28:08
问题 I am trying to send the serialized version of a model to a view as a param, using the gem active_model_serializers #app/serializers/admin_serializer.rb class AdminSerializer < ActiveModel::Serializer attributes :id, :email, :access_locked? end #app/controllers/dashboard/admins_controller.rb def index @search = Admin.search(params[:q]) @admins = @search.result(:distinct => true).page(params[:page]).per(10) @page_entries_info = view_context.page_entries_info @admins # render json: @admins

Method “POST” not allowed with Django Rest Framework

我只是一个虾纸丫 提交于 2019-12-13 11:04:03
问题 I'm trying to create a JSON API compliant rest service using Django Rest Framework JSON API: https://django-rest-framework-json-api.readthedocs.io/en/stable/index.html I think I'm stuck at the Django Rest Framework level, but I am not certain. I think the GET request is working, but the POST is not because I get this response: $ curl -H 'Accept: application/vnd.api+json; indent=2' -X POST http://localhost:8000/greeters/ { "errors": [ { "detail": "Method \"POST\" not allowed.", "source": {

PATCHing resources with nested objects with Flask/SQLAlchemy

感情迁移 提交于 2019-12-12 20:45:50
问题 I have the following setup: # models class Author(BaseModel): id = Column(Integer, primary_key=True) first_name = Column(String(64)) last_name = Column(String(64)) class Book(db.Model): id = Column(Integer, primary_key=True) title = Column(String(64)) author_id = Column(Integer, ForeignKey("author.id"), nullable=True) author = relationship(Author, backref=backref('books')) # schema class AuthorSchema(BaseSchema): first_name = fields.Str() last_name = fields.Str() class Meta(BaseSchema.Meta):

Ember.js - How to handle error with DS.store.findRecord() method

你。 提交于 2019-12-12 14:44:41
问题 I am using following simple code to retrieve user from server. var someUser = this.store.findRecord('user', 0); I am using this for retrieving the user. if user is not found on 0 id, server returns 404. and error as per json api. but how do i know about error on client side about it ? 回答1: Taken from Ember guides: Use store.findRecord() to retrieve a record by its type and ID. This will return a promise that fulfills with the requested record. Since the return value is a promise, you can use

How to override the primary key with a JSON API attribute

纵然是瞬间 提交于 2019-12-12 05:19:24
问题 I've got a model called "Membership" that has a string attribute "inviteToken" which I would like to use as my primary key. I've created the following serializer, but cannot get it to pick up the primary key from the JSON. app/serializers/membership.js: import DS from 'ember-data'; export default DS.JSONAPISerializer.extend({ primaryKey: 'invite-token' // also tried 'inviteToken' }); The specific error I'm getting is: Error while processing route: invitations.show Assertion Failed: You must

In Django, how do you keep a module's url configurations encapsulated inside the module?

给你一囗甜甜゛ 提交于 2019-12-11 09:33:06
问题 Currently, I import url configurations into my Django project with: from django.conf.urls import include from django.contrib import admin from django.urls import path, re_path from rest_framework import routers from greeter.views import GreeterViewSet ROUTER = routers.DefaultRouter() ROUTER.register(r'greeters', GreeterViewSet) urlpatterns = [ path('admin/', admin.site.urls), re_path(r'^', include(ROUTER.urls)), ] Is there a way where I can move these parts of the code: ROUTER = routers

Google Cloud Platform - How to upload image file into google cloud storage bucket?

不羁岁月 提交于 2019-12-11 06:24:40
问题 I am trying to upload Image into google cloud storage bucket using Google Cloud Storage JSON API. The file is getting uploaded but it is not showing anything. <?php if(isset($_POST["submit"])) { // Move uploaded file to a temp location $uploadDir = 'temp/'; $filename=$_FILES["fileToUpload"]["name"]; $filesize=$_FILES["fileToUpload"]["size"]; $uploadFile = $uploadDir . basename($_FILES['fileToUpload']['name']); $authheaders = array( "Authorization: Bearer xxxxxx(my access token)", "Content

Ember data JSONAPI complex attribute data

a 夏天 提交于 2019-12-11 06:07:43
问题 I have a data structure as follows coming back from the server for some filter functionality I'm writing. Where each filter-group has many filters. data: [ { type: "filter-group", id: "556d7f5fa1f9de08500ef4e8_1", attributes: { name: "Colour", created-date: "0001-01-01T00:00:00Z", active: true, filters: [ { id: "556d7f5fa1f9de08500ef4e8_1_1", name: "Red", created-date: "0001-01-01T00:00:00Z", active: true }, { id: "556d7f5fa1f9de08500ef4e8_1_2", name: "Blue", created-date: "0001-01-01T00:00

Active Model Serializer and Pundit deleting records during a Show CRUD action

北战南征 提交于 2019-12-11 05:14:00
问题 Okay, something is seriously broken here... I am using Active Model Serializer and Pundit for my Rails 5 JSONAPI server and Ember for my frontend application. I have User model and Pundit policy for User model which prevent non-authors from viewing unpublished stories and chapters. At the moment, I am seeing a weird problem which goes like this: 1. UserA creates StoryA, and two published chapters Chapter1 and Chapter2 2. UserA then creates two unpublished chapters Chapter3 and Chapter4 3.

HATEOAS and links/actions

江枫思渺然 提交于 2019-12-11 04:46:55
问题 I'm trying to wrap my head around how to (and if to) implement HATEOAS in my api. I like one of the concept of feeding the client only actions that are appropriate in the current situation. However I'm not sure if I'm implementing this idea correctly. Let's say I have a resource type order with a status that can be changed, it can have different statuses ( processing , accepted , declined , expired , successful). Should I then create the following json object: { ... "links": { "accept": "http