add hours in Django models

2

I am trying to make a movie model in Django, but I would like to add the duration of it and I do not know how to do it very well in django, I know that you can add date and time with datetime in the models. But I only want an hour of duration.

models.py

class Movies(models.Model):
    title = models.CharField(max_length=255)
    poster = models.ImageField(upload_to='media/movies/')
    description = models.TextField()
    duration = models.CharField()
    genre = models.ForeignKey(Genres)
    categorie = models.ForeignKey(Categories)

I have that model, obviously a ChaField in duration would not work because it would accept alphanumeric values and that's not the idea.

If anyone could help me define a format to add hours, I would appreciate it!

    
asked by ikenshu 15.08.2016 в 15:17
source

1 answer

3

I present you to the field DurationField that is used to store periods of time according to the object timedelta .

The precisions can be found in the Django documentation, I leave the link that corresponds to version 1.10: link

    
answered by 15.08.2016 / 16:10
source