Reputation: 453
I'm trying to have the DateField (created_at/updated_at) I have set up to be a readonly field that I can access through both the list_display and the form for adding in Django Admin. The way I have it set up it's showing as:
%09/%24/%2018
I know it's pulling from DATE_FORMAT in settings.py:
DATE_FORMAT = '%m/%d/%Y'
I just haven't figured out how to remove the % before it is displayed in Admin. Is there a way to clean this up? I've tried already to access the created_at/updated_at fields to write an algorithm to remove the extra characters, but can't seem to extract the values.
Here is my code if that helps. Thanks in advance!
class BatchForm(forms.ModelForm):
class Meta:
model = Batch
fields = '__all__'
class BatchAdmin(admin.ModelAdmin):
form = BatchForm
readonly_fields = ('created_at', 'updated_at')
list_display = ('item', 'active', 'desc', 'quantity', 'created_at', 'updated_at')
class Batch(models.Model):
created_at = models.DateField(auto_now_add=True)
updated_at = models.DateField(auto_now=True)
Upvotes: 0
Views: 115
Reputation: 780
Based on the documentation, for the DATE_FORMAT, you do not need to put the %
. So you would actually want to simply put DATE_FORMAT = 'm/d/Y'
Upvotes: 1