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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:26:45+00:00 2026-05-31T18:26:45+00:00

I currently have three classes User , UserProfile , and Vendor . User is

  • 0

I currently have three classes User, UserProfile, and Vendor. User is the built-in Django one from from django.contrib.auth.models import User. The other two are as follow

Here is UserProfile

class UserProfile( models.Model ) :
    TYPE_CHOICES = (
        ( 't', 'tenant'           ),
        ( 'm', 'property manager' ),
        ( 'o', 'property owner'   ),
        ( 'v', 'vendor'           ),
        ( 'w', 'web user'         ),
        ( 'x', 'other'            ),
    )
    user      = models.ForeignKey( User, unique = True )
    user_type = models.CharField( max_length = 1, choices = TYPE_CHOICES, default = 't' )

User.profile = property( lambda u : UserProfile.objects.get_or_create( user = u )[ 0 ] )

And here is Vendor

class Vendor( models.Model ) :
    def __unicode__( self ) :
        return self.name

    name  = models.CharField( max_length = 135 )
    users = models.ManyToManyField( User, null = True, blank = True )

I want to limit the Vendor.users to only User whose UserProfile.user_type is vendor.

How do I use limit_choices_to. Can I do something like…

users = models.ManyToManyField( User, null = True, blank = True, limit_choices_to = { UserProfile.objects.filter( user = self.users ).user_type : 'm' } )

I know the above code will throw an error, but hopefully you can see what I’m trying to do.

Thanks in advance!

  • 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-31T18:26:46+00:00Added an answer on May 31, 2026 at 6:26 pm

    I was able to do it with

    manager = models.ForeignKey( User, related_name = 'manager', limit_choices_to = { 'userprofile__user_type' : 2 } )
    

    where 2 is the primary key (user_type_id) of property manager in the UserType class.

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

Sidebar

Related Questions

I have three classes (domain, role and user). Domain and role are properties of
So I currently have three unordered lists in my header. This is a single-page
I currently have mirroring setup between three computers, principle, mirror, and witness. During the
I have three divs: A, B and C. A is currently visible and I
I have a Visual Studio 2008 solution that's currently consisting of three projects: A
So currently in our code, we have a bunch of classes around accessing roles
I have three classes with common parent. Let's say parent is Animal and children
I'm currently using Eclipse Indigo and I'd like to have my meta-model classes to
I currently have the DatePicker in my project but there are problems due to
I currently have a Ruby on Rails system, and there are plans to port

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.