Permalink
Browse files

Compatible with TastyPie 0.9.12-alpha (dropped support for earlier

versions!)
  • Loading branch information...
1 parent 66136a7 commit 9b1ba600d560dc05f8c0ea34c5bafaa3f61655b9 @dekked dekked committed Aug 20, 2012
Showing with 78 additions and 180 deletions.
  1. +10 −37 README.rst
  2. +1 −1 example/api/resources.py
  3. +64 −139 extendedmodelresource/extendedmodelresource.py
  4. +2 −2 requirements.txt
  5. +1 −1 setup.py
View
@@ -5,19 +5,19 @@
The ``ExtendedModelResource`` is an extension for TastyPie's ``ModelResource`` that adds some interesting features:
* Supports easily using resources as *nested* of another resource, with proper authorization checks for each case.
-* Supports using a custom identifier attribute for resources in uris (not only the object's pk!)
+* [This feature has already been included in the official TastyPie] Supports using a custom identifier attribute for resources in uris (not only the object's pk!)
Requirements
============
Required
--------
-* django-tastypie 0.9.11 and its requirements.
+* Latest django-tastypie from repository (0.9.12-alpha or hopefully greater) and its requirements.
Optional
--------
-* Django 1.4 for the sample project.
+* Django 1.4.1 for the sample project.
Installation
@@ -154,51 +154,24 @@ Caveats
Changing object's identifier attribute in urls
==============================================
-With TastyPie's ``ModelResource`` you can override a method to change the identifier attribute used for objects in the URLs (see `Using Non-PK Data For Your URLs <http://django-tastypie.readthedocs.org/en/latest/cookbook.html#using-non-pk-data-for-your-urls>`_) ::
-
- class UserResource(ModelResource):
- class Meta:
- queryset = User.objects.all()
-
- def override_urls(self):
- return [
- url(r"^(?P<resource_name>%s)/(?P<username>[\w\d_.-]+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
- ]
-
-This adds a new URL using ``username`` and ignores the old URL using ``pk`` ::
-
- ^api/ ^(?P<resource_name>user)/(?P<username>[\w\d_.-]+)/$ [name='api_dispatch_detail']
- ^api/ ^(?P<resource_name>user)/$ [name='api_dispatch_list']
- ^api/ ^(?P<resource_name>user)/schema/$ [name='api_get_schema']
- ^api/ ^(?P<resource_name>user)/set/(?P<pk_list>\w[\w/;-]*)/$ [name='api_get_multiple']
- ^api/ ^(?P<resource_name>user)/(?P<pk>\w[\w/-]*)/$ [name='api_dispatch_detail']
-
-But the old URL is still there, and this can be a bit confusing when you have an error with the URLs.
-
-Using ``ExtendedModelResource`` it is as easy as adding a new entry in the ``Meta`` class ::
+Using the latest TastyPie you can define a ``detail_uri_name`` attribute
+in the ``Meta`` class, to use a different attribute than the object's ``pk`` ::
class UserResource(ExtendedModelResource):
class Meta:
queryset = User.objects.all()
- url_id_attribute = 'username'
-
-And you will get this list of urls ::
-
- ^api/ ^(?P<resource_name>user)/$ [name='api_dispatch_list']
- ^api/ ^(?P<resource_name>user)/schema/$ [name='api_get_schema']
- ^api/ ^(?P<resource_name>user)/set/(?P<username_list>(\w[\w-]*;?)*)/$ [name='api_get_multiple']
- ^api/ ^(?P<resource_name>user)/(?P<username>\w[\w-]*)/$ [name='api_dispatch_detail']
+ detail_uri_name = 'username'
-If you need to change the regular expression used for your identifier attribute in the urls, you can override the method ``get_url_id_attribute_regex`` and return it, like the following example ::
+With ``ExtendedModelResource`` you can change the regular expression used for your identifier attribute in the urls, you can override the method ``get_url_id_attribute_regex`` and return it, like the following example ::
- def get_url_id_attribute_regex(self):
+ def get_detail_uri_name_regex(self):
return r'[aA-zZ][\w-]*'
More information
================
-:Date: 04-19-2012
-:Version: 0.1
+:Date: 08-20-2012
+:Version: 0.2
:Authors:
- Alan Descoins - Tryolabs <alan@tryolabs.com>
- Martín Santos - Tryolabs <santos@tryolabs.com>
View
@@ -38,7 +38,7 @@ class UserByNameResource(ExtendedModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'userbyname'
- url_id_attribute = 'username'
+ detail_uri_name = 'username'
def get_url_id_attribute_regex(self):
# The id attribute respects this regex.
Oops, something went wrong.

0 comments on commit 9b1ba60

Please sign in to comment.