This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from tastypie.resources import ModelResource | |
| from yourapp.api.cache import CustomCache | |
| from yourapp.models import YourModel | |
| class SampleResource(ModelResource): | |
| class Meta: | |
| queryset = YourModel.objects.all() | |
| resource_name = 'sample' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyResource(ModelResource): | |
| class Meta: | |
| queryset = MyModel.objects.all() | |
| resource_name = 'myresource' | |
| def override_urls(self): | |
| return [ | |
| url(r"^(?P<resource_name>%s)/compare%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_compare'), name="api_get_compare"), | |
| ] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML> | |
| <!-- zero-timeout.html, L. David Baron <dbaron@dbaron.org>, 2010-03-07, 2010-03-09 --> | |
| <!-- | |
| Copyright (c) 2010, The Mozilla Foundation | |
| All rights reserved. | |
| Redistribution and use in source and binary forms, with or without | |
| modification, are permitted provided that the following conditions are |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib.auth.models import User | |
| # from tastypie.authentication import ApiKeyAuthentication | |
| from tastypie.authorization import DjangoAuthorization | |
| from tastypie import fields | |
| from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS | |
| from core.api.authentication import OpenReadApiKeyAuthentication | |
| class UserResource(ModelResource): | |
| bio = fields.CharField(attribute='profile__bio', null=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [04/13/2011 -:- 10:19:17 AM] daniellindsley (~daniellin@gateway.the-worldco.com) joined the channel. | |
| [04/13/2011 -:- 10:19:17 AM] Topic is Tastypie: Creating delicious APIs for Django | Google Group @ http://groups.google.com/group/django-tastypie/ | Submit issues @ http://github.com/toastdriven/django-tastypie/issues | |
| [04/13/2011 -:- 10:19:17 AM] Set by daniellindsley on November 8, 2010 1:54:47 PM CST | |
| [04/13/2011 -:- 10:23:04 AM] Disconnected | |
| [04/13/2011 -:- 10:23:13 AM] daniellindsley (~daniellin@gateway.the-worldco.com) joined the channel. | |
| [04/13/2011 -:- 10:23:13 AM] Topic is Tastypie: Creating delicious APIs for Django | Google Group @ http://groups.google.com/group/django-tastypie/ | Submit issues @ http://github.com/toastdriven/django-tastypie/issues | |
| [04/13/2011 -:- 10:23:14 AM] Set by daniellindsley on November 8, 2010 1:54:47 PM CST | |
| [04/13/2011 -:- 10:42:36 AM] joshbohde: gudmundur: You could probably overwrite dispatch to check if the pk is "self" and if so grab the id of the current use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| matt_c: | |
| * Ellington Story & Section inlines | |
| * Redis PubSub + Node + Whitelist = real-time activity on site | |
| codysoyland: | |
| * Gevent + 0MQ multi-test runner | |
| fxdgear: | |
| * More improvements on SocialBeer.me + Portal 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import datetime | |
| from haystack import indexes | |
| from haystack import site | |
| from myapp.models import Note | |
| class NoteIndex(indexes.SearchIndex): | |
| text = indexes.CharField(document=True, use_template=True) | |
| author = indexes.CharField(model_attr='user') | |
| pub_date = indexes.DateTimeField(model_attr='pub_date') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyResource(ModelResource): | |
| def obj_create(self, bundle, request=None, **kwargs): | |
| """ | |
| A ORM-specific implementation of ``obj_create``. | |
| """ | |
| bundle.obj = self._meta.object_class() | |
| for key, value in kwargs.items(): | |
| setattr(bundle.obj, key, value) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ParentResource(ModelResource): | |
| children = fields.ToManyField(ChildResource, 'children') | |
| def override_urls(self): | |
| return [ | |
| url(r"^(?P<resource_name>%s)/(?P<pk>\w[\w/-]*)/children%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_children'), name="api_get_children"), | |
| ] | |
| def get_children(self, request, **kwargs): | |
| try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SampleResource(ModelResource): | |
| # ... then ... | |
| def dehydrate(self, bundle): | |
| bundle = super(SampleResource, self).dehydrate(bundle) | |
| bundle.data['the_field'] = call_method_that_returns_the_dict() | |
| return bundle | |
| # Or... |