I need to generate either .odt or .docx files based on the information I have in my database. Let's say I have a model:
class Contact(models.Model):
first_name = models.CharField()
last_name = models.CharField()
email = models.EmailField()
I want that users are able to generate office document that contains that information and also some other text. I took a look for this example which is using python-docx and it gives me an idea how to generate that document. But I can't figure out where this file is saved or is it even created. In my template I have a link:
<a href="{{ contact.generate_docx }}">generate .docx document</a>
where generate_docx()
runs the code which can be found from the link I provided above.
How I can implement my system so that when my link is clicked, then document should be created or updated based on the data in database and after that downloaded to users computer? It's not mandatory to save that document to database but I'm also interested to hear how to do that as well.