Reputation: 137
In the admin page I added the following code:
class StoryAdmin(admin.ModelAdmin):
list_display = ('__unicode__', 'domain', 'moderator', 'created_at', 'updated_at')
list_filter = ('created_at', 'updated_at')
search_fields = ('title','moderator__username','moderator__first_name','moderator__last_name')
fields = ('title','url','created_at','updated_at')
readonly_fields = ('created_at','updated_at')
admin.site.register(Story, StoryAdmin)
Everything works just fine, except when I add a new story in the admin panel the readonly_fields
in the template displays as (none)
!
Upvotes: 0
Views: 235
Reputation: 174624
This is by design; from the readonly_fields
documentation:
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; they are also excluded from the ModelForm used for creating and editing.
If you want your users not to edit fields, simply do not show them as part of the admin form, by removing them from the fields
tuple.
Upvotes: 2