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
| var data = JSON.stringify({ | |
| "user": "/api/v1/user/1", | |
| "title": "My New Blog Post", | |
| "body": "Something interesting should be here..." | |
| }); | |
| $.ajax({ | |
| url: '/api/v1/entry/', | |
| type: 'POST', | |
| contentType: 'application/json', |
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 HiddenFieldResource(ModelResource): | |
| secret = fields.CharField(help_text="Public lookup key.") | |
| def hydrate_secret(self, bundle): | |
| lookup_key = bundle.obj.secret | |
| bundle.obj.secret = lookup_secret(lookup_key) | |
| return bundle | |
| def dehydrate_secret(self, bundle): | |
| bundle.data['secret'] = bundle.obj.secret.lookup_key |
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 django.db import models | |
| class Profile(models.Model): | |
| user = models.OneToOneField(User) | |
| silly_field = models.CharField(max_length=255, default="Silly") | |
| def auto_create_profile(sender, instance, created, **kwargs): | |
| if created: | |
| user.profile, created = Profile.objects.get_or_create(user=instance) |
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
| { | |
| "name": "foo", | |
| "resource_uri": "/api/v1/list/1", | |
| "items": { | |
| "meta": { | |
| "resource_uri": "/api/v1/list/1/items/", | |
| "count": 5 | |
| }, | |
| "objects": [ |
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 UserResource(ModelResource): | |
| def dispatch_detail(request, **kwargs): | |
| if kwargs.get('pk') == "self": | |
| # This assumes that self.is_authenticated sets request.user | |
| self.is_authenticated(request) | |
| kwargs['pk'] = request.user.id | |
| return CurrentUserResource.dispatch_detail(request, **kwargs) | |
| return super(UserResource, self).dispatch_detail(request, **kwargs) | |
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
| 07:10 < bedspax> uhm | |
| 07:10 < bedspax> i'm confused :) | |
| 07:16 < danielzilla> DanGer: Hard to say without seeing your code. If the template has inheritance, the context will act as a list, so you might need to try ``resp.context[-1]``. | |
| 07:16 < bedspax> danielzilla, hi | |
| 07:16 < bedspax> for my doubts, what you advice to me? | |
| 07:17 < danielzilla> bedspax: I have no clue what you're asking about. | |
| 07:18 < bedspax> i would have in the same resource this three resources, that are related to the model User: http://dpaste.com/hold/531887/ | |
| 07:19 < danielzilla> I'm sorry, I don't understand. Are you trying to combine them into one resource, or just get the ``ForeignKey`` fields working. | |
| 07:20 < bedspax> ok np | |
| 07:20 < bedspax> the first |
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
| v1_api = Api(api_name='v1') | |
| v1_api.register(BookResource()) | |
| # Intentionally left out PageResource |
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
| _ = require 'underscore' | |
| express = require 'express' | |
| cradle = require 'cradle' | |
| class Queue | |
| # Class to store the queue documents to store in Couch. | |
| constructor: -> | |
| _.bindAll @, 'flush' | |
| @reqs = [] |
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 MyGeoResource(Resource): | |
| def apply_sorting(self, objects, options=None): | |
| if options and "longitude" in options and "latitude" in options: | |
| return objects.distance(Point(options['latitude'], options['longitude'])).order_by('distance') | |
| return super(MyGeoResource, self).apply_sorting(objects, options) | |