Skip to content

Instantly share code, notes, and snippets.

@codysoyland
Created May 2, 2010 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codysoyland/387536 to your computer and use it in GitHub Desktop.
Save codysoyland/387536 to your computer and use it in GitHub Desktop.
diff --git a/tastypie/api.py b/tastypie/api.py
index 0344a81..b4f2adc 100644
--- a/tastypie/api.py
+++ b/tastypie/api.py
@@ -50,6 +50,19 @@ class Api(object):
# Register it globally so we can build URIs.
_add_resource(self, resource, canonical)
+ def register_representation(self, representation, name, canonical=True):
+ """
+ Registers a ``Representation`` subclass with the API.
+
+ This serves as a Resource factory method and a proxy to Api.register
+ to reduce boilerplate in cases where you need no customization in your
+ ``Resource`` subclass.
+ """
+ class BasicResource(Resource):
+ representation = representation
+ resource_name = name
+ self.register(BasicResource, canonical)
+
def unregister(self, resource_name):
"""
If present, unregisters a resource from the API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment