开发者

input_formats in django admin has no effect

开发者 https://www.devze.com 2022-12-27 07:43 出处:网络
I\'m trying to use input_foramts in the admin but it has no effect. What am I doing wrong? # model class Feedback(models.Model):

I'm trying to use input_foramts in the admin but it has no effect. What am I doing wrong?

# model class Feedback(models.Model):

created_at = models.DateTimeField(auto_now_add=True)

# admin form class FeedbackAdminForm(forms.Mod开发者_Python百科elForm): created_at = forms.DateTimeField(input_formats=('%d/%m/%Y',)) class Meta: model = Feedback

# admin class FeedbackAdmin(admin.ModelAdmin): form = FeedbackAdminForm admin.site.register(Feedback, FeedbackAdmin)

Thanks


Maybe you can use the ModelAdmin.formfield_overrides like this:

class Feedback(models.Model):
    created_at = models.DateTimeField()

    class Meta:
        verbose_name = 'Feedback'
        verbose_name_plural = 'Feedbacks'

    def  __unicode__(self):
        return u'%s' % (self.created_at)

class FeedbackAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.DateTimeField: {'input_formats': ('%d/%m/%Y',)},
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号