解決済み: django フォームの日付ピッカー

Django フォームの日付ピッカーの主な問題は、あまりユーザーフレンドリーではないことです。 さまざまなオプションを見つけて使用するのは難しく、ピッカーを Django Web サイトの他の部分と組み合わせて使用​​する方法が明確ではありません。

I am trying to use a date picker in my Django form. I have tried using the following code:
<code>{{ form.date_of_birth }}
</code>
But this does not work. Can anyone help?


A:

You need to add <code>class="vDateField"</code> to your field in order for the jQuery UI DatePicker widget to be applied.  For example, if you have a field named <code>date_of_birth</code>, then you would do something like this:  <code>{{ form.date_of_birth|add_class:"vDateField" }}</code>.  You can also add this class directly in your model's Meta class, like so:  <code>Meta: fields = ('date_of_birth', ) widgets = {'date_of': forms.TextInput(attrs={'class': 'vDateField'})}</code>.  

フォーム

フォームは Django の強力なツールです。 ユーザーからデータを収集し、データベースに保存できます。 フォームを使用すると、カスタム フォームを作成して、データベースへのデータ送信をより簡単にすることもできます。

Django での日付

Django では、日付は datetime オブジェクトです。 日付は、単純な datetime オブジェクトまたは DateTime クラスのインスタンスのいずれかです。

関連記事:

コメント