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

  • Home
  • SEARCH
  • 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 7026033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:03:49+00:00 2026-05-28T00:03:49+00:00

I recently added slug fields to my MySQL database models (I don’t know why

  • 0

I recently added slug fields to my MySQL database models (I don’t know why it didn’t occur to me to do this earlier). Now I have a bunch of blank slug fields in my database. I included a save definition in each model

class test(models.Model):
    q = models.CharField(max_length=30)
    s = models.SlugField()

    def save(self, *args, **kwargs):
        self.s = slugify(self.q)
        super(test, self).save(*args, **kwargs)

Now I want to write something to populate each record in my models. Any suggestions on what code I can write to perhaps have it cycle through all my models/records and populate the slugs?

An additional complication (though I’m not sure I care a ton about this). I have a field in each model:

last_modified = models.DateTimeField("Last Modified", auto_now=True)

I’d rather not trigger this because the records aren’t really being modified. Can I populate the slugs without updating the last_modified fields?

  • 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-28T00:03:50+00:00Added an answer on May 28, 2026 at 12:03 am

    Well if it isn’t a lot of data, and it is just a one off thing, just do it in the shell:

    $ python manage.py shell
    >>> from my_app.models import Test
    >>> for obj in Test.objects.all():
    >>>     obj.save()
    

    If you are going to do this a lot, write a custom management command that does this.

    As for your auto_now issue, this is the reason I’ve stopped using auto_now and auto_now_add. Every time I’ve used them, I’ve always ripped them out later. In fact, the Django developers have said they consider them deprecated and they probably will be removed in the future. I’d just edit the source code and remove that option before running your command, then either add it back in or replace it with custom save() logic.

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

Sidebar

Related Questions

I recently added a new column to a MySQL database (featured), then added that
I have recently added OpenID login to my website. But I don't know how
I've recently added a couple of fields to some tables in my database (SQL
I've recently added Microsoft Unity to my MVC3 project and now I'm getting this
I have recently added a new column (age) to a database table (user). I
I recently added a new project to my Visual Studio 2008 solution. Now, as
We recently added a feature to our software that requires .NET 2.0 SP2. This
We recently added auditing to our database. A colleague implemented it using triggers and
I've recently added this little bit of code to my .htaccess file: RewriteCond %{REQUEST_FILENAME}
I recently added some SQL functions to my database via a migrate, and they

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.