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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:16:29+00:00 2026-05-22T02:16:29+00:00

I am working on a design for some models in Django and wanted to

  • 0

I am working on a design for some models in Django and wanted to get some advice. I have a model for teams, of which many users can be a part of. The users can also be members of many teams, but they cannot be members of the same team twice. There is also separate information I want to track for each team/user combo. On top of that, there will be a user who is an “admin” for each team, but each team may have only a single admin. I have some condensed data model definitions as follows:

class Team(models.Model):
    name = models.CharField()
    members = models.ManyToManyField(User, through='Membership')
    admin = models.ForeignKey(User)

class Membership(models.Model):
    user = models.ForeignKey(User)
    team = models.ForeignKey(Team)
    extra_data = models.CharField()

So I guess my two questions are:

1) how would I make it so that on the Membership model, no user and team combination appeared more than once?

2) Is there a better way to signify an Admin on the team, while making sure that each team only had a single one? It seems like if I’m storing the admin like this, while enforcing the rule of having only a single admin, it becomes too cumbersome to query all team members since the admin will not be in the Membership table. And if they are stored in membership, than I’d have to perform another query to see if they are admin of this team or not. The thought of using an “is_admin” field in Membership popped in my head, but I’m unsure of how to keep the constraints of 1 admin per team.

Any help would be greaty appreciated.

UPDATE:
looks like the unique_together meta tag is what I’m looking for on the first question. I’m still curious about the second one though….

  • 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-22T02:16:30+00:00Added an answer on May 22, 2026 at 2:16 am

    First question:

    You can add a constraint to prevent it:

    class Membership(models.Model):
        user = models.ForeignKey(User)
        team = models.ForeignKey(Team)
        extra_data = models.CharField()
        class Meta:
            unique_together = (('user','team'),)
    

    Second question(s):

    You could add a ranking field to the membership model and make ‘user’ and ‘rank’ unique_together, positive integer field. And user with rank == 1 is the admin. Or similar. It will be enforcing your scheme, but can be cumbersome to code the maintenance of it. You may well be better off with what you’ve got.

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

Sidebar

Related Questions

I'm working with a database with poor design. Most tables do have a PK,
I'm working on a public release if a model using Fortran 9x and I'd
I'm working on a database design for a building monitoring system. It goes a
I'm working on a JSF project on Weblogic 11g, and our initial design is
I'm working on a system in which multiple client objects are expected to implement
I want to make sure I am testing Models/Objects in isolation and not as
I have a webapp written in PHP using a MySQL database backend. This question
I'm working on a poker analysis tool with the following use case: User create
I am trying to self-study both object oriented design and parallel programming using the
I've recently started working on a web app with a new company and found

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.