Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 895611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:35:10+00:00 2026-05-15T14:35:10+00:00

I added a slug field to my database and now need to go through

  • 0

I added a slug field to my database and now need to go through and add those. I want to run a script that looks at the slug field in the database and if empty generates and saves. Here is what I thought was along the lines, but is not working.

from project.apps.tracks.models import *

def process_slug():  
    if not track.slug:  
        slug = slugify("%s - %s" % (track.name, track.artist)) 
    else:  
        slug = "" 

    super(process_slug, track).save()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:35:11+00:00Added an answer on May 15, 2026 at 2:35 pm

    From your posted code it is not evident, that you are actually looping through all your Track objects.

    from project.apps.tracks.models import Track
    # import for slugify
    
    def process_slug():
        """ Populate slug field, if they are empty. 
        """
        for track in Track.objects.all():
            if not track.slug:  
                slug = slugify("%s - %s" % (track.name, track.artist)) 
                track.slug = slug
                track.save()
    

    One preferred place for such occasionally recurring commands would be under management/commands inside your application.


    Another way to implement would be to override your Track model’s save method. It would check for emtpy slugs on every save (which is not performant).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently added slug fields to my MySQL database models (I don't know why
I added my Python script to the scripts folder of Blender (which were hidden)
I added a custom form to my opportunity entity so now I have the
I added a custom install action to my installer to add one of my
I added some simple WatiN tests to our app today to check that a
I added a text file to a testapp's solution and I want to read
I have a set of document objects and label objects, and I want those
I need to have dynamic routes with symfony 2 where a slug parameter is
Just trying out Mongoid at the moment, I've run into an issue that's probably
EDIT: I have added Slug column to address performance issues on specific record selection.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.