1
I am trying to overwrite the save method of models so that when a new book is created it is saved and exported immediately to a file. json, this would be a form of automatic backup, but when registering a new book it exports all the items except the last one registered, but it should export all, someone could give me an example of how to overwrite this method correctly??
def save(self, filename="books", *args, **kwargs):
get = serializers.serialize("json", Books.objects.all())
bkp = open("backup/" + filename + ".json", "w")
bkp.write(get)
super(Books, self).save(*args, **kwargs)
This method is within some class?
– Brumazzi DB
Yes, this is in my model class, the save function referenced above and used to override the pattern used by models.Model.
– dhelbegor