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

  • Home
  • SEARCH
  • 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 8922391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:49:16+00:00 2026-06-15T06:49:16+00:00

I have two models, Group, and List Item. List Items belong inside Groups: class

  • 0

I have two models, Group, and List Item. List Items belong inside Groups:

class List_Item(models.Model):
    name = models.CharField("List Item Name", max_length=200, unique = True)
    group = models.ForeignKey(Group, verbose_name="Group")

    creation_date = models.DateTimeField("Creation Date", default=datetime.now)
    notes = models.TextField("Notes", blank=True)

    user = models.ForeignKey(User, editable=False)

    def __unicode__(self):
        return self.name

class Group(models.Model):
    name = models.CharField("Group Name", max_length=200, unique = True)
    notes = models.TextField("Notes", blank=True)

    user = models.ForeignKey(User, editable=False)

    def __unicode__(self):
        return self.name

In my forms for List Items, a ModelForm has a dropdown for Groups. Currently, it lists all Groups, regardless of which user a Group belongs to. But I want to only display Groups that belong to the user logged in. How might I do this?

  • 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-15T06:49:17+00:00Added an answer on June 15, 2026 at 6:49 am

    You would have to override the form field inside the init method. You could pass the logged in user to the form from the view and filter based on it

    #form
    class ListItemform(forms.ModelForm):
        def __init__(self, *args, ** kwargs):
                self.user = kwargs.pop('user', None)
                super(ListItemform, self).__init__(*args, **kwargs)
                self.fields['group'].queryset = Group.objects.filter(user = self.user)
    #view
    def displayform(request):
        user = request.user
        form = ListItemForm(user = user)
        return ...
    
    • 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 separate apps: # Groups app class Group(models.Model): name =
I have two models: class Contact(models.Model): name = models.CharField(max_length=255) class Campaign(models.Model): contact = models.ForeignKey(Contact,
I have two models class Employer(models.Model): name = models.CharField(max_length=300, blank=False) id = models.IntegerField() status
I have two models: class Source(models.Model): name = models.CharField(max_length=200) class Data(models.Model): date = models.DateField(db_index=True)
I have the following models: # Group for Key/Value pairs class Group(models.Model): name =
i have these two models public class Group { [Key] public int GroupID {
I have two models like this: class ClassA(models.Model): ida = models.AutoField(primary_key=True) classb = models.ForeignKey(ClassB)
I have two models, one is Group, the other Item. A group has many
I have two models, Users and Groups. Each group can have many users and
I have two models: class Group < ActiveRecord::Base belongs_to :sites end class Site <

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.