Saturday, November 22, 2014

Re: please help: problem saving strings to the database

Thank you Tiago, you got it. It was the Comma. So grateful to you. I searched for hours and did not catch this simple reason, that resulted form my copy and paste!

Am Freitag, 21. November 2014 15:02:20 UTC+1 schrieb Tiago Almeida:
Check if you have a comma after the string.

 log = ClassroomLog.objects.get(...)
        log.text = "Hallo",
        log.save()

Sexta-feira, 21 de Novembro de 2014 11:57:40 UTC, Sabine Maennel escreveu:
Hello,

I do not know why this is happening: If I try to update a database record the text gets into the field the wrong way:

models.py

from model_utils.models import TimeStampedModel

class ClassroomLog(TimeStampedModel):
    ...
    text = models.TextField()

then somewhere else I put data in that database like that:

        ...
        log = ClassroomLog.objects.get(...)
        log.text = "Hallo"
        log.save()

then the field in the database will contain this:

        ('Hallo',) 

What am I doing wrong here?

If I do this instead: 

        ...
        log = ClassroomLog.objects.get(...)
        log.delete()
        log = ClassroomLog(..., text = "Hallo", ...)
        log.save()

it works out as expected and the admin of the database shows for list_display = ('text',): 

        Hallo  

Can someone please help me with this. I tried for quite a while, but could not figure out what is happening.

         with kind regards and thanks in advance
                 Sabine

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9e3331a5-1278-4b6d-bafb-e2fee77c0dfa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment