Get admin url for a model

1
2
3
4
5
6
from django.core import urlresolvers
from django.contrib.contenttypes.models import ContentType

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,))

More like this

  1. Application-independent permalink to admin url for an object by dchandek 4 years, 2 months ago
  2. Front end admin toolbar by eallik 2 years, 5 months ago
  3. CSV Exporting of Model Data by monokrome 2 years, 6 months ago
  4. ExtendibleModelAdminMixin by dokterbob 2 years, 6 months ago
  5. Automatic urls for static pages by jibbolo 1 year, 6 months ago

Comments

s29 (on October 27, 2010):

Nice. Minor tweak, args=(self.pk,) instead, to support models with explicit primary_key.

#

(Forgotten your password?)