Hello,

1. Please copy your code exactly. Is it really "pytz.timezone(TIME_ZONE)"? Or
   is it "pytz.timezone(*settings.*TIME_ZONE)"? If it is the first one, please
   include the definition or importing of TIME_ZONE.
2. Please pretty-print your dictionary. You can use pprint for that. If it
   doesn't work on OrderedDicts, convert it to a simple dictionary before
   pretty printing.
3. Likewise, do something so that your SQL statement is more readable, such as
   manually inserting newlines and indents.

Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 28/03/2022 22.02, Andrés Alvarez wrote:
I need to save some fields in my database in the format YYY-MM-MM 00:00:00+00. So I decide to do this:
field_to_save = datetime.combine(date_to_save, time.min, 
pytz.timezone(TIME_ZONE))
in settings.py I have:
TIME_ZONE = 'America/Mexico_City'
USE_I18N = True
USE_L10N = True
USE_TZ = True

My model:
class Program(models.Model):
    objects = models.Manager()
    objects_custom = ProgramManager()
    class Meta:
        ordering = ['id']
    # ... others fields
    start_at = models.DateTimeField(null=True)
    finish_at = models.DateTimeField(null=True)

Here are my values to create the register:
OrderedDict([('has_individual_budget', False), ('name', 'plan test create program start_at datetime'), ('program_budget', '0'), ('uuid4', 'd6effacf-3c19-48db-ab06-5af1d97df599'), ('country_list', '[{"id":239,"name":"Venezuela","iso_code2":"VE","iso_code3":"VEN","phone_prefix":58,"currency":"VEF","flag":"U+1F1FB U+1F1EA","phone_national_regex":"^[68]00\\\\d{7}|(?:[24]\\\\d|[59]0)\\\\d{8}$","active":1}]'), ('method_payment', '7fb39a7e-a6de-488b-9564-9bd853b598ec'), ('currency', 'USD'), ('is_saved', False), ('start_at', datetime.datetime(2022, 3, 28, 0, 0, tzinfo=<DstTzInfo 'America/Mexico_City' LMT-1 day, 17:23:00 STD>)), ('finish_at', datetime.datetime(2022, 4, 27, 23, 59, 59, 999999, tzinfo=<DstTzInfo 'America/Mexico_City' LMT-1 day, 17:23:00 STD>)), ('company', <Company: Company object (247)>), ('card_provider', <CardProvider: stripe-usa>), ('payment_provider', <CardProvider: stripe-usa>)]) as you can see the field 'start_at' is the datetime that I want to store in the database, but when I look the insert query: {'sql': 'INSERT INTO "user_program" ("name", "program_budget", "company_id", "active", "uuid4", "country_list", "method_payment", "currency", "create_at", "discharge_program", "updated_at", "deleted_at", "is_saved", "is_suspended", "start_at", "finish_at", "has_individual_budget", "card_provider_id", "payment_provider_id") VALUES (\'plan test create program start_at datetime\', \'0\', 247, true, \'d6effacf-3c19-48db-ab06-5af1d97df599\', \'[{"id":239,"name":"Venezuela","iso_code2":"VE","iso_code3":"VEN","phone_prefix":58,"currency":"VEF","flag":"U+1F1FB U+1F1EA","phone_national_regex":"^[68]00\\\\d{7}|(?:[24]\\\\d|[59]0)\\\\d{8}$","active":1}]\', \'7fb39a7e-a6de-488b-9564-9bd853b598ec\', \'USD\', \'2022-03-28T18:47:10.865801+00:00\'::timestamptz, \'2022-03-28T18:47:10.865870+00:00\'::timestamptz, \'2022-03-28T18:47:10.865913+00:00\'::timestamptz, NULL, false, false, \'2022-03-28T00:00:00-06:37\'::timestamptz, \'2022-04-27T23:59:59.999999-06:37\'::timestamptz, false, 1, 1) RETURNING "user_program"."id"', 'time': '0.267'}
the timezone part is -06:37 should be only -06.
Plase tell me how to fix that, if I need to change the TIME_ZONE or something.

Regards, Andres.

--
You received this message because you are subscribed to the Google Groups "Django users" 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-users/1999ec1e-9170-432e-adc0-71cab3dece6an%40googlegroups.com <https://groups.google.com/d/msgid/django-users/1999ec1e-9170-432e-adc0-71cab3dece6an%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "Django 
users" 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-users/9f518ac9-3b8e-5bc5-fae2-c65ebd00d6c6%40antonischristofides.com.

Reply via email to