I am trying to process some text files and feed the result directly into a 
django model using create(). As so often seems to happen with me, this 
turns out to not be as simple as I thought it would be. Specifically, I 
can’t seem to get any data into ‘clock’, the time field in my model. When I 
tried making the input data a string, it rejected it. When I tried making 
it a function, it told me it was expecting a string, and no version of int, 
float, or decimal got past Pylint. What is the right way to get this done, 
or do I need to do direct db inserts instead? Here is my code. Thanks.

As a string ***

from io import TextIOBase

from os import environ

import textract

import django

environ['DJANGO_SETTINGS_MODULE'] = 'chronicle.settings'

django.setup()

from ktab.models import Entry


text = textract.process('/home/malikarumi/010417_odt_tests/2018-01-01 
psycopg2-error-at-or-near.odt', encoding='utf_8')

b = TextIOBase(text)

b.write(Entry.objects.create(

   title='2018-01-01 psycopg2-error-at-or-near', content=b, 
chron_date='2018-01-05',

   clock='23:59:59'))

b.save()

(lifeandtimes) malikarumi@Tetuoan2:~/Projects/lifeandtimes/chronicle$ 
python django_textract_7.py

Traceback (most recent call last):

 File "django_textract_7.py", line 17, in <module>

   clock='23:59:59'))

io.UnsupportedOperation: write

--

As a function ***

from time import time, localtime

from io import TextIOBase

from os import environ

import textract

import django

environ['DJANGO_SETTINGS_MODULE'] = 'chronicle.settings'

django.setup()

from ktab.models import Entry


text = textract.process('/home/malikarumi/010417_odt_tests/2018-01-01 
psycopg2-error-at-or-near.odt', encoding='utf_8')

b = TextIOBase(text)

b.write(Entry.objects.create(

   title='2018-01-01 psycopg2-error-at-or-near', content=str(b), 
chron_date='2018-01-05',

   clock=localtime(time())))

b.save()

(lifeandtimes) malikarumi@Tetuoan2:~/Projects/lifeandtimes/chronicle$ 
python django_textract_10.py

Traceback (most recent call last):

 File "django_textract_10.py", line 18, in <module>

   clock=localtime(time())))

<...snip…>

File 
"/home/malikarumi/Projects/lifeandtimes/lib/python3.6/site-packages/django/utils/dateparse.py",
 
line 76, in parse_time

   match = time_re.match(value)

TypeError: expected string or bytes-like object

(lifeandtimes) malikarumi@Tetuoan2:~/Projects/lifeandtimes/chronicle$ 

--

As a string that evaluates to the past ***

(lifeandtimes) malikarumi@Tetuoan2:~/Projects/lifeandtimes/chronicle$ 
python django_textract_9.py

Traceback (most recent call last):

 File "django_textract_9.py", line 17, in <module>

   clock='04:04:04'))

io.UnsupportedOperation: write

***Back to the same old error. How can it not support writing to a single 
field when it writes to all the others? ***
Django 1.11.5 Postgres 9.4, Psycopg2, Python 3.6.3

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/94714f16-9f9d-42e6-add4-5798a9389f09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to