is there a way to get the same results of using pre-populated fields in django's admin site for slug fields in a standard modelform
Well django is open source, so if you want to replicate certain behaviour you can read the code and pick and chose what you like. For instance, you can see that contrib.admin uses a script called urlify.js to do the dynamic slugging, with usage something like this:
<script type="text/javascript" src="/admin-media/js/urlify.js"></script>
<script type="text/javascript">
document.getElementById("id_title").onkeyup = function() {
var e = document.getElementById("id_slug");
if (!e._changed) { e.value = URLify(document.getElementById("id_title").value, 50); }
}
</script>
... depending of course on where your admin media is served from (mine is from "/admin-media/")
Or if you're happy to do your slugifying in your view, you can use the function that's used in django.template as the slugify filter: django.template.defaultfilters.slugify.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With