Login

Snippets by hchargois

Snippet List

Readonly fields with link to change page in admin

Usage : class MyModelAdmin(ReadonlyLinksMixin, admin.ModelAdmin): readonly_fields_links = ('field1', 'field2') This adds a new ModelAdmin property (`readonly_fields_links`) that acts like the default `readonly_links` except that (if the field's type is a model that can be edited in the admin site) the value of the field has a link to the object. Same functionality as * [This snippet](https://www.djangosnippets.org/snippets/937/) * [and this one](https://www.djangosnippets.org/snippets/1008/) Except that it works without messing with the form that gets validated and saved, and thus without sometimes saving None values. It uses the documented property that `readonly_fields` can be callables ([Django doc](https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display)) : the fields in `readonly_links_fields` are turned into callables that are appended to `readonly_links`. Each callable creates the linked value.

  • admin
Read More

hchargois has posted 1 snippet.