prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Change order of the blog posts
  Currently all blog posts that are published on grand-challenge are sorted based on the date the post was initially created. We would like to change this to the date the post was published such that the most recent post are shown on top. I had contact with @jmsmkn on slack after which he suggested a few changes I could make in the code to change this. After discussing this with Kiran we thought it might be best to first create an issue here. 
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `app/grandchallenge/blogs/models.py`
  Content:
  ```
  1 from django.conf import settings
  2 from django.contrib.auth import get_user_model
  3 from django.db import models
  4 from django_extensions.db.fields import AutoSlugField
  5 from simple_history.models import HistoricalRecords
  6 from stdimage import JPEGField
  7 
  8 from grandchallenge.core.storage import get_logo_path, public_s3_storage
  9 from grandchallenge.subdomains.utils import reverse
  10 
  11 
  12 class Tag(models.Model):
  13     name = models.CharField(max_length=200, unique=True)
  14     slug = AutoSlugField(populate_from="name", max_length=200)
  15 
  16     def __str__(self):
  17         return self.name
  18 
  19 
  20 class Post(models.Model):
  21     created = models.DateTimeField(auto_now_add=True)
  22     modified = models.DateTimeField(auto_now=True)
  23 
  24     title = models.CharField(max_length=1024)
  25     slug = AutoSlugField(populate_from="title", max_length=1024)
  26     description = models.TextField()
  27     content = models.TextField()
  28 
  29     authors = models.ManyToManyField(
  30         to=get_user_model(), related_name="blog_authors"
  31     )
  32 
  33     logo = JPEGField(
  34         upload_to=get_logo_path,
  35         storage=public_s3_storage,
  36         variations=settings.STDIMAGE_SOCIAL_VARIATIONS,
  37     )
  38 
  39     tags = models.ManyToManyField(to=Tag, blank=True, related_name="posts")
  40 
  41     published = models.BooleanField(default=False)
  42 
  43     history = HistoricalRecords()
  44 
  45     class Meta:
  46         ordering = ("-created",)
  47 
  48     def __str__(self):
  49         return self.title
  50 
  51     def get_absolute_url(self):
  52         return reverse("blogs:detail", kwargs={"slug": self.slug})
  53 
  54     @property
  55     def public(self):
  56         return self.published
  57
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/app/grandchallenge/blogs/models.py b/app/grandchallenge/blogs/models.py
  --- a/app/grandchallenge/blogs/models.py
  +++ b/app/grandchallenge/blogs/models.py
  @@ -1,6 +1,7 @@
   from django.conf import settings
   from django.contrib.auth import get_user_model
   from django.db import models
  +from django.utils import timezone
   from django_extensions.db.fields import AutoSlugField
   from simple_history.models import HistoricalRecords
   from stdimage import JPEGField
  @@ -48,6 +49,16 @@
       def __str__(self):
           return self.title
   
  +    def __init__(self, *args, **kwargs):
  +        super().__init__(*args, **kwargs)
  +        self._published_orig = self.published
  +
  +    def save(self, *args, **kwargs):
  +        if self._published_orig is False and self.published is True:
  +            self.created = timezone.now()
  +
  +        super().save(*args, **kwargs)
  +
       def get_absolute_url(self):
           return reverse("blogs:detail", kwargs={"slug": self.slug})
  
verification_info: {"golden_diff": "diff --git a/app/grandchallenge/blogs/models.py b/app/grandchallenge/blogs/models.py\n--- a/app/grandchallenge/blogs/models.py\n+++ b/app/grandchallenge/blogs/models.py\n@@ -1,6 +1,7 @@\n from django.conf import settings\n from django.contrib.auth import get_user_model\n from django.db import models\n+from django.utils import timezone\n from django_extensions.db.fields import AutoSlugField\n from simple_history.models import HistoricalRecords\n from stdimage import JPEGField\n@@ -48,6 +49,16 @@\n     def __str__(self):\n         return self.title\n \n+    def __init__(self, *args, **kwargs):\n+        super().__init__(*args, **kwargs)\n+        self._published_orig = self.published\n+\n+    def save(self, *args, **kwargs):\n+        if self._published_orig is False and self.published is True:\n+            self.created = timezone.now()\n+\n+        super().save(*args, **kwargs)\n+\n     def get_absolute_url(self):\n         return reverse(\"blogs:detail\", kwargs={\"slug\": self.slug})\n", "issue": "Change order of the blog posts\nCurrently all blog posts that are published on grand-challenge are sorted based on the date the post was initially created. We would like to change this to the date the post was published such that the most recent post are shown on top. I had contact with @jmsmkn on slack after which he suggested a few changes I could make in the code to change this. After discussing this with Kiran we thought it might be best to first create an issue here. \r\n\n", "before_files": [{"content": "from django.conf import settings\nfrom django.contrib.auth import get_user_model\nfrom django.db import models\nfrom django_extensions.db.fields import AutoSlugField\nfrom simple_history.models import HistoricalRecords\nfrom stdimage import JPEGField\n\nfrom grandchallenge.core.storage import get_logo_path, public_s3_storage\nfrom grandchallenge.subdomains.utils import reverse\n\n\nclass Tag(models.Model):\n    name = models.CharField(max_length=200, unique=True)\n    slug = AutoSlugField(populate_from=\"name\", max_length=200)\n\n    def __str__(self):\n        return self.name\n\n\nclass Post(models.Model):\n    created = models.DateTimeField(auto_now_add=True)\n    modified = models.DateTimeField(auto_now=True)\n\n    title = models.CharField(max_length=1024)\n    slug = AutoSlugField(populate_from=\"title\", max_length=1024)\n    description = models.TextField()\n    content = models.TextField()\n\n    authors = models.ManyToManyField(\n        to=get_user_model(), related_name=\"blog_authors\"\n    )\n\n    logo = JPEGField(\n        upload_to=get_logo_path,\n        storage=public_s3_storage,\n        variations=settings.STDIMAGE_SOCIAL_VARIATIONS,\n    )\n\n    tags = models.ManyToManyField(to=Tag, blank=True, related_name=\"posts\")\n\n    published = models.BooleanField(default=False)\n\n    history = HistoricalRecords()\n\n    class Meta:\n        ordering = (\"-created\",)\n\n    def __str__(self):\n        return self.title\n\n    def get_absolute_url(self):\n        return reverse(\"blogs:detail\", kwargs={\"slug\": self.slug})\n\n    @property\n    def public(self):\n        return self.published\n", "path": "app/grandchallenge/blogs/models.py"}], "after_files": [{"content": "from django.conf import settings\nfrom django.contrib.auth import get_user_model\nfrom django.db import models\nfrom django.utils import timezone\nfrom django_extensions.db.fields import AutoSlugField\nfrom simple_history.models import HistoricalRecords\nfrom stdimage import JPEGField\n\nfrom grandchallenge.core.storage import get_logo_path, public_s3_storage\nfrom grandchallenge.subdomains.utils import reverse\n\n\nclass Tag(models.Model):\n    name = models.CharField(max_length=200, unique=True)\n    slug = AutoSlugField(populate_from=\"name\", max_length=200)\n\n    def __str__(self):\n        return self.name\n\n\nclass Post(models.Model):\n    created = models.DateTimeField(auto_now_add=True)\n    modified = models.DateTimeField(auto_now=True)\n\n    title = models.CharField(max_length=1024)\n    slug = AutoSlugField(populate_from=\"title\", max_length=1024)\n    description = models.TextField()\n    content = models.TextField()\n\n    authors = models.ManyToManyField(\n        to=get_user_model(), related_name=\"blog_authors\"\n    )\n\n    logo = JPEGField(\n        upload_to=get_logo_path,\n        storage=public_s3_storage,\n        variations=settings.STDIMAGE_SOCIAL_VARIATIONS,\n    )\n\n    tags = models.ManyToManyField(to=Tag, blank=True, related_name=\"posts\")\n\n    published = models.BooleanField(default=False)\n\n    history = HistoricalRecords()\n\n    class Meta:\n        ordering = (\"-created\",)\n\n    def __str__(self):\n        return self.title\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self._published_orig = self.published\n\n    def save(self, *args, **kwargs):\n        if self._published_orig is False and self.published is True:\n            self.created = timezone.now()\n\n        super().save(*args, **kwargs)\n\n    def get_absolute_url(self):\n        return reverse(\"blogs:detail\", kwargs={\"slug\": self.slug})\n\n    @property\n    def public(self):\n        return self.published\n", "path": "app/grandchallenge/blogs/models.py"}]}