""" This module holds the django admin models of the ``brainstormers`` app. """

from django.contrib import admin
from django.contrib.contenttypes.admin import GenericTabularInline

from .models import Like


class LikeAdmin(admin.ModelAdmin):
    """ Admin for Like. """

    fields = ('author', 'weight', ('content_type', 'object_uuid'), 'date_time')
    readonly_fields = ('date_time',)
    list_display = ('__str__', 'weight')
    list_filter = ('author', 'weight')


class LikeInline(GenericTabularInline):
    """ Admin for Like Inline. """

    model = Like
    ct_field = 'content_type'
    ct_fk_field = 'object_uuid'
    fields = ('author', 'weight', 'date_time')
    readonly_fields = ('date_time',)


class LikeableAdmin(admin.ModelAdmin):
    """ Admin for Likeable Model Admin.
    Allows to add like inlines below model admin.
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.inlines += [LikeInline]

admin.site.register(Like, LikeAdmin)
