# Using TextChoices

**URL:** <https://forum.djangoproject.com/t/using-textchoices/26764>\
**Category:** Getting Started\
**Created:** [January 9, 2024, 7:27am UTC](https://forum.djangoproject.com/t/using-textchoices/26764 "2024-01-09T07:27:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![callmejg147](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/callmejg147/32/17973_2.png) [@callmejg147](https://forum.djangoproject.com/u/callmejg147)\
**Post date:** [January 9, 2024, 7:27am UTC](https://forum.djangoproject.com/t/using-textchoices/26764/1 "2024-01-09T07:27:36Z")

</div>

I’m using Django 4.2 and i was looking for a field to select form a given options. I came across TextChoises but its not showing up in my admin panel. Am i using it the right way?

models.py

```auto
class Gallery(models.Model):
    id = models.AutoField(primary_key=True)
    type = models.TextChoices("Image", "Video")
    title = models.CharField(max_length=100,null=True)
    file = models.FileField(upload_to='gallery/', null=True)

```

what i am trying to do is to have two options image or video to choose from.

---

<div class="post-metadata">

**Author:** ![addwebsolution](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/addwebsolution/32/23762_2.png) [@addwebsolution](https://forum.djangoproject.com/u/addwebsolution)\
**Post date:** [January 9, 2024, 7:37am UTC](https://forum.djangoproject.com/t/using-textchoices/26764/2 "2024-01-09T07:37:07Z")

</div>

You can use choices attribute in your model fields like:

```auto
class MC:
    timing = (
        ('D', "Day"),
        ('W', "Week"),
        ('M', "Month")
    )

    gender = (
        (1, "Man"),
        (2, "Woman"),
        (3, "Agender"),
        (4, "Bigender"),
        (5, "Genderfluid"),
        (6, "Genderqueer"),
        (7, "Gender nonconfirming"),
        (8, "Gender questioning"),
        (9, "Gender variant"),
        (10, "Intersex"),
        (11, "Neutrois"),
        (12, "Nonbinary Man"),
    )

class ABC(models.Model):
    duration_type = models.CharField(choices=MC().timing, default='M', max_length=3)
    gender = models.SmallIntegerField(default=1, choices=MC.gender)

```

In the above example I’ve given different kinds of choices like with `CharField` and `SmallIntegerField`.

---

<div class="post-metadata">

**Author:** ![callmejg147](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/callmejg147/32/17973_2.png) [@callmejg147](https://forum.djangoproject.com/u/callmejg147)\
**Post date:** [January 9, 2024, 7:39am UTC](https://forum.djangoproject.com/t/using-textchoices/26764/3 "2024-01-09T07:39:57Z")

</div>

Yes i get how to use choices with CharField but i wanted to try out or understand TextChoices.

---

<div class="post-metadata">

**Author:** ![addwebsolution](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/addwebsolution/32/23762_2.png) [@addwebsolution](https://forum.djangoproject.com/u/addwebsolution)\
**Post date:** [January 9, 2024, 7:45am UTC](https://forum.djangoproject.com/t/using-textchoices/26764/4 "2024-01-09T07:45:30Z")

</div>

Okay, so take a look at this part of docs [Model field reference | Django documentation | Django](https://docs.djangoproject.com/en/5.0/ref/models/fields/#enumeration-types) here you will see how `models.TextChoices` are being used.

---

<div class="post-metadata">

**Author:** ![addwebsolution](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/addwebsolution/32/23762_2.png) [@addwebsolution](https://forum.djangoproject.com/u/addwebsolution)\
**Post date:** [January 9, 2024, 7:47am UTC](https://forum.djangoproject.com/t/using-textchoices/26764/5 "2024-01-09T07:47:02Z")

</div>

Also, according to your model the updated model from my end should be like this:

```auto
class Gallery(models.Model):
    class MediaType(models.TextChoices):
        IMAGE = 'Image'
        VIDEO = 'Video'

    id = models.AutoField(primary_key=True)
    type = models.CharField(max_length=5, choices=MediaType.choices)

```
