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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:27:14+00:00 2026-06-08T15:27:14+00:00

I need to have a view with users that havn’t got any group. I

  • 0

I need to have a view with users that havn’t got any group. I have tried to make a query with .except but it has failed because of manytomany fields…

My models :

class UserProfile(models.Model):
    user = models.OneToOneField(User, unique=True)
    courses_list = models.ManyToManyField('Course', blank=True)
    group_list = models.ManyToManyField('Group', blank=True)

class Group(models.Model):
    name = models.CharField(max_length=30)
    assignment = models.ForeignKey(Assignment)
    members = models.ManyToManyField(UserProfile, through=UserProfile.group_list.through, blank=True)

class Assignment (models.Model):
    course = models.ForeignKey(Course)

class Course(models.Model):
    subscribed = models.ManyToManyField(UserProfile, through= UserProfile.courses_list.through, blank=True)

So, I need to select users subscribed to the assignment (assignment.course.subscribed.all send all) that haven’t got any group (the problem is that I need to take care of groups linked to this assignment only)

I have tried groupless = detailedassignment.course.subscribed.exclude(username = group_list.filter(assignment=detailedassignment).members.username.all()) but it doesn’t work at all (and i think it is normal when I see the code..)

Edit :

I have removed relations in a way, now my models are :

My models :

class UserProfile(models.Model):
    user = models.OneToOneField(User, unique=True)

class Group(models.Model):
    name = models.CharField(max_length=30)
    assignment = models.ForeignKey(Assignment)
    members = models.ManyToManyField(UserProfile, blank=True)

class Assignment (models.Model):
    course = models.ForeignKey(Course)

class Course(models.Model):
    subscribed = models.ManyToManyField(UserProfile, blank=True)

I have tried to use :

groupless = detailedassignment.course.subscribed.exclude(user__username__in = Group.objects.filter(assignment=detailedassignment).members.objects.values_list('user__username'))

But I have 'QuerySet' object has no attribute 'members'

  • 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-08T15:27:15+00:00Added an answer on June 8, 2026 at 3:27 pm

    You’re forgetting the user reference. So if I interpret you properly, you want something like –

    groupless = detailedassignment.course.subscribed.exclude(user__username__in = group_list.filter(assignment=detailedassignment).members.objects.values_list('user__username'))
    

    OR try this –

    groupless = UserProfile.objects.filter(courses_list__assignment = detailedassignment).exclude(group_list__assignment=detailedassignment)
    

    Also as an aside, your model design looks somewhat skewed, with same references running across each other. And there’s no need to add backward references (like in model `Course). Django gives you the functionality for backward referencing. See https://docs.djangoproject.com/en/dev/topics/db/queries/#following-relationships-backward

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

Sidebar

Related Questions

I have a list view control that users can add items to but I
I have a view that changes if users scrolls it. I need something to
In a certain view I have got different elements and I need the keyboard
So I have a view that allows users to Approve or Reject items listed
I have a view that returns users projects and also their windows login. An
I have a view controller that allows users to add an nsstring to an
I have a view that enables users to edit their profiles (usual name, username
I have a view with a huge paginated list of records that need filtering.
I have a simple table view which is editable. All I need the user
I need to have a new view(w/ ViewController) added over the top of another.

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.