# Buggy code
def discover(self):
    """Manual discovery."""
    # Accounts
    self.register(User, WeblateUserAdmin)
    self.register(Role, RoleAdmin)
    self.register(Group, WeblateGroupAdmin)
    self.register(AuditLog, AuditLogAdmin)
    self.register(AutoGroup, AutoGroupAdmin)
    self.register(Profile, ProfileAdmin)
    self.register(VerifiedEmail, VerifiedEmailAdmin)

    # Languages
    if settings.DEBUG:
        self.register(Language, LanguageAdmin)

    # Screenshots
    self.register(Screenshot, ScreenshotAdmin)

    # Fonts
    self.register(Font, FontAdmin)
    self.register(FontGroup, FontGroupAdmin)

    # Translations
    self.register(Project, ProjectAdmin)
    self.register(Component, ComponentAdmin)
    self.register(WhiteboardMessage, WhiteboardMessageAdmin)
    self.register(ComponentList, ComponentListAdmin)
    self.register(ContributorAgreement, ContributorAgreementAdmin)

    # Show some controls only in debug mode
    if settings.DEBUG:
        self.register(Translation, TranslationAdmin)
        self.register(Unit, UnitAdmin)
        self.register(Suggestion, SuggestionAdmin)
        self.register(Comment, CommentAdmin)
        self.register(Check, CheckAdmin)
        self.register(Dictionary, DictionaryAdmin)
        self.register(Change, ChangeAdmin)
        self.register(Source, SourceAdmin)

    if settings.BILLING_ADMIN:
        # Billing
        if "weblate.billing" in settings.INSTALLED_APPS:
            # pylint: disable=wrong-import-position
            from weblate.billing.admin import (
                PlanAdmin,
                BillingAdmin,
                InvoiceAdmin,
            )
            from weblate.billing.models import Plan, Billing, Invoice

            self.register(Plan, PlanAdmin)
            self.register(Billing, BillingAdmin)
            self.register(Invoice, InvoiceAdmin)

        # Hosted
        if "wlhosted.integrations" in settings.INSTALLED_APPS:
            # pylint: disable=wrong-import-position
            from wlhosted.payments.admin import CustomerAdmin, PaymentAdmin
            from wlhosted.payments.models import Customer, Payment

            self.register(Customer, CustomerAdmin)
            self.register(Payment, PaymentAdmin)

    # Legal
    if "weblate.legal" in settings.INSTALLED_APPS:
        # pylint: disable=wrong-import-position
        from weblate.legal.admin import AgreementAdmin
        from weblate.legal.models import Agreement

        self.register(Agreement, AgreementAdmin)

    # Python Social Auth
    self.register(UserSocialAuth, UserSocialAuthOption)
    self.register(Nonce, NonceOption)
    self.register(Association, AssociationOption)

    # Django REST Framework
    self.register(Token, TokenAdmin)

    # Django core
    self.register(Site, SiteAdmin)

    # Simple SSO
    if "simple_sso.sso_server" in settings.INSTALLED_APPS:
        from simple_sso.sso_server.server import ConsumerAdmin
        from simple_sso.sso_server.models import Consumer

        self.register(Consumer, ConsumerAdmin)


