Repository: wagtail/wagtail

Issue:
`ModelIndexView` does not work with custom object managers
<!--
Found a bug? Please fill out the sections below. 👍
-->

### Issue Summary

<!--
A summary of the issue.
-->

In `ModelIndexView._get_snippet_types`, the `count` is done by accessing `model.objects.all().count()`. This does not work with models that have a default manager that is not `objects`.

When registering a model as a snippet that defines a custom default manager with a name different than `objects` it will throw an exception. In our case:

```
AttributeError: type object 'ParserError' has no attribute 'objects'
(4 additional frame(s) were not displayed)
...
  File "wagtail/admin/auth.py", line 165, in decorated_view
    response = view_func(request, *args, **kwargs)
  File "django/views/generic/base.py", line 98, in view
    self.setup(request, *args, **kwargs)
  File "wagtail/snippets/views/snippets.py", line 85, in setup
    self.snippet_types = self._get_snippet_types()
  File "wagtail/snippets/views/snippets.py", line 88, in _get_snippet_types
    return [
  File "wagtail/snippets/views/snippets.py", line 91, in <listcomp>
    "count": model.objects.all().count(),
```

### Steps to Reproduce

1. Start a new project with `wagtail start myproject`
2. Add a new model that has a manager not named "objects" (see example below)
3. Register that model as a snippet
4. Go to snippets view
5. See error

```py
from django.db import models
from wagtail.snippets.models import register_snippet

class ParserErrorManager(models.Manager):
   pass

@register_snippet
class ParserError(models.Model):
   err_msg = models.CharField(max_length=250)

    errors = ParserErrorManager()
```

Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?

-   I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: (yes / no)

### Technical details

-   Python version: 3.10.
-   Django version: 4.2.8.
-   Wagtail version: 5.2.3.
-   Browser version: https://www.whatsmybrowser.org/b/RFN3C

### Working on this

<!--
  Do you have thoughts on skills needed?
  Are you keen to work on this yourself once the issue has been accepted?
  Please let us know here.
-->

Anyone can contribute to this. View our [contributing guidelines](https://docs.wagtail.org/en/latest/contributing/index.html), add a comment to the issue once you’re ready to start.



Discussion:

Resolving patch:
diff --git a/wagtail/snippets/views/snippets.py b/wagtail/snippets/views/snippets.py
--- a/wagtail/snippets/views/snippets.py
+++ b/wagtail/snippets/views/snippets.py
@@ -90,7 +90,7 @@ def _get_snippet_types(self):
         return [
             {
                 "name": capfirst(model._meta.verbose_name_plural),
-                "count": model.objects.all().count(),
+                "count": model._default_manager.all().count(),
                 "model": model,
             }
             for model in get_snippet_models()


Test patch:
diff --git a/wagtail/test/testapp/migrations/0035_modelwithcustommanager.py b/wagtail/test/testapp/migrations/0035_modelwithcustommanager.py
new file mode 100644
--- /dev/null
+++ b/wagtail/test/testapp/migrations/0035_modelwithcustommanager.py
@@ -0,0 +1,30 @@
+# Generated by Django 5.0.1 on 2024-03-15 21:20
+
+import django.db.models.manager
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("tests", "0034_custompermissionmodel"),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name="ModelWithCustomManager",
+            fields=[
+                (
+                    "id",
+                    models.AutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
+            ],
+            managers=[
+                ("instances", django.db.models.manager.Manager()),
+            ],
+        ),
+    ]
diff --git a/wagtail/test/testapp/models.py b/wagtail/test/testapp/models.py
--- a/wagtail/test/testapp/models.py
+++ b/wagtail/test/testapp/models.py
@@ -1011,6 +1011,17 @@ class Meta:
 register_snippet(AdvertWithTabbedInterface)
 
 
+class CustomManager(models.Manager):
+    pass
+
+
+class ModelWithCustomManager(models.Model):
+    instances = CustomManager()
+
+
+register_snippet(ModelWithCustomManager)
+
+
 # Models with RevisionMixin
 class RevisableModel(RevisionMixin, models.Model):
     text = models.TextField()