Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's not immediately available, but you can make your own system quite easily my overriding the <code>save()</code> method in your model. Eg.</p> <pre><code>def save(self, *args, **kwargs): # If there is not already a slug in place... if not self.[name-of-slug-field]: # Import django's builtin slug function from django.template.defaultfilters import slugify # Call this slug function on the field you want the slug to be made of self.[name-of-slug-field] = slugify(self.[field-to-slugify]) # Call the rest of the old save() method super([model-name], self).save(*args, **kwargs) </code></pre> <p>You'd need to change the things in square brackets to make them relevant to your model.</p> <p><code>[name-of-slug-field]</code> is the field in your model which holds the actual slug (eg. 'this-is-slugged')</p> <p><code>[field-to-slugify]</code> is the field you want to build the slug from (in your case, it will probably be <code>title</code>)</p> <p><code>[model-name]</code> is the name of the model that this method is in</p> <p>The last line of that code is the only potentially complicated bit I think, it just adds the remainder of the old <code>save()</code> method in its place so when you call <code>save()</code> it still physically commits the changes to the database.</p> <p>Obviously these changes will only be made server-side, so the user won't 'see' them happening, so if you want to emulate how the Django admin panel works exactly (ie. the slug automatically appears in the textbox for slug), you would need to incorporate mazelife's Ajax code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload