# Django Admin Sortable Model (move up and down)

**URL:** <https://forum.djangoproject.com/t/django-admin-sortable-model-move-up-and-down/13854>\
**Category:** The Admin\
**Created:** [May 22, 2022, 3:46pm UTC](https://forum.djangoproject.com/t/django-admin-sortable-model-move-up-and-down/13854 "2022-05-22T15:46:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gosukiwi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gosukiwi/32/8602_2.png) [@gosukiwi](https://forum.djangoproject.com/u/gosukiwi)\
**Post date:** [May 22, 2022, 3:46pm UTC](https://forum.djangoproject.com/t/django-admin-sortable-model-move-up-and-down/13854/1 "2022-05-22T15:46:48Z")

</div>

I have a model, let’s say `Post`, that has an integer `ordinality` field. `Post` belongs to `Category`:

```python
class Category(models.Model):
    name = models.CharField(max_length=128)

class Post(models.Model):
    name = models.CharField(max_length=128)
    ordinality = models.IntegerField()
    category = models.ForeignKey(Category, on_delete=models.CASCADE)

```

In the admin panel, I want to:

- Filter posts by category, don’t just show all posts
- Order posts by `ordinality`
- Be able to change the ordinality from the list view, by clicking “up” and “down” links in the table
- Be smart when creating new `Post` models and automatically set the `ordinality` so that it’s last

Eg: If I have a `Post(name="Post 1", ordinality=1, category=general)` and I create a new one, `ordinality` should be set to `2`. If there’s already a `Post` in the same category with ordinality `2`, it should be `3`, and so on. So the ordinality is scoped by category in this case.

I’m new to Django (coming form Rails) and I want to know “the Django way” to solve this. I’m not sure if this is doable with the admin (I don’t mind implementing my own admin extensions) or if I should create a custom page for this.

Thanks in advance 🙂

---

<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:** [May 22, 2022, 4:19pm UTC](https://forum.djangoproject.com/t/django-admin-sortable-model-move-up-and-down/13854/2 "2022-05-22T16:19:53Z")

</div>

When looking for ideas or modules to perform specific functions, one place to check is [djangopackages.org](http://djangopackages.org).

In this case, try searching for “sort”. You should see [django-admin-sortable2](https://djangopackages.org/packages/p/django-admin-sortable2/) as one of the top options.

It may be sufficient for what you need - it may not, but it should be a suitable starting point for further research.

---

<div class="post-metadata">

**Author:** ![gosukiwi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gosukiwi/32/8602_2.png) [@gosukiwi](https://forum.djangoproject.com/u/gosukiwi)\
**Post date:** [May 23, 2022, 4:24am UTC](https://forum.djangoproject.com/t/django-admin-sortable-model-move-up-and-down/13854/3 "2022-05-23T04:24:53Z")

</div>

Thanks! It is quite limited, but I managed to make it work using `django-admin-sortable2` 🙂

It does not work with `order_with_respect_to`, and it forces you to sort the list view, even if you only want to use it in the `StackedInline`, but I think that’s Django’s admin panel design.
