Created
October 12, 2012 02:49
-
-
Save zeekay/3877034 to your computer and use it in GitHub Desktop.
Tastypie helper
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 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