Ching 482b55e66d feat(package.json): 重装依赖
重装依赖

Signed-off-by: Ching <loooching@gmail.com>
2022-02-02 21:07:01 +08:00

15 lines
3.3 KiB
HTML

<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="X-UA-Compatible" content="IE=edge"><title> Tastypie · MarkDown</title><meta name="description" content="Tastypie - Ching"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="short icon" href="/favicon.png"><link rel="stylesheet" href="/css/apollo.css"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600" type="text/css"><meta name="generator" content="Hexo 6.0.0"><link rel="alternate" href="/atom.xml" title="MarkDown" type="application/atom+xml">
</head><body><header><a href="/" class="logo-link"><img src="/logo.png"></a><ul class="nav nav-list"><li class="nav-list-item"><a href="/" target="_self" class="nav-list-link">ALL</a></li><li class="nav-list-item"><a href="/categories/leetcode/" target="_self" class="nav-list-link">LEETCODE</a></li><li class="nav-list-item"><a href="/atom.xml" target="_self" class="nav-list-link">RSS</a></li></ul></header><section class="container"><div class="post"><article class="post-block"><h1 class="post-title">Tastypie</h1><div class="post-meta"><div class="post-time">2016年5月4日</div></div><div class="post-content"><h4 id="Resources-in-Tastypie"><a href="#Resources-in-Tastypie" class="headerlink" title="Resources in Tastypie"></a>Resources in Tastypie</h4><p>Resources are the heart of Tastypie. By defining a resource we can actually convert a model into an API stream. The data is automatically converted into API response.</p>
<p>Understanding the process of creating a resource.</p>
<ol>
<li>Import ModelResource from Tastypie.</li>
<li>Import models from services app</li>
<li>Create custom resource by inheriting ModelResource and link app model in inner Meta class of resource.</li>
</ol>
<p>Add API URL in the urls.py of app.</p>
<h4 id="Dehydrating-the-JSON-data"><a href="#Dehydrating-the-JSON-data" class="headerlink" title="Dehydrating the JSON data"></a>Dehydrating the JSON data</h4><p><img src="https://impythonist.files.wordpress.com/2016/04/tastypie_ill.png?w=800" alt="flow"></p>
<p>Dehydration in Tastypie means making alterations before sending data to the client. Suppose we need to send capitalized product names instead of small letters. Now we see two kinds of dehydrate methods.</p>
<h5 id="Dehydrate-field-method"><a href="#Dehydrate-field-method" class="headerlink" title="Dehydrate_field method"></a>Dehydrate_field method</h5><p>This <code>dehydrate_field</code> is uesd to modify field on the response JSON. </p>
<h5 id="Dehydrate-method"><a href="#Dehydrate-method" class="headerlink" title="Dehydrate method"></a>Dehydrate method</h5><p>Dehydrate method is useful for aadding additional fields to bundle (response data). </p>
<p>Similarly using <code>hydrate</code> method we can alter the bundle data which is generated from request at the time of PUT or POST methods.</p>
</div></article></div></section><footer><div class="paginator"><a href="/2016/05/10/TastyPie-Note-1/" class="prev">PRVE</a><a href="/2016/04/25/Django-Manager-Method/" class="next">NEXT</a></div><div class="copyright"><p>© 2016 - 2022 <a href="http://blog.tunpok.com">Ching</a>, unless otherwise noted.</p></div></footer><script src="https://cdn.bootcss.com/mathjax/2.5.3/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script></body></html>