Created
January 29, 2015 15:52
-
-
Save walterrenner/70354ed96e81de57724f to your computer and use it in GitHub Desktop.
get_admin_url() for any model instance
This file contains 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 django.core import urlresolvers | |
from django.contrib.contenttypes.models import ContentType | |
from django.db import models | |
class MyModel(models.Model): | |
def get_admin_url(self): | |
content_type = ContentType.objects.get_for_model(self.__class__) | |
return urlresolvers.reverse("admin:%s_%s_change" % (content_type.app_label, content_type.model), args=(self.id,)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
source: http://stackoverflow.com/questions/10420271/django-how-to-get-admin-url-from-model-instance