![](/img/trans.png)
[英]Using models between an App and API app in Django Rest framework
我將為現有的 Django 項目創建 API 和 Django Rest 框架。 我想在“ API/models.py ”中使用現有應用程序( product/models.py )的模型。 在使用from product.models import item,... 導入后我將創建serializ ...
[英]Using models between an App and API app in Django Rest framework
我將為現有的 Django 項目創建 API 和 Django Rest 框架。 我想在“ API/models.py ”中使用現有應用程序( product/models.py )的模型。 在使用from product.models import item,... 導入后我將創建serializ ...
[英]How do I use Active-record-serializer to compose custom JSON data
我有以下模型和序列化器。 我想要這樣一種情況,當我向我的 List Controller index發出請求時,我得到Expected Json 。 請看下面: 在這里查看我的數據庫關聯圖預計JSON 楷模 序列化器 我已經描述了我上面的嘗試。 ...
[英]Ruby Active Model serializer custom serializer for same model
可以說我有一個方法如下 現在這有效,它返回我的自定義序列化程序,但如果我想將自定義鍵添加到有效負載,如 {data: application} 它停止工作。 但是當我將渲染方法更改為 它通過錯誤或序列化程序沒有被擊中。 ...
[英]¿How to use a serializer for @record.all?
我有一個帶有序列化器的Kit model: 我需要使用這個序列化程序來渲染我的所有套件,如下所示: 我的路線 我收到一個錯誤: 這是我第一次使用序列化程序,我錯過了什么? ...
[英]ActiveModel::Serializers JSON API nested associations needs to include a value
我有一個 Rails 7 API 並且我正在使用gem 'active_model_serializers', '~> 0.10.0'使 het 符合 json_api 要求,但我需要在我的項目的嵌套屬性中包括名稱,而不僅僅是id 和 type,我嘗試了很多我在互聯網上找到的東西,但沒有一個能 ...
[英]How to render a part of fields embed model?
我想渲染嵌入模型字段的一部分。 我寫了下面的代碼。 但是,我得到的回復包括所有嵌入模型的字段。class RacesController < ApplicationController def index render json: Race.all, include: 'held ...
[英]Why rails_blob_url in the application and in the test works generates different links?
在 ReviewController 中,序列化程序用於顯示 json。 像這兒: 序列化程序使用以下屬性:image 。 像這樣: 此處使用了幫助程序“ rails_blob_url ”。 spec_test 中使用了相同的助手。 像這兒: 運行測試時,圖片的鏈接不匹配 你知道 ...
[英]Use ActiveModelSerializers with rawSQL query result
我想對 Rails 中的 rawSQL 查詢的結果使用 ActiveModelSerializers。 找不到辦法。 我嘗試了幾種選擇: 給出一個PG::Result 給出一個ActiveRecords::Result 但是這些都不能序列化。 ...
[英]Rails active_model_serializers not working
這是我第一次使用active_model_serializers gem,我一直在查看文檔並沒有找到解決方案。 我已遵循所有入門文檔,但是當我嘗試獲取序列化記錄時,我得到標准 rails JSON 未序列化記錄。 我在 SO 中發現了一個類似的線程: active_model_serializers ...
[英]Changing "render" key from "plain" to "json" causes server error
考慮以下代碼class AuthenticatedController < ApplicationController rescue_from InvalidCredentials, with: :unauthenticated def current_user raise ...
[英]How to sort by attributes in rails serializer?
正如標題所說,我應該如何使用 Rails 中的 Active Model Serializer 中的屬性對 api 進行排序? 我有一個包含購物清單的示例 api。 它包括產品名稱、位置和價格。 在我的序列化程序中 我想使用屬性name對其進行排序。 我該怎么做? 謝謝你。 ...
[英]Is there a way to serialize nested attributes outside of the parent with ActiveModel Serializer?
我升級了 activemodel 序列化程序,現在輸出與以前不同。 我試圖讓 JSON 輸出與以前的輸出相匹配。 具體來說,我希望對象嵌套屬性與主對象處於同一級別。 例如,假設我的序列化程序如下: 這將是當前的輸出: 我想要的是這樣的: 我目前正在使用多個序列化程序在控制器中執行此操作 ...
[英]'ArticleSerializer' object has no attribute 'get'
文章序列化器: 設置: model: 查看 function: 我剛剛創建了一個簡單的序列化程序,但是每當我嘗試獲取響應時,它都會說我創建的 ArticleSerializer 沒有屬性“get”。 錯誤 ...
[英]How to add different many-to-many field into a single instance or row of a foreign key in django-rest-framework using model serializer
我正在使用 Django-rest-framework 創建一個電子商務網站並做出反應。 我正在嘗試將商品添加到購物車。 我可以在前端將商品添加到購物車,但我想將購物車數據存儲到后端(Django)數據庫,這樣每當用戶將商品添加到購物車並重新加載頁面時,商品仍應像任何其他商品一樣在他的購物車中其他電 ...
[英]jsonapi::Serializer Specify Foreign Key in Association belongs_to / has_many
我有一個無法修改的數據庫,因為它是從我無法控制的節點中填充的只讀數據庫。 這會導致表具有不同於 Rails 默認方式的foreign_keys 。 您可以在以下模型中看到當前情況:# app/models/epoch_stake.rb class EpochStake < DbSyncReco ...
[英]Rspec test that uses active model serializer in nested engine not passing
AnimalSerializer 位於 animal_engine/app/serializers/api_handler/api/private/mobile_app/v8 奇怪地序列化單個項目有效。 我收到以下錯誤 UncaughtThrowError:未捕獲的拋出:no_serialize ...
[英]How to specify the key format (i.e. camelcase) for an ActiveModel::Serializer :has_many association as a one-off option (not global config)?
我有一個這樣的序列化程序: 我的問題是,在實例化序列化程序並在其上調用as_json時,我得到以下信息: 但是我的前端 API 期望接收fooBars而不是蛇形foo_bars 。 如何將序列化程序配置為 output foo_bars與鍵fooBars的關聯 ...
[英]Name Error at /registration/api/registration/ name 'name' is not defined
實際上,我正在嘗試驗證序列化程序中給出的字段 注意:問題在驗證字段中。 在添加驗證字段之前它工作正常。 有人可以幫我解決這個問題嗎? 我認為驗證很容易,但我遇到了以下問題。 我的序列化程序.py: 我的模型.py: 我收到此錯誤: ...
[英]Conditional Active Model Serializer with Dates
我需要創建一個條件,以便日期小於當前日期的事件不會顯示在 JSON 中,而只能看到即將發生的事件。 class EventSerializer < ActiveModel::Serializer attributes :end_date def end_date date_t ...
[英]Conditional attributes and methods in rails serializer 0.10
在這里,我想對控制器的基本動作設置條件。 例如,我只想為索引操作而不是其他操作發送 conditional_attributes。 但根據我的知識, rails "active_model_serializers", "~> 0.10.0" 並沒有給出任何這樣的東西。 ...