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 8734039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:45:56+00:00 2026-06-13T09:45:56+00:00

In a model I usually put a uuid field for friendly URI, also a

  • 0

In a model I usually put a “uuid” field for friendly URI, also a “slug” field.

Say I have a model named “SomeModel”, by overriding its save() method, I can generate a uuid and a slug when it’s being saved:

class SomeModel(models.Model):
    ...
    def save(self, *args, **kwargs):
        if not self.uuid:
            uuid = shortuuid.uuid()[:10]
            while SomeModel.objects.filter(uuid=uuid).exists():
                uuid = shortuuid.uuid()[:10]
            self.uuid = uuid
        if not self.slug:
            self.slug = slugify(self.title)[:500].rstrip('-')
        super(SomeModel, self).save(*args, **kwargs)

It works well on regular model. Now I’d like to have an abstract model:

class SomeAbstractModel(models.Model):
    class Meta:
        abstract = True
    def save(self, *args, **kwargs):
        ...

And then:

class SomeModel(SomeAbstractModel):
    class Meta(SomeAbstractModel.Meta):
        ...

The problem is, in the abstract model, looks like I cannot just simply replace

while SomeModel.objects.filter(uuid=uuid).exists():

with

while SomeAbstractModel.objects.filter(uuid=uuid).exists():

because abstract model doesn’t have a manager.

I was wondering in this case, how can I avoid having redundant code in all models’ save() methods. Also I’m not sure if

while SomeModel.objects.filter(uuid=uuid).exists():

is the best practice to check if an uuid exists or not.

  • 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-06-13T09:45:57+00:00Added an answer on June 13, 2026 at 9:45 am

    Not sure if it is the prettiest way in town but this should work:

    while self.__class__.objects.filter(...):
        pass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying the model-first method when designing my application. We usually like
I usually tend to define the model layer of my apps using POJO's, such
In my applications I always end up implementing a Model-View-Presenter pattern and usually end
I have an app with an Account model. Each Account belongs_to a sport, which
I have the following model: from django.db import models import datetime class Club(models.Model): establishment
I have just been thinking about the concept of view model object we create
So the branching model I usually use is similar to the following: http://nvie.com/posts/a-successful-git-branching-model/ However,
Say I have a route setup: 'photos/:id' : 'showPhoto' and somebody shares the url:
I usually create a solution folder in Visual Studio and put my DB scripts
I have been developing enterprise applications for many years using .Net My apps usually

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.