order thinks on the front page by time of last edit

instead of time of creation
This commit is contained in:
Christian Lawson-Perfect 2025-05-04 08:22:31 +01:00
parent dcdb3d87be
commit 94643dc2c7
5 changed files with 37 additions and 4 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 5.0.3 on 2025-04-26 07:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('thinks', '0004_think_creation_time'),
]
operations = [
migrations.AddField(
model_name='think',
name='last_edited',
field=models.DateTimeField(blank=True, null=True),
),
]

View file

@ -13,6 +13,7 @@ class Think(models.Model):
slug = models.SlugField() slug = models.SlugField()
category = models.CharField(max_length=100, blank=True, null=True) category = models.CharField(max_length=100, blank=True, null=True)
creation_time = models.DateTimeField(auto_now_add=True) creation_time = models.DateTimeField(auto_now_add=True)
last_edited = models.DateTimeField(blank=True, null=True)
is_template = models.BooleanField(default=False) is_template = models.BooleanField(default=False)

View file

@ -33,7 +33,8 @@ body {
display: grid; display: grid;
grid-template-rows: auto 1fr; grid-template-rows: auto 1fr;
min-height: 100vh; min-height: 100svh;
max-height: 100svh;
margin: 0; margin: 0;
padding: var(--half-spacing); padding: var(--half-spacing);
@ -128,8 +129,8 @@ input[type="file"] {
overflow: hidden; overflow: hidden;
--col-1-width: auto; --col-1-width: auto;
grid-template: grid-template:
"nav editor preview" min-content "nav editor preview" 1fr
"log editor preview" 1fr "log log log" min-content
/ var(--col-1-width) var(--editor-size) var(--preview-size) / var(--col-1-width) var(--editor-size) var(--preview-size)
; ;

View file

@ -0,0 +1,9 @@
<html>
<body>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{form}}
<button type="submit">Submit</button>
</form>
</body>
</html>

View file

@ -4,6 +4,7 @@ from django.http import HttpResponse, JsonResponse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.views import generic from django.views import generic
from django.urls import reverse from django.urls import reverse
from django.utils.timezone import now
from itertools import groupby from itertools import groupby
import json import json
import mimetypes import mimetypes
@ -41,7 +42,7 @@ class IndexView(ThinkMixin, generic.ListView):
context['templates'] = Think.objects.filter(is_template=True) context['templates'] = Think.objects.filter(is_template=True)
context['recent_thinks'] = Think.objects.filter(is_template=False).order_by('-creation_time')[:3] context['recent_thinks'] = Think.objects.all().order_by('-last_edited', '-creation_time')[:3]
context['thinks'] = sorted(Think.objects.filter(is_template=False), key=lambda t: (t.category if t.category else '', -t.creation_time.timestamp())) context['thinks'] = sorted(Think.objects.filter(is_template=False), key=lambda t: (t.category if t.category else '', -t.creation_time.timestamp()))
@ -100,6 +101,9 @@ class ThinkView(ThinkMixin, generic.DetailView):
think = self.object think = self.object
think.last_edited = now()
think.save(update_fields=('last_edited',))
root = think.root root = think.root
strpath = self.request.GET.get('path') strpath = self.request.GET.get('path')