tags:

views:

113

answers:

1

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.ModelForm): 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

+1  A: 

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',)},
    }
aeby
It's a good idea but it doesn't work. I don't know why.
pablo
Can you paste your model definition somewhere?
aeby
I did post it in the original question.
pablo
There was a comma missing in the format tuple. I have updated the example.
aeby