[1.11] deviation between .create() and .update()

47 views
Skip to first unread message

Henrik Baran

unread,
Nov 12, 2017, 7:59:57 AM11/12/17
to django...@googlegroups.com
Hi Django users,

I observed something weird while trying to update an existing database
record. I create new records by passing a dictionary as **kwargs to
.create(). This dictionary includes strings, integers and model
instances matching with my model fields. However, one model field is a
CharField that can be populated passing a model instance. This works
fine for create. But if I try to update this record passing the exactly
same dictionary as **kwargs to .update(), Django raises a TypeError
telling me that I cannot update that field because it is a CharField and
I cannot pass model instances.

... so is this a bug, because it works in .create() or must I adapt my
approach?


Thanks a lot for reply.
BR,
Henrik

signature.asc

Matthew Pava

unread,
Nov 13, 2017, 9:22:04 AM11/13/17
to django...@googlegroups.com
Are you saving the string representation of the model instance? I would cast the model instance as a str in that case, i.e. str(instance).
--
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...@googlegroups.com.
To post to this group, send email to django...@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/7012f455-7483-fab4-92c3-4cf943ef1a09%40posteo.de.
For more options, visit https://groups.google.com/d/optout.

Henrik Baran

unread,
Nov 15, 2017, 3:17:17 PM11/15/17
to django...@googlegroups.com
This actual works, however I am still curious about the deviation
between create and update.
Reply all
Reply to author
Forward
0 new messages