FANDOM


New in Django 1.2

By default the admin shows all fields as editable. Any fields in this option (which should be a list or tuple) will display its data as-is and non-editable. This option behaves nearly identical to ModelAdmin.list_display. Usage is the same, however, when you specify ModelAdmin.fields or ModelAdmin.fieldsets the read-only fields must be present to be shown (they are ignored otherwise).

If readonly_fields is used without defining explicit ordering through ModelAdmin.fields or ModelAdmin.fieldsets they will be added last after all editable fields.


code examplesEdit

from django.contrib import admin
from django.db import models
from myproject.myapp import utils

class Author(models.Model):
    first_name = models.CharField(max_length=32)
    last_name = models.CharField(max_length=32)
    birthday = models.DateField()

    def signature(self):
        """
        Returns an image of the author's signature in <a> tags
        """"

        return "<img src='http://authorsigs.com/%s-%s.jpg'/>" % \
            (self.first_name, self.last_name)
    signatures.allow_tags = True
   
class AuthorAdmin(admin.ModelAdmin):
    read_only_fields = ('signature', )
   
admin.site.register(Author, AuthorAdmin)

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.