#34214: Bug in default for TimeField when using a timezone
------------------------------------------+------------------------
               Reporter:  PierreAnquetil  |          Owner:  nobody
                   Type:  Uncategorized   |         Status:  new
              Component:  Uncategorized   |        Version:  4.1
               Severity:  Normal          |       Keywords:
           Triage Stage:  Unreviewed      |      Has patch:  0
    Needs documentation:  0               |    Needs tests:  0
Patch needs improvement:  0               |  Easy pickings:  0
                  UI/UX:  0               |
------------------------------------------+------------------------
 Hi !

 In Python, a datetime.time instance can have a timezone.

 For a Timefield model in Django, which represents a datetime.time
 instance, it should be logic to use a datetime.time to set a default.

 In fact, it's partially possible :

 models.TimeField(null=False,blank=False,default=time(18,30,0,0,None)) or
 models.TimeField(null=False,blank=False,default=time(18,30,0,0)) works

 But when you want to use a timezone on your default, it does not work :
 
models.TimeField(null=False,blank=False,default=time(18,30,0,0,tz.gettz('Europe/Paris')))
 dont works.

 In Django 3.1, the error was that it was not possible to use <= between
 timefieldand Datetimefield. So i guess the error was that when setting a
 timezone on a time, when the default of timefield had a timezone set,
 django was converting it in a datetimefield.


 In Django 4.1, the error message changed : NameError  : name 'tzfile' is
 not defined.
 In my models.py, i use :
 from dateutil import tz
 ...
 
heure_midi=models.TimeField(null=False,blank=False,default=time(18,30,0,0,tz.gettz('Europe/Paris')))

 It's transformed in the migration in :

 import datetime
 ...

 migrations.AddField(
             model_name='restaurant',
             name='heure_soir',
             field=models.TimeField(default=datetime.time(18, 30,
 tzinfo=tzfile('Europe/Paris'))),
         ),

 the import datetime works, but there is no import tz or anything, and the
 tz.gettz has been changed in "tzfile"

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34214>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070185188637f0-0f1d91e3-ebf9-4da2-aaf8-c8018a3bbcb1-000000%40eu-central-1.amazonses.com.

Reply via email to