# Custom display values in drop downs for TabularInline

**URL:** <https://forum.djangoproject.com/t/custom-display-values-in-drop-downs-for-tabularinline/17180>\
**Category:** The Admin\
**Created:** [November 22, 2022, 5:30am UTC](https://forum.djangoproject.com/t/custom-display-values-in-drop-downs-for-tabularinline/17180 "2022-11-22T05:30:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jason/32/5523_2.png) [@Jason](https://forum.djangoproject.com/u/Jason)\
**Post date:** [November 22, 2022, 5:30am UTC](https://forum.djangoproject.com/t/custom-display-values-in-drop-downs-for-tabularinline/17180/1 "2022-11-22T05:30:35Z")

</div>

I have a TabularInline that includes the CarType and Car models:

```auto
class Car(models.Model):
    name = models.CharField(max_length=100)
    type = models.ManyToMany(CarTypes, through="CarTypeWithCar"))
    manufacturer = models.ForeignKey(Manfacturer, on_delete=models.PROTECT)

    def __str__ (self):
        return self.name

...

CarTypeWithCar(models.Model):
    car_type = models.ForeignKey(
        CarType, on_delete=models.CASCADE
    )
    car = models.ForeignKey(
        Car, on_delete=models.CASCADE
    )

...

class CarTypeWithCarAdminInline(admin.TabularInline):
    model = Car.type.through
    fields = ["car_type", "car"]

```

The problem is, when I click the select dropdown for the `car` field in my Inline, it lists just the name of the car (which can be a little confusing for a big list). I would like to customize the values in the `car` select to display something like `f"{self.car.manufacturer} - {self.car}"` instead of just the ` __str__ ` of the Car model. I really do not want to change the ` __str__ `, since I am using that in other places in my app.

I’ve wrestled with this the entire evening, and I’m still not sure how to make it happen. Thank you in advance for any assistance!

---

<div class="post-metadata">

**Author:** ![leandrodesouzadev](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/leandrodesouzadev/32/8981_2.png) [@leandrodesouzadev](https://forum.djangoproject.com/u/leandrodesouzadev)\
**Post date:** [November 22, 2022, 10:40am UTC](https://forum.djangoproject.com/t/custom-display-values-in-drop-downs-for-tabularinline/17180/2 "2022-11-22T10:40:20Z")

</div>

Hey there!  
Maybe you can do this using [formfield\_for\_foreignkey](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey), just after this section, also there’s two anothers, maybe that fit into your use case.

---

<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:** [November 22, 2022, 12:46pm UTC](https://forum.djangoproject.com/t/custom-display-values-in-drop-downs-for-tabularinline/17180/3 "2022-11-22T12:46:17Z")

</div>

I’m not quite understanding what you’re trying to achieve here.

Typically, an AdminInline is used to allow for editing a second, related model, relative to the base model of that admin page.

For example, if this is being used in the admin page for `Car`, you could use the AdminInline to allow for the editing of related `CarTypes`.

It appears that you’re working in that direction - what confuses me is the presence of the `car` field in the `fields` list of `CarTypeWithCarAdminInline` - or why you’re creating an inline for the join table instead of `CarType`. (See [Working with many-to-many models](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/#working-with-many-to-many-models). )

Aside from that, there are ways to customize what shows up in the `choices` for a form field. `TabularInline` is a subclass of `InlineModelAdmin`. `InlineModelAdmin` has a variety of options including specifying the `form` class - which could be a custom form of your creation, containing the custom `choices`.

---

<div class="post-metadata">

**Author:** ![Jason](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jason/32/5523_2.png) [@Jason](https://forum.djangoproject.com/u/Jason)\
**Post date:** [November 22, 2022, 3:31pm UTC](https://forum.djangoproject.com/t/custom-display-values-in-drop-downs-for-tabularinline/17180/4 "2022-11-22T15:31:42Z")

</div>

Ken, thank you for your help and your patience with my confusing example! Customizing the values choices in the form is definitely what I want to do. I will try subclassing `InlineModelAdmin.InlineModelAdmin` and modifying the choices in a custom form. The models I’m actually using in my application are really large and thus not suitable for a forum post, but my contrived example seemingly wasn’t any better. 🫤 Next time I will build a little app for an example instead.

@leandrodesouzadev thanks for the interesting link! Just a couple of items below your link, I noticed [ModelAdmin.formfield\_for\_choice\_field](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_choice_field), which has some interesting logic for detecting my field. Thanks for the cool link!
