Can't display DateField on form with auto_now = True

后端 未结 2 739
無奈伤痛
無奈伤痛 2021-01-25 00:59

I have a model with auto_now, and auto_now_add set for Update and Create fields:

class HotelProfiles(models.Model):
  fe_result_id = models.AutoField(primary_key         


        
2条回答
  •  半阙折子戏
    2021-01-25 01:25

    • Make the fields you want readonly
    • explicitly override what fields are available in this admin form (readonly fields will be present but readonly)

    Example:

    from django.contrib import admin
    
    class HotelProfilesAdmin(admin.ModelAdmin) :
        # Keep the fields readonly
        readonly_fields = ['fe_created_date','fe_updated_date']
    
        # The fields in the order you want them
        fieldsets = (
            (None, {
                'fields': ('fe_created_date', 'fe_updated_date', ...other fields)
            }),
        )
    
    # Add your new adminform to the site
    admin.site.register(HotelProfiles, HotelProfilesAdmin)
    

提交回复
热议问题