2👍
If it’s core functionality for saving the model you’ll want it as part of the save method. However, if you already have a functioning model and you want to extend it for other purposes then signals are your best bet since they allow for properly decoupled modules.
A good example might be that you want to add event logging to your site, so you simply listen for the signals that signify an event rather than modifying the original site code.
post_save() is usually best because it means the model has been successfully saved, using pre_save() doesn’t guarantee that the save will be successful so shouldn’t be used for anything that would depend on the save being completed.
0👍
Post save. That way the new data (the reason for performing the serialization) is already in the database. It’ll make for a much cleaner bit of code that simply takes from the database and doesn’t have to worry about adding an extra value.
The other way that comes to mind is to maintain the xml file in parallel to the database. That is to say, in your save() add the data to the database, and to the xml file. This would have a much less overhead if you’re dealing with huge tables.
- [Answered ]-Django Rest Framework: How to get value of the ForeignKey
- [Answered ]-How to iterate over json object in python containing dictionary and list
- [Answered ]-Help on my django models for my shoe review website