please help: problem saving strings to the database

41 megtekintés
Ugrás az első olvasatlan üzenetre

Sabine Maennel

olvasatlan,
2014. nov. 21. 6:57:402014. 11. 21.
– django...@googlegroups.com
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

Tiago Almeida

olvasatlan,
2014. nov. 21. 9:02:202014. 11. 21.
– django...@googlegroups.com
Check if you have a comma after the string.

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

Szymon Krzemiński

olvasatlan,
2014. nov. 21. 13:21:512014. 11. 21.
– django...@googlegroups.com
Looks like the record is stored as a one-element tuple. Don't know what's the source of this behaviour yet, though.

Sabine Maennel

olvasatlan,
2014. nov. 22. 5:49:312014. 11. 22.
– django...@googlegroups.com
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!

Sabine Maennel

olvasatlan,
2014. nov. 22. 5:51:162014. 11. 22.
– django...@googlegroups.com
Thank you Szymon, Tiago just got it: I had a misplaced comma that caused the error.
Válasz mindenkinek
Válasz a szerzőnek
Továbbítás
0 új üzenet