code: def gen_url_regex(resource):
      " URL regex for resource class generator. "
  
      if resource._meta.parent:
          yield resource._meta.parent._meta.url_regex.rstrip('/$').lstrip('^')
  
      for p in resource._meta.url_params:
          yield '%(name)s/(?P<%(name)s>[^/]+)' % dict(name=p)
  
      if resource._meta.prefix:
          yield resource._meta.prefix
  
      yield '%(name)s/(?P<%(name)s>[^/]+)?' % dict(name=resource._meta.namef gen_url_regex(resource):
      " URL regex for resource class generator. "
  
      if resource._meta.parent:
          yield resource._meta.parent._meta.url_regex.rstrip('/$').lstrip('^')
  
      for p in resource._meta.url_params:
          yield '%(name)s/(?P<%(name)s>[^/]+)' % dict(name=p)
  
      if resource._meta.prefix:
          yield resource._meta.prefix
  
      yield '%(name)s/(?P<%(name)s>[^/]+)?' % dict(name=resource._meta.name)
docs: URL regex for resource class generator.