Serialize all models from tastypie resource
Serializes all models of a resource to json. Borrowed from https://github.com/toastdriven/django-tastypie/issues/442
- json
- tastypie
Serializes all models of a resource to json. Borrowed from https://github.com/toastdriven/django-tastypie/issues/442
Although configuring filtering in TastyPie is possible, it is limited to per-field filters, which are not enough for more complex filtering. If your model implement custom manager methods for complex filters, exposing these methods as TastyPie Resource list endpoints is not an easy task. The ModelResource subclass provided here does this, providing 3 ways of complex filtering: * define querysets for filters directly in the Resource declaration * use Model manager custom method * use QuerySet custom method
MongoDB Resource for Tastypie ============================= Allows you to create delicious APIs for MongoDB. Settings -------- MONGODB_HOST = None MONGODB_PORT = None MONGODB_DATABASE = "database_name" Example of Usage ---------------- 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", null=True) class Meta: resource_name = "documents" list_allowed_methods = ["delete", "get", "post"] authorization = Authorization() object_class = Document collection = "documents" # collection name Github Repository ================= <https://github.com/fatiherikli/tastypie-mongodb-resource>
This is an Authorization class for [Tastypie](http://django-tastypie.readthedocs.org/en/latest/authentication_authorization.html) v0.9.11 (v0.9.12 changes how Authorization works). DjangoAuthorization checks specific permissions — `add_model`, `change_model`, `delete_model`, 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 the `login_required` decorator.
In case you ever use [requests](http://python-requests.org/) (or [slumber](http://slumber.in/)) to do requests against a Tastypie API that requires API key authentication, this small custom auth class will help you. Use it like that (with requests): auth = TastypieApiKeyAuth('jezdez', '25fdd0d9d210acb78b5b845fe8284a3c93630252') response = requests.get('http://api.foo.bar/v1/spam/', auth=auth) or with slumber: auth = TastypieApiKeyAuth('jezdez', '25fdd0d9d210acb78b5b845fe8284a3c93630252') api = slumber.API("http://api.foo.bar/v1/", auth=auth) spam = api.spam().get()
5 snippets posted so far.