diff --git a/fet2020/posts/static/js/auto_slug.js b/fet2020/posts/static/js/auto_slug.js index 7b799749..a2187feb 100644 --- a/fet2020/posts/static/js/auto_slug.js +++ b/fet2020/posts/static/js/auto_slug.js @@ -1,5 +1,7 @@ window.addEventListener("load", function() { (function($) { + var slug = $("input#id_slug").val(); + $("input#id_title").on('input', function() { var title = $("input#id_title").val(); @@ -10,7 +12,7 @@ window.addEventListener("load", function() { getUrl = window.location baseUrl = getUrl.protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[0]; - $.ajax({type:'GET', url: baseUrl + 'posts/func/slug_calc', data:{'title': title }, complete:complete}); + $.ajax({type:'GET', url: baseUrl + 'posts/func/slug_calc', data:{'title': title, 'slug': slug }, complete:complete}); }); })(django.jQuery); }); diff --git a/fet2020/posts/views.py b/fet2020/posts/views.py index a3f85339..e3880739 100644 --- a/fet2020/posts/views.py +++ b/fet2020/posts/views.py @@ -146,11 +146,13 @@ def slug_calc(request): if request.method == "GET": get = request.GET.copy() title = get["title"] + slug_str = get["slug"] - datetime_now = timezone.now() - date_str = datetime_now.strftime("%Y-%m-%d") + if not slug_str: + datetime_now = timezone.now() + date_str = datetime_now.strftime("%Y-%m-%d") - slug_str = slugify(date_str) + "-" + slugify(title) + slug_str = slugify(date_str) + "-" + slugify(title) return HttpResponse(slug_str)