title: Is Django post_save triggered before/after saving instance to database?
body: <p>I have a website using Django. Each post is an object called Article. I want to retrieve the post's HTML after saving it so I wrote the following post_save hook:</p>
  
  <pre><code>@receiver(models.signals.post_save, sender=Article)
  def _send_article_mentions(sender, instance, **kwargs):
      import requests
      from django.contrib.sites.models import Site
      from urlparse import urljoin
      from ParallelTransport.settings import ARTICLES_URL
      SITE_URL = 'http://'+Site.objects.get_current().domain
      article_url = urljoin( SITE_URL, instance.get_absolute_url() )
      import time
      time.sleep(20)
      r = requests.get(article_url)
      error_file = open(ARTICLES_URL+'/'+'error.txt','w')
      error_file.write('file started1\n')
  
      m = r.status_code
      error_file.write(str(m))
      error_file.close()
  </code></pre>
  
  <p>It basically waits for 20s (added as a test) then tries to retrieve the HTML of the post using its URL, and writes the request status code to a file for debugging.</p>
  
  <p>The problem is I always get status = 404 on the first save, it does work on 2nd and subsequent saves. I thought the way Django works would be, in order:</p>
  
  <ol>
  <li>save instance to database using save(). At this point the post would get a URL</li>
  <li>send post_save signal</li>
  </ol>
  
  <p>But then I should be able to retrieve the HTML in post_save. Am I understanding post_save incorrectly?</p>
  
  <p>Added notes:</p>
  
  <ol>
  <li>Putting this code in save() method does not work. Nor should it. The post is added to database at the end of the save() method and so should not have any URL until save() ends.</li>
  <li>This is on a production site, not on the development server.</li>
  <li>I want to use the links in the HTML to send 'pingbacks' or actually <a href="http://indiewebcamp.com/webmention" rel="noreferrer">webmention</a>. But all my pingbacks are being rejected because the post does not have a URL yet. This is the bare minimum code that does not work.</li>
  </ol>