Skip to content

Instantly share code, notes, and snippets.

@vbmendes
Created February 10, 2010 13:21
Show Gist options
  • Save vbmendes/300299 to your computer and use it in GitHub Desktop.
Save vbmendes/300299 to your computer and use it in GitHub Desktop.
def GetAdminAddURL(self, model_class=None, model_instance=None):
# Se passar a classe, utiliza a classe, se passar a instancia
# pega a classe dela.
if model_class is None:
model_class = model_instance.__class__
from django.core import urlresolvers
from django.contrib.contenttypes.models import ContentType
content_type = ContentType.objects.get_for_model(model_class)
return urlresolvers.reverse("admin:%s_%s_add" % (content_type.app_label,
content_type.model))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment