python


DateFields not using custom DATE_FORMAT for output


I've followed Django's documentation in order to set the date output format for all the DateFields used in my project.
Despite this, dates are still not being rendered in the format I'm enforcing. They're being outputted as YYYY-mm-dd instead.
Here's my config:
settings.py
USE_L10N = False
DATE_FORMAT = '%d/%m/%Y'
SHORT_DATE_FORMAT = '%d/%m/%Y'
DATE_INPUT_FORMATS = [
'%d/%m/%Y', # '25/10/2006'
]
Is there something I'm missing here, or is this a bug with Django?
Are you specifying how the template engine should format your variable? You need to add the date tag where you output your variable in the template.
From the documentation:
If value is a datetime object (e.g., the result of datetime.datetime.now()), the output will be the string 'Wed 09 Jan 2008'.
When used without a format string, the DATE_FORMAT format specifier is used. Assuming the same settings as the previous example:
[...]
Meaning you have to do something like this:
{{ my_variable|date }}
With the help of FunkyBob on IRC, the issue has been resolved.
I was using a custom widget for my DateFields:
class CalendarWidget(forms.TextInput):
class Media:
css = {
'all': ('main/js/vendor/pickadate.js-3.5.6/lib/compressed/themes/default.css',
'main/js/vendor/pickadate.js-3.5.6/lib/compressed/themes/default.date.css',)
}
js = ('main/js/vendor/pickadate.js-3.5.6/lib/compressed/picker.js',
'main/js/vendor/pickadate.js-3.5.6/lib/compressed/picker.date.js',
'main/js/datepicker.min.js',)
I simply had to use forms.DateInput instead of forms.TextInput in order for it to output my dates in the correct format.

Related Links

how to get subclassed QWidgets from QToolBox?
Reading from pipe stdout waits infinitely
Getting Slice of one dimension in ndarray
Parsing Tex using python re library
Fix the seed for the community module in Python that uses networkx module
select first n items of a list without using a loop.
when I initiate second button click -> AttributeError: Application instance has no attribute 'readfile'
Python 3.4 with an older Python script for use in Blender, TypeErrors
error when installing numpy for pypy2.2.1
How to find out in which locale it was encoded to?
alembic revision - multiple heads (due branching) error
Python set value multiindex Pandas
Multiplication table for double digit numbers using nested loops in Python
pandas time_range does not start from start date
Django How about my method to solve anti spam post request? Is there better solutions?
How can I write a csv file with multiple header lines with pandas to_csv()?

Categories

HOME
makefile
converter
ssas-2012
tinyos
freepascal
wmic
drupal-7
bing
antivirus
jasmine
mainframe
is-empty
file-io
ng-admin
shipping
eclipse-cdt
wicket
iso
image-recognition
dlib
arm-template
google-people
android-fragmentactivity
cvs2svn
plsqldeveloper
cocoa-touch
spring-ws
philips-hue
datadog
superscript
crt
smart-mobile-studio
backup-strategies
pljson
data-extraction
nsurlconnection
code-behind
agent
polyfills
jrules
stress-testing
drawingarea
defold
jgraph
applepayjs
persistent
udev
volume
gce
iron.io
barcode-printing
project-template
cjson
iostat
libreadline
push-diffusion
slam-algorithm
json-schema-validator
spring-lemon
emokit
project-online
spinlock
multinomial
anythingslider
java.util.calendar
data-import
mirrorlink
qbfc
type-mismatch
jcr-sql2
utf-32
pgagent
sid
dache
getimagedata
valence
colt
internal
roxygen
healthvault
confusion-matrix
sslexception
nimrod
nscolor
leptonica
jqmobi
surveyor-gem
lame
fortran77
appfog
domain-calculus
tridion2009
git-filter-branch
linkedhashset
icefaces-3
continuous-testing
electronic-signature
curljs
paintcomponent
svn-hooks
requestfactory
task-management
system-codedom-compiler
configurable
database-diagramming
interface-design
associativity

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App