Store page slug
This commit is contained in:
parent
4c25b7cd91
commit
67dfd04bbb
5 changed files with 12 additions and 3 deletions
|
@ -4,5 +4,6 @@ class Page(models.Model):
|
||||||
__yamdl__ = True
|
__yamdl__ = True
|
||||||
|
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
|
slug = models.CharField(max_length=128, unique=True, db_index=True)
|
||||||
|
|
||||||
content = models.TextField()
|
content = models.TextField()
|
||||||
|
|
6
yamdl_playground/core/utils.py
Normal file
6
yamdl_playground/core/utils.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from yamdl.loader import ModelLoader
|
||||||
|
|
||||||
|
class CustomYamdlLoader(ModelLoader):
|
||||||
|
def load_fixture(self, model_class, data, file_path):
|
||||||
|
data["slug"] = file_path.stem
|
||||||
|
super().load_fixture(model_class, data, file_path)
|
|
@ -11,7 +11,7 @@ def search(request):
|
||||||
pages = Page.objects.filter(id__in=row)
|
pages = Page.objects.filter(id__in=row)
|
||||||
return HttpResponse(str(pages), content_type="text/plain")
|
return HttpResponse(str(pages), content_type="text/plain")
|
||||||
|
|
||||||
def content(request, id):
|
def content(request, slug):
|
||||||
page = get_object_or_404(Page, id=id)
|
page = get_object_or_404(Page, slug=slug)
|
||||||
|
|
||||||
return HttpResponse(markdown.markdown(page.content), content_type="text/html")
|
return HttpResponse(markdown.markdown(page.content), content_type="text/html")
|
||||||
|
|
|
@ -80,6 +80,8 @@ YAMDL_DIRECTORIES = [
|
||||||
BASE_DIR / "content",
|
BASE_DIR / "content",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
YAMDL_LOADER = "yamdl_playground.core.utils.CustomYamdlLoader"
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
|
|
|
@ -19,5 +19,5 @@ from .core import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("search/", views.search),
|
path("search/", views.search),
|
||||||
path("content/<int:id>/", views.content)
|
path("content/<slug:slug>/", views.content)
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue