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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:53:51+00:00 2026-06-03T13:53:51+00:00

I have have a many-to-many relation in a Django(1.4) model. class UserProfile(models.Model): foos =

  • 0

I have have a many-to-many relation in a Django(1.4) model.

class UserProfile(models.Model):
    foos = models.ManyToManyField(Foo)

I want to enforce that each User(Profile) has at least one Foo. Foos can have zero-or-more User(Profiles)s.

I would love this to be enforced at the model and admin levels, but just enforcing it in the admin would be sufficient.

If I understand correctly, ‘many’ in Django-speak is zero-or-more.

I want a ManyToOneOrMore relation. How can I do this?

Thanks,

Chris.

  • 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-03T13:53:52+00:00Added an answer on June 3, 2026 at 1:53 pm

    You can’t enforce this on at the model level as @Greg details, but you can enforce it on a form by simply making the field required. This won’t prevent anyone with shell-level access from manually creating a UserProfile without a foo, but it will force anyone using a browser-based form method of creation.

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

Sidebar

Related Questions

I have two models in relation one-to-many: class Question(db.Model): questionText = db.StringProperty(multiline=False) class Answer(db.Model):
I have a simple one-to-many (models.ForeignKey) relationship between two of my model classes: class
I am learning django admin, i have to models with a one-to-many relation between
i have an entity Entity1 that have one to many relation with Entity2 as
I have a simple SQL relational model with a many to many relation. Here
I have 3 tables: Book, Section and Content. I want to add many-to-many relation
my situation is that i have one to many relation ,like order and orderdetails
I have a product table that has a many-to-many relation to itself (using a
I have a model book with a one to many relation with authors. I
I have 2 models which have a has_and_belongs_to_many relation: class Category < ActiveRecord::Base has_and_belongs_to_many

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.