# Path: modeltrans/admin.py
# class ActiveLanguageMixin:
#     """
#     ModelAdmin mixin to only show fields for the fallback and current language in the change view.
#     """
# 
#     form_class = TranslationModelForm
# 
# Path: example/app/models.py
# class Blog(models.Model):
#     title = models.CharField(max_length=255)
#     body = models.TextField(null=True, blank=True)
# 
#     category = models.ForeignKey(Category, null=True, blank=True, on_delete=models.CASCADE)
# 
#     i18n = TranslationField(fields=("title", "body"))
# 
#     class Meta:
#         indexes = [GinIndex(fields=["i18n"])]
# 
#     def __str__(self):
#         return self.title_i18n
# 
#     def get_absolute_url(self):
#         return reverse("blog_detail", args=(self.pk,))
# 
# class Category(models.Model):
#     name = models.CharField(max_length=255)
# 
#     i18n = TranslationField(fields=("name",))
# 
#     class Meta:
#         indexes = [GinIndex(fields=["i18n"])]
#         verbose_name_plural = "categories"
# 
#     def __str__(self):
#         return self.name_i18n
# 
# Path: example/app/utils.py
# def disable_admin_login():
#     """
#     Disable admin login, but allow editing.
# 
#     amended from: https://stackoverflow.com/a/40008282/517560
#     """
#     User = get_user_model()
# 
#     try:
#         user, created = User.objects.update_or_create(
#             id=1,
#             defaults=dict(
#                 first_name="Default Admin",
#                 last_name="User",
#                 is_superuser=True,
#                 is_active=True,
#                 is_staff=True,
#             ),
#         )
#     except ProgrammingError:
#         # auth_user doesn't exist, this allows the migrations to run properly.
#         user = None
# 
#     def no_login_has_permission(request):
#         setattr(request, "user", user)
# 
#         return True
# 
#     return no_login_has_permission


from django.contrib import admin
from modeltrans.admin import ActiveLanguageMixin
from .models import Blog, Category
from .utils import disable_admin_login



admin.site.has_permission = disable_admin_login()


@admin.register(Blog)
class BlogAdmin(ActiveLanguageMixin, admin.ModelAdmin):
    list_display = ("title_i18n", "category")
    search_fields = ("title_i18n", "category__name_i18n")



# Path: modeltrans/admin.py
# class ActiveLanguageMixin:
#     """
#     ModelAdmin mixin to only show fields for the fallback and current language in the change view.
#     """
# 
#     form_class = TranslationModelForm
# 
# Path: example/app/models.py
# class Blog(models.Model):
#     title = models.CharField(max_length=255)
#     body = models.TextField(null=True, blank=True)
# 
#     category = models.ForeignKey(Category, null=True, blank=True, on_delete=models.CASCADE)
# 
#     i18n = TranslationField(fields=("title", "body"))
# 
#     class Meta:
#         indexes = [GinIndex(fields=["i18n"])]
# 
#     def __str__(self):
#         return self.title_i18n
# 
#     def get_absolute_url(self):
#         return reverse("blog_detail", args=(self.pk,))
# 
# class Category(models.Model):
#     name = models.CharField(max_length=255)
# 
#     i18n = TranslationField(fields=("name",))
# 
#     class Meta:
#         indexes = [GinIndex(fields=["i18n"])]
#         verbose_name_plural = "categories"
# 
#     def __str__(self):
#         return self.name_i18n
# 
# Path: example/app/utils.py
# def disable_admin_login():
#     """
#     Disable admin login, but allow editing.
# 
#     amended from: https://stackoverflow.com/a/40008282/517560
#     """
#     User = get_user_model()
# 
#     try:
#         user, created = User.objects.update_or_create(
#             id=1,
#             defaults=dict(
#                 first_name="Default Admin",
#                 last_name="User",
#                 is_superuser=True,
#                 is_active=True,
#                 is_staff=True,
#             ),
#         )
#     except ProgrammingError:
#         # auth_user doesn't exist, this allows the migrations to run properly.
#         user = None
# 
#     def no_login_has_permission(request):
#         setattr(request, "user", user)
# 
#         return True
# 
#     return no_login_has_permission


# Path: example/app/admin.py
from django.contrib import admin
from modeltrans.admin import ActiveLanguageMixin
from .models import Blog, Category
from .utils import disable_admin_login




admin.site.has_permission = disable_admin_login()


@admin.register(Blog)
class BlogAdmin(ActiveLanguageMixin, admin.ModelAdmin):
    list_display = ("title_i18n", "category")
    search_fields = ("title_i18n", "category__name_i18n")



class DefaultAdminCategory(Category):