# How to create a filter of any related object (ForeignKey field) in Add or Edit page in Admin Site

**URL:** <https://forum.djangoproject.com/t/how-to-create-a-filter-of-any-related-object-foreignkey-field-in-add-or-edit-page-in-admin-site/4001>\
**Category:** Using Django\
**Created:** [August 21, 2020, 6:16am UTC](https://forum.djangoproject.com/t/how-to-create-a-filter-of-any-related-object-foreignkey-field-in-add-or-edit-page-in-admin-site/4001 "2020-08-21T06:16:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![technqvi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/technqvi/32/1851_2.png) [@technqvi](https://forum.djangoproject.com/u/technqvi)\
**Post date:** [August 21, 2020, 6:16am UTC](https://forum.djangoproject.com/t/how-to-create-a-filter-of-any-related-object-foreignkey-field-in-add-or-edit-page-in-admin-site/4001/1 "2020-08-21T06:16:36Z")

</div>

Hi

I want to know How to create a filter of the related object (ForeignKey field) in Adding or Editing page in Admin Site.

**Please guide some code or reference links about this question for me to read more.**

General speaking, It is how to customize in add/edit page on the admin site.

My requirement is that I don’t want to list all company, it has to just filter company.is\_customer =True for dropdown list in Edit/Add Brand page

 ![queryset](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/7/73b993600ab91e6146dea81ca1db1bc49b3deb8b.png)

model.py

```auto
class Company(models.Model):
    company_name = models.CharField('Company Name', max_length=255,unique=True )
    company_address=models.CharField('Company Address',max_length=255 ,null=True, blank=True)
    company_telephone = models.CharField('Company Telephone', max_length=255, null=True, blank=True)
    manager = models.ManyToManyField(Manager)

    is_customer =models.BooleanField('Is Customer',default=True)
    is_subcontractor = models.BooleanField('Is Sub Contractor', default=True)

class DataCenter(models.Model):
    datacenter_name = models.CharField('DataCenter Name', max_length=255)

    company=models.ForeignKey('Company',on_delete=models.CASCADE)
    

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 21, 2020, 12:39pm UTC](https://forum.djangoproject.com/t/how-to-create-a-filter-of-any-related-object-foreignkey-field-in-add-or-edit-page-in-admin-site/4001/2 "2020-08-21T12:39:04Z")

</div>

I’d start with taking a look at the [ModelAdmin.formfield\_for\_foreignkey](https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey) method to see whether that will work for you.

Ken

---

<div class="post-metadata">

**Author:** ![technqvi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/technqvi/32/1851_2.png) [@technqvi](https://forum.djangoproject.com/u/technqvi)\
**Post date:** [August 24, 2020, 4:15pm UTC](https://forum.djangoproject.com/t/how-to-create-a-filter-of-any-related-object-foreignkey-field-in-add-or-edit-page-in-admin-site/4001/3 "2020-08-24T16:15:28Z")

</div>

Thank you, I can already do it.
