Search code examples
pythonpython-3.xflaskflask-admin

Strange behaviour of flask admin


I have a collection of various models in my flask project. Some of the models have foreign keys to two other models (many-to-many tables).

When I open these many-to-many models in flask-admin some of the records get duplicated on different pages and not all records are shown. However, the total number of records is correct.

When I sort the records by the many-to-many model's id then everything is fine - all records are shown and without any duplicates. I haven't seen such strange behaviour with other models (which are not many-to-many), but only with many-to-many ones.

Does anybody know how to resolve this strange issue?


Solution

  • Unfortunately, it seems that the StackOverflow community sometimes just ignores some questions. However, some time ago I resolved my issue.

    I added this line to my model definition:

    column_sortable_list = ('id',)
    

    I needed to clearly state what columns can be used for sorting. This solved the problem in my many-to-many models. Now there are no duplicates and all the records are shown. Don't know if it is a feature or a bug.

    If you need to see all columns presorted in ascending order by id then add this:

    column_default_sort = ('id', False)
    

    Hope this will help other developers using flask-admin.