# Traceback (IndexError)
uwsgi stderr \| ERROR Internal Server Error: /translate/products-template-based/bo-test-template-based/de/
--
| Traceback (most recent call last):
| File "/usr/local/lib/python3.7/dist-packages/django/core/handlers/exception.py", line 34, in inner
| response = get_response(request)
| File "/usr/local/lib/python3.7/dist-packages/django/core/handlers/base.py", line 115, in _get_response
| response = self.process_exception_by_middleware(e, request)
| File "/usr/local/lib/python3.7/dist-packages/django/core/handlers/base.py", line 113, in _get_response
| response = wrapped_callback(request, *callback_args, **callback_kwargs)
| File "/usr/local/lib/python3.7/dist-packages/weblate/trans/views/edit.py", line 518, in translate
| 'addword_form': InlineWordForm(),
| File "/usr/local/lib/python3.7/dist-packages/weblate/trans/util.py", line 268, in render
| return django_render(request, template, context, status=status)
| File "/usr/local/lib/python3.7/dist-packages/django/shortcuts.py", line 36, in render
| content = loader.render_to_string(template_name, context, request, using=using)
| File "/usr/local/lib/python3.7/dist-packages/django/template/loader.py", line 62, in render_to_string
| return template.render(context, request)
| File "/usr/local/lib/python3.7/dist-packages/django/template/backends/django.py", line 61, in render
| return self.template.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 171, in render
| return self._render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 163, in _render
| return self.nodelist.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 937, in render
| bit = node.render_annotated(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 904, in render_annotated
| return self.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/loader_tags.py", line 150, in render
| return compiled_parent._render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 163, in _render
| return self.nodelist.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 937, in render
| bit = node.render_annotated(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 904, in render_annotated
| return self.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/loader_tags.py", line 62, in render
| result = block.nodelist.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 937, in render
| bit = node.render_annotated(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 904, in render_annotated
| return self.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/defaulttags.py", line 513, in render
| return self.nodelist.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 937, in render
| bit = node.render_annotated(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 904, in render_annotated
| return self.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/defaulttags.py", line 309, in render
| return nodelist.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 937, in render
| bit = node.render_annotated(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 904, in render_annotated
| return self.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/defaulttags.py", line 309, in render
| return nodelist.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 937, in render
| bit = node.render_annotated(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 904, in render_annotated
| return self.render(context)
| File "/usr/local/lib/python3.7/dist-packages/django/template/library.py", line 214, in render
| _dict = self.func(*resolved_args, **resolved_kwargs)
| File "/usr/local/lib/python3.7/dist-packages/weblate/trans/templatetags/translations.py", line 187, in format_translation
| plural = language.plural
| File "/usr/local/lib/python3.7/dist-packages/django/utils/functional.py", line 80, in __get__
| res = instance.__dict__[self.name] = self.func(instance)
| File "/usr/local/lib/python3.7/dist-packages/weblate/lang/models.py", line 430, in plural
| return self.plural_set.filter(source=Plural.SOURCE_DEFAULT)[0]
| File "/usr/local/lib/python3.7/dist-packages/django/db/models/query.py", line 309, in __getitem__
| return qs._result_cache[0]
| IndexError: list index out of range

# Fixed code
def discover(self):
    """Manual discovery."""
    # Accounts
    self.register(User, WeblateUserAdmin)
    self.register(Role, RoleAdmin)
    self.register(Group, WeblateGroupAdmin)
    self.register(AuditLog, AuditLogAdmin)
    self.register(AutoGroup, AutoGroupAdmin)
    self.register(Profile, ProfileAdmin)
    self.register(VerifiedEmail, VerifiedEmailAdmin)

    # Languages
    self.register(Language, LanguageAdmin)

    # Screenshots
    self.register(Screenshot, ScreenshotAdmin)

    # Fonts
    self.register(Font, FontAdmin)
    self.register(FontGroup, FontGroupAdmin)

    # Translations
    self.register(Project, ProjectAdmin)
    self.register(Component, ComponentAdmin)
    self.register(WhiteboardMessage, WhiteboardMessageAdmin)
    self.register(ComponentList, ComponentListAdmin)
    self.register(ContributorAgreement, ContributorAgreementAdmin)

    # Show some controls only in debug mode
    if settings.DEBUG:
        self.register(Translation, TranslationAdmin)
        self.register(Unit, UnitAdmin)
        self.register(Suggestion, SuggestionAdmin)
        self.register(Comment, CommentAdmin)
        self.register(Check, CheckAdmin)
        self.register(Dictionary, DictionaryAdmin)
        self.register(Change, ChangeAdmin)
        self.register(Source, SourceAdmin)

    if settings.BILLING_ADMIN:
        # Billing
        if "weblate.billing" in settings.INSTALLED_APPS:
            # pylint: disable=wrong-import-position
            from weblate.billing.admin import (
                PlanAdmin,
                BillingAdmin,
                InvoiceAdmin,
            )
            from weblate.billing.models import Plan, Billing, Invoice

            self.register(Plan, PlanAdmin)
            self.register(Billing, BillingAdmin)
            self.register(Invoice, InvoiceAdmin)

        # Hosted
        if "wlhosted.integrations" in settings.INSTALLED_APPS:
            # pylint: disable=wrong-import-position
            from wlhosted.payments.admin import CustomerAdmin, PaymentAdmin
            from wlhosted.payments.models import Customer, Payment

            self.register(Customer, CustomerAdmin)
            self.register(Payment, PaymentAdmin)

    # Legal
    if "weblate.legal" in settings.INSTALLED_APPS:
        # pylint: disable=wrong-import-position
        from weblate.legal.admin import AgreementAdmin
        from weblate.legal.models import Agreement

        self.register(Agreement, AgreementAdmin)

    # Python Social Auth
    self.register(UserSocialAuth, UserSocialAuthOption)
    self.register(Nonce, NonceOption)
    self.register(Association, AssociationOption)

    # Django REST Framework
    self.register(Token, TokenAdmin)

    # Django core
    self.register(Site, SiteAdmin)

    # Simple SSO
    if "simple_sso.sso_server" in settings.INSTALLED_APPS:
        from simple_sso.sso_server.server import ConsumerAdmin
        from simple_sso.sso_server.models import Consumer

        self.register(Consumer, ConsumerAdmin)