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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:31:44+00:00 2026-06-09T17:31:44+00:00

I need to make a request on the model himself : class Course(models.Model): owner

  • 0

I need to make a request on the model himself :

class Course(models.Model):
    owner = models.ForeignKey(User, related_name='course', limit_choices_to={'userprofile__status': 'teacher'})

class Assignment (models.Model):
    course = models.ForeignKey(Course, related_name='assignment')
    admins = models.ManyToManyField(User, blank=True, null=True, limit_choices_to={'userprofile__status': 'teacher'})

I need admin contain all users (with teacher as status) without the owner. I have tried with Q objects but it was not a success…

  • 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-09T17:31:45+00:00Added an answer on June 9, 2026 at 5:31 pm

    I’m not sure if you can do this right on the model, but if you could it would be done with F. Something like:

    from django.db.models import Q, F
    
    ...
    
    limit_choices_to=Q(userprofile__status='teacher') & ~Q(id=F('owner_id'))
    

    You have to use Q because you can’t assert a negative with the dictionary pattern. The ~ negates the second Q and F('owner_id') is use to select the value for owner.

    Like I said, though, I haven’t tried to do this myself, so I can’t say if it will work or not. You’ll just have to give it a whirl and let us know.

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

Sidebar

Related Questions

I need to make special request to database through django. For example: class Model(models.Model):
I'm not familiar with Java but I need to make a request to a
I need to make a cURL request to a https URL, but I have
I Need to make a webpage. asp.net this webpage recieve parameter by using Request.Querystring
I need to set time out for the Http Request we make to a
In the save() method on a model, I need to execute a request for
Since I embeded fetch request in my model.xcdatamodeld, I need an instance of NSManagedObjectModel
I have a model form that I use to update a model. class Turtle(models.Model):
Hi I have a model containing: class MyModel(models.Model): id = models.IntegerField(primary_key=True) recorded_on = models.DateField()
Let's say I have two models, Book and Page: class Book(models.Model): pass class Page(models.Model):

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.