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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:46:03+00:00 2026-06-15T08:46:03+00:00

I have a couple models using Multi-table Inheritance. like so. class Group(models.Model): title =

  • 0

I have a couple models using Multi-table Inheritance. like so.

class Group(models.Model):  
    title =  models.CharField(unique=True,max_length=255)


class UserGroup(Group):  
   user = models.ForeignKey(User)  
   def save(self, *args, **kwargs):  
       self.title = self.user.username  
       return super(Group, self).save(*args, **kwargs)  

UserGroups need to have unique titles and so do Groups. But It doesn’t matter if an UserGroup has the same title as a Group. Matter a fact this should happen in some cases. How can I do this?

Edit:
What if I used the save method to create an namespace.

class UserGroup(Group):  
   user = models.ForeignKey(User)  
   def save(self, *args, **kwargs):  
       self.title = "user:" + self.user.username  
       return super(UserGroup, self).save(*args, **kwargs) 

class Group(models.Model):  
    title =  models.CharField(unique=True,max_length=255)
    def save(self, *args, **kwargs):  
       self.title = "group:" + self.title
       return super(Group, self).save(*args, **kwargs)  

Would this be a good solution?

  • 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-15T08:46:04+00:00Added an answer on June 15, 2026 at 8:46 am

    What you need is for Group.title and UserGroup.title to be in independent tables. The problem with your design is that in Django multi-table inheritance, child tables are never independent of their parent tables; you will need to make both Group and UserGroup inherit from another model, either concrete or abstract, and then have both children declare a title field.

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

Sidebar

Related Questions

I have a couple of Django models set up like this: class Group(models.model): name
I have the following model: class Ticket(models.Model): title = models.CharField() merged_to = models.ForeignKey(self, related_name='merger_ticket',
Using Django 1.1.1 In models.py: class Site(models.Model): name = models.CharField(max_length=50) class SiteMonth(models.Model): site =
I have a couple of methods I'd like to share between models rather than
I'm using Ruby on Rails. I have a couple of models which fit the
I have read a couple of articles about using new JS frameworks like Backbone.js
In my Backbone application I have a model consisting of a couple of sub-models
I am using Rails and postgres. I have a couple of models using STI
I'm using the as_json method heavily in a couple of models I have in
I have a couple of models in a Rails app. Let's say it's Products

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.