Home Python Django Datetime objects and literal strings vs variables
Reply: 0

Python Django Datetime objects and literal strings vs variables

user910
1#
user910 Published in April 22, 2018, 6:06 pm

I am transferring some legacy posts into a new Django blog. In my script, I have the following code:

    Entry.objects.create(
        title=['title'], slug=['slug'], chron_date=['chron_date'],
        clock='23:59:59', content=['content'])

The problem is that the date, time, and datetime fields all refuse to take a variable, or, they all treat the intended variable as a literal string, which generates errors. The only solution I’ve found is the one you see for clock, where I have to hard code a literal string. This means I have to go back through the posts one at a time to manually correct the dates and times.

Questions: Why do the date and time objects work this way? Is this the only workaround, or am I missing something that would allow me to use a variable and loop through all the actual dates and get them imported?

Thanks.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.3165 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO