简体   繁体   中英

django time field displays as none in admin panel

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM