I can't seem to write a line from a file to a field of a Django model. The field is described in the model as:
text = models.TextField(null=True, blank=True, help_text='A status message.')
However, when I attempt to create a new object I cannot fill this field using the readline function:
file = open(filename, 'r')
str = file.readline()
When I attempt to use str
for the text field I don't seem to be able to read or write to the database. I'm not given any error so I'm assuming its an encoding problem. Any advice? Thanks.
edit
The database is a postgres database and the field type is "text".
The code I'm using to create the object is:
Message.objects.create_message(sys, str)
and
def create_message(self, system, msg):
"""Create a message for the given system."""
m = Message.objects.create(system=system,
text=msg)
return m