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

The Archive Base Latest Questions

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

I am trying to perform the custom filters in Django Admin but it seems

  • 0

I am trying to perform the custom filters in Django Admin but it seems that when i filter based on parent and teacher in my case, i tend to get repeated values. Meaning to say that the number of parents(481) is more than the total number(221). Some of the values get repeated.. How do i avoid this? Any idea?

admin.py:

class AdultRoleListFilter(SimpleListFilter):

    title = _('Role of Adult')
    parameter_name = 'adultrole'
    def lookups(self, request, model_admin):
        return (
            ('T', _('Teacher')),
            ('P', _('Parent')),)
    def queryset(self, request, queryset):
        if self.value() == 'P':
            return queryset.filter(relationships__role='P')
        if self.value() == 'T':
            return queryset.filter(relationships__role='T')

Models.py

class Student(models.Model):
   name = models.CharField(max_length=255)
   birthday= models.DateField(blank=True,null=True)

class Adult(models.Model):
   user = models.OneToOneField(User)
   students = models.ManyToManyField(Student, through='StudentAdultRelationship', related_name='adults')

class class StudentAdultRelationship(models.Model):

    PARENT = 'P'
    TEACHER ='T'
    FOLLOWER = 'F'

    ROLE_CHOICES = (
        (PARENT, 'Parent'),
        (TEACHER, 'Teacher'),
        (FOLLOWER, 'Follower'),
    )

    adult = models.ForeignKey(Adult, related_name='relationships')
    student = models.ForeignKey(Student, related_name='relationships')
    role = models.CharField(choices=ROLE_CHOICES, max_length=1)

Need some guidance on 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-10T06:49:33+00:00Added an answer on June 10, 2026 at 6:49 am

    Multiple relationships must exist for the same student; say a Student with 3 adults of role P would return 3 students; you must add a distinct() call to your QuerySet to ensure unique students.

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

Sidebar

Related Questions

I am trying to perform some custom validation with play framework but I don't
I'm trying to implement a custom filter template for all text based searches and
I'm trying to write a custom filter for Dynamic data that will allow me
Context: I am trying to perform a custom animation from a normal UIViewController.view to
I am trying to use a custom segue to perform a kind of zoom
I'm trying to write a custom Rake task to perform some tests for a
I'm trying to use a custom ClaimsAuthorizationManager based on the excellent work from Dominic
I'm trying to perform a custom animation on an Activity transition. The activity is
I have several links I'm trying to create to either perform custom controller methods
I'm trying to make a custom segue so that the destination view controller slides

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.