title: Django create .odt or .docx documents to download
body: <p>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:</p>
  
  <pre><code>class Contact(models.Model):
      first_name = models.CharField()
      last_name = models.CharField()
      email = models.EmailField()
  </code></pre>
  
  <p>I want that users are able to generate office document that contains that information and also some other text. I took a look for <a href="https://python-docx.readthedocs.org/en/latest/" rel="nofollow">this example</a> 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:</p>
  
  <pre><code>&lt;a href="{{ contact.generate_docx }}"&gt;generate .docx document&lt;/a&gt;
  </code></pre>
  
  <p>where <code>generate_docx()</code> runs the code which can be found from the link I provided above.</p>
  
  <p><strong>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?</strong> It's not mandatory to save that document to database but I'm also interested to hear how to do that as well.</p>