django模型时域o min:sec格式

时间:2017-01-09 22:54:06

标签: django models timefield

如何将django模型中的TimeField格式设置为[min:sec],就像音轨一样?

class Song(models.Model):
    title = models.CharField(max_length=128)
    duration = models.TimeField(null=True)

1 个答案:

答案 0 :(得分:0)

在app中创建form.py并在视图中继承此表单如果你想在admin中使用相同的概念,那么也在django admin中继承

from django import forms
from .models import Song
class SongForm(forms.ModelForm):
    duration = forms.TimeField(widget=forms.TimeInput(format='%H:%M'))
    class Meta:
        model = Song