Skip to content

Instantly share code, notes, and snippets.

@zeekay
Created October 12, 2012 02:49
Show Gist options
  • Save zeekay/3877034 to your computer and use it in GitHub Desktop.
Save zeekay/3877034 to your computer and use it in GitHub Desktop.
Tastypie helper
from inspect import isclass
from tastypie.resources import ModelResource
from django.conf import settings
from itertools import chain
def generate_urls():
for app in settings.INSTALLED_APPS:
if not app.startswith('django'):
try:
mod = __import__(app + '.api', fromlist=['api'])
for attr in dir(mod):
if not attr.startswith('_'):
obj = getattr(mod, attr)
if isclass(obj) and issubclass(obj, ModelResource):
yield obj().urls
except ImportError:
pass
def resource_urls():
return tuple(chain(*generate_urls()))
urlpatterns = resource_urls()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment