djangosnippets.org: Latest snippets tagged with 'tastypie'http://djangosnippets.org/tags/tastypie/2013-03-08T11:22:11.660306-06:00Serialize all models from tastypie resource
2013-03-08T11:22:11.660306-06:00xtranophilisthttp://djangosnippets.org/snippets/2900/<p>Serializes all models of a resource to json.</p>
<p>Borrowed from https://github.com/toastdriven/django-tastypie/issues/442</p>
Freely redistributableTatsypie: additional list endpoints for custom Model's manager methods
2012-11-15T17:38:29.397752-06:00migajekhttp://djangosnippets.org/snippets/2847/<p>Although configuring filtering in TastyPie is possible, it is limited to per-field filters, which are not enough for more complex filtering.</p>
<p>If your model implement custom manager methods for complex filters, exposing these methods as TastyPie Resource list endpoints is not an easy task.</p>
<p>The ModelResource subclass provided here does …</p>
Freely redistributableTastypie MongoDB Resource
2012-10-04T08:09:15.533081-05:00fatiheriklihttp://djangosnippets.org/snippets/2830/<h1>MongoDB Resource for Tastypie</h1>
<p>Allows you to create delicious APIs for MongoDB.</p>
<h2>Settings</h2>
<pre><code>MONGODB_HOST = None
MONGODB_PORT = None
MONGODB_DATABASE = "database_name"
</code></pre>
<h2>Example of Usage</h2>
<pre><code>from tastypie import fields
from tastypie.authorization import Authorization
from tastypie_mongodb.resources import MongoDBResource, Document
class DocumentResource(MongoDBResource):
id = fields.CharField(attribute="_id")
title = fields.CharField(attribute="title", null=True)
entities = fields.ListField(attribute="entities", …</code></pre>
Freely redistributableTastypie v0.9.11 LoginRequiredAuthorization
2012-08-16T15:55:41.562047-05:00cottonhttp://djangosnippets.org/snippets/2801/<p>This is an Authorization class for <a href="http://django-tastypie.readthedocs.org/en/latest/authentication_authorization.html">Tastypie</a> v0.9.11 (v0.9.12 changes how Authorization works).</p>
<p>DjangoAuthorization checks specific permissions — <code>add_model</code>, <code>change_model</code>, <code>delete_model</code>, etc. If you don't need that level of permissions checking, this might be useful. It just makes sure the User is logged in. It's equivalent to …</p>
Freely redistributableCustom requests auth class for Tastypie API key authentication
2012-03-30T05:52:25.098864-05:00jezdezhttp://djangosnippets.org/snippets/2727/<p>In case you ever use <a href="http://python-requests.org/">requests</a> (or <a href="http://slumber.in/">slumber</a>) to do requests against a Tastypie API that requires API key authentication, this small custom auth class will help you.</p>
<p>Use it like that (with requests):</p>
<pre><code>auth = TastypieApiKeyAuth('jezdez', '25fdd0d9d210acb78b5b845fe8284a3c93630252')
response = requests.get('http://api.foo.bar/v1/spam/', auth=auth)
</code></pre>
<p>or with slumber:</p>
<pre><code>auth = TastypieApiKeyAuth('jezdez', '25fdd0d9d210acb78b5b845fe8284a3c93630252') …</code></pre>
Freely redistributable