私のモデル:
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 (... 基本的には template1.html と同じ)
{% load mytagsandfilters %}
{{ another_question.published_date|show_date_the_way_management_wants_it:"D d M Y" }}
私の目標: 2 つの場所で重複しているため、テンプレート フィルターの使用を削除したいと考えています。
これにより、私はもっときれいになります:
template1.html
{% load mytagsandfilters %}
{{ question.published_date }}
template2.html
{% load mytagsandfilters %}
{{ another_question.published_date }}
それで...
Q. これを行うために StackOverflowQuestion モデル クラスのメソッドをオーバーライドする方法はありますか? それとも、models.DateTimeField をサブクラス化してそれを行う方法でしょうか? それとも他の方法ですか?