I have a Django model that uses a JsonField field.
At some point, I update the field with the IP address and save this field:
class Agent(models.Model): properties = jsonfield.JSONField(default = {}) def save_ip_address(self, ip_address): self.properties['ip'] = ip_address self.save()
Looks pretty straight forward. is not it?
But the field was not saved using the ip dictionary element ... and I have no idea why!
I made a workaround that works, but doesn't look good in my code:
d = self.properties d['ip'] = ip_address self.properties = d self.save()
Thus, JsonField is really stored in the database with an IP address.
Does anyone know why the first approach did not work? and what should I do to fix this?
Thanks!
source share