Indradhanush Gupta
Indradhanush Gupta

Reputation: 4237

How to do an append to an existing field in a Django Model?

I have a model :

class Info(models.Model):
    m_id = models.IntegerField()
    message = models.CharField(max_length=500)

I want to be able to append data to message field. That is say for m_id = 1 message = 'Hello' exists.

I want do a query that will add 'World' to message thus making it 'Hello World'

How can I do this?

Upvotes: 2

Views: 2592

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798536

Modify, then save.

someinfo.message += ' World'
someinfo.save()

Upvotes: 7

Related Questions