2

my model:

class StackOverflowQuestion(models.Model):
     published_date = models.DateTimeField(...)

template1.html:

{% load mytagsandfilters %}

{{ question.published_date|show_date_the_way_management_wants_it:"D d M Y" }}

template2.html (...basically identical to template1.html)

{% load mytagsandfilters %}

{{ another_question.published_date|show_date_the_way_management_wants_it:"D d M Y" }}

My goal: I want to remove the use of the template filter because it's duplicated in two places.

This would leave me something way cleaner:

template1.html

{% load mytagsandfilters %}

{{ question.published_date }}

template2.html

{% load mytagsandfilters %}   

{{ another_question.published_date }} 

so...

Q. Is there a way maybe to override a method in the StackOverflowQuestion model class to do this? Or maybe a way to subclass models.DateTimeField to do it? Or some other way?

David Lam
  • 4,689
  • 3
  • 23
  • 34
  • note note: I'm not looking for the DATE_FORMAT setting as I need to write some Python to implement a set of requirements etc. – David Lam Jan 25 '13 at 01:00
  • oh also, i tried subclassing models.DateTimeField and overriding __ unicode __ ...but that doesn't appear to be the right spot/way – David Lam Jan 25 '13 at 01:08
  • The only way I know of is to build a custom model field (fields specify a default widget). I wish I could override the default modelform engine widget per model field instance. Starring – Yuji 'Tomita' Tomita Jan 25 '13 at 01:34

1 Answers1

0

Since you don't want to customize DATE_FORMAT in your settings.py, you can still act at the form level. As mentionned in this post, the DateInput widget should do the trick.

Community
  • 1
  • 1
Mathieu
  • 431
  • 1
  • 6
  • 15