Home>

I'm making an Instagram story in Django.
I can delete the posted text, but
In addition, I would like to add a function that automatically deletes posts after 6 hours.
I want to delete it from the database, so I want to implement it in Django instead of Js.

Current code

views.py
@require_POST
def delete_itch (request, writing_id):
    detail = get_object_or_404 (writing, id = writing_id)
    detail.delete ()
    return redirect ('top: index')
models.py
class writing (models.Model):
    write = models.CharField (max_length = 100)
    created_at = models.DateTimeField (auto_now = True)
    def __str __ (self):
        return self.write
template
{% for detail in works%}

  
    {{detail}}
  

<form method = "post" action = "{% url 'top: delete_itch' detail.pk%}">{% csrf_token%}
  <button type = "submit">Delete</button>
</form>
<hr>
{% endfor%}
  • Answer # 1

    I think using cron is simpler and easier than using Django alone.
    If you search for "Dnago cron", you will see many things.