[Answered ]-Django: How can i set the name field of a newly created record based on autoincrement id?

2👍

You would need to overwrite the Model’s save method like that:

class YourModel(model):
    ....
    def save(self,*args,**kwargs):
        if not self.id:
            update_name=True
        else:
            update_name=False
        super(YourModel,self).save(*args,**kwargs)
        if update_name:
            self.name='whatever %s' %self.id
            super(YourModel,self).save(*args,**kwargs)

Leave a comment