2👍
You need to decide if you are ok with a regular date object on the model (and the DB) and will just customize the form widgets or if you want the data store to have the specific data.
If you only want to have forms display day and month, you need to write a custom widget and hook it up to the form in the ModelAdmin class. Django’s documentation has a pretty good introduction to writing custom fields and custom widgets
In both cases it’s much easier to subclass an existing Model / widget and change the behavior you want.
1👍
A DateField
is a whole date. If you only care about the month and day then use __month
and __day
when querying.
- Django: vps or shared hosting?
- Django – skip first row of array
- From django.contrib.gis.geos import GEOSException, GEOSGeometry, fromstr ImportError: cannot import name GEOSException
- ImportError: 'tests' module incorrectly
- Is it possible to use fixtures from other apps in django's tests?
1👍
This works for me:
data_sorted = sorted(My_Model.objects.all(), key=lambda e: e.myDataField.strftime("%m-%d"))
Source:stackexchange.com