I am using Django Admin to visualize and edit data of my Model. One of the model's field is date and unfortunately is a CharField but with a validator ( dd.mm.yyyy ). I am trying to figure out of a solution to sort those dates in the correct way when the admin press on the sort button that is default from django. In my experience with Java it was all about overwriting the compare function of the class.
data_de_montat = models.CharField(help_text="eg: 02.07.2020 or 12.9.2021", max_length=15, validators=[
RegexValidator(r'^[0-9]{1,2}.[0-9]{1,2}.[0-9]{4}$',
message='It should be dd.ll.aaaa',
code='wrong format'
)])

In django it is very easy. You only need to go in to admin.py make a class with you model name and than add filter on create date which automatically sort out all dates for you. Example:
Step 1: Go to admin.py of your app
Step 2:Add following code
class YourModelAdmin(admin.ModelAdmin):
list_filter=['data_de_montat']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With