簡體   English   中英

Django / MySQL時間數據類型

[英]Django/MySQL time datatype

我正在使用Django從已經創建並由其他人使用的現有mysql數據庫中導入。 我正在使用:

python manage.py inspectdb > models.py

我所討論的模型中的類如下:

class Funciones(models.Model):
    idfuncion = models.IntegerField(primary_key=True)
    idpelicula = models.ForeignKey(Peliculas, db_column='idpelicula')
    idcine = models.ForeignKey(Cines, db_column='idcine')
    hora = models.TextField() # This field type is a guess.
    tipo_3d = models.IntegerField(null=True, db_column=u'3d', blank=True) # Field renamed
    xd = models.IntegerField(null=True, blank=True)
    gtmax = models.IntegerField(null=True, blank=True)
    vip = models.IntegerField(null=True, blank=True)
    idioma = models.CharField(max_length=33)
    idciudad = models.ForeignKey(Ciudades, db_column='idciudad')
    class Meta:
        db_table = u'funciones'

現在,此屬性為: hora = models.TextField()#此字段類型為猜測值

對應於MYSQL中的時間 dataType。 現在,由於我不能更改MYSQL中的dataType,因為其他人已經從另一個應用程序創建了許多對數據庫的查詢,因此我想知道在Django模型中應該使用的適當的相應django數據類型。 我當時在想DateTimeField,但是在寫入數據庫之前,我必須以某種方式截斷日期部分。

有任何想法嗎?

謝謝

編輯:

正如佩德羅指出:

Django實際上有一個TimeField,為什么不使用它呢? –佩德羅·羅馬諾

您可以使用https://djangosnippets.org/snippets/1060/使用Timedelta對象表示“經過的時間”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM