# Path: apps/api/models.py
# class Scopes(models.Model):
#     group = models.ManyToManyField(Group)
#     scopes = models.ManyToManyField(ScopesDefinition)
#     description = models.CharField(max_length=500)
# 
#     def __str__(self):
#         return ' '.join(
#             list(
#                 self.scopes.all().values_list('scope', flat=True),
#             ),
#         )
# 
# class ScopesDefinition(models.Model):
#     scope = models.CharField(max_length=300)
#     description = models.CharField(max_length=500)
# 
#     def __str__(self):
#         return self.scope


from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import Scopes, ScopesDefinition


# Register your models here.


class ScopesDefinitionAdminInline(admin.TabularInline):
    model = Scopes.scopes.through


class GroupAdminInline(admin.TabularInline):
    model = Scopes.group.through


@admin.register(Scopes)
class ScopesAdmin(admin.ModelAdmin):
    list_display = ('get_scopes', 'description')
    exclude = ('group', 'scopes')
    inlines = (GroupAdminInline, ScopesDefinitionAdminInline,)

    def get_scopes(self, obj):
        return ' '.join(
            list(
                obj.scopes.all().values_list('scope', flat=True),
            ),
        )



# Path: apps/api/models.py
# class Scopes(models.Model):
#     group = models.ManyToManyField(Group)
#     scopes = models.ManyToManyField(ScopesDefinition)
#     description = models.CharField(max_length=500)
# 
#     def __str__(self):
#         return ' '.join(
#             list(
#                 self.scopes.all().values_list('scope', flat=True),
#             ),
#         )
# 
# class ScopesDefinition(models.Model):
#     scope = models.CharField(max_length=300)
#     description = models.CharField(max_length=500)
# 
#     def __str__(self):
#         return self.scope


# Path: apps/api/admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import Scopes, ScopesDefinition



# Register your models here.


class ScopesDefinitionAdminInline(admin.TabularInline):
    model = Scopes.scopes.through


class GroupAdminInline(admin.TabularInline):
    model = Scopes.group.through


@admin.register(Scopes)
class ScopesAdmin(admin.ModelAdmin):
    list_display = ('get_scopes', 'description')
    exclude = ('group', 'scopes')
    inlines = (GroupAdminInline, ScopesDefinitionAdminInline,)

    def get_scopes(self, obj):
        return ' '.join(
            list(
                obj.scopes.all().values_list('scope', flat=True),
            ),
        )



@admin.register(ScopesDefinition)