Currently working on a project that does not have a slug field, and this value is created in the template using:
{{ n.title|slugify }}
I need to incorporate the slug into a jQuery function, but the variable always remains empty:
$("select#model").click(function() {
var u = $(this).find(":selected").val();
var slg = $(this).find(":selected").text();
var slug = "{{ slg|slugify }}";
window.location.href("link that is created with u and slug);
});
Is there any way to use Django template tags within JavaScript?
Edit:
I have a queryset:
Model.objects.all()
How can I manually add a field to this queryset?