# Path: baton/admin.py
# class InputFilter(admin.SimpleListFilter):
#     template = 'baton/filters/input_filter.html'
# 
#     def lookups(self, request, model_admin):
#         # Dummy, required to show the filter.
#         return ((),)
# 
#     def choices(self, changelist):
#         # Grab only the "all" option.
#         all_choice = next(super(InputFilter, self).choices(changelist))
#         all_choice['query_parts'] = (
#             (k, v)
#             for k, v in changelist.get_filters_params().items()
#             if k != self.parameter_name
#         )
#         yield all_choice
# 
# class RelatedDropdownFilter(RelatedFieldListFilter):
#     template = 'baton/filters/dropdown_filter.html'
# 
# Path: testapp/app/news/models.py
# class News(models.Model):
#     category = models.ForeignKey(
#         Category,
#         verbose_name='category',
#         on_delete=models.CASCADE,
#         related_name='news',
#     )
#     date = models.DateField('date')
#     datetime = models.DateTimeField('datetime', blank=True, null=True, help_text='insert date')
#     title = models.CharField('title', max_length=50, help_text='please insert a cool title')
#     link = models.URLField('link', blank=True, null=True)
#     image = FilerImageField(null=True, blank=True, on_delete=models.SET_NULL, related_name="news_image")
#     content = HTMLField(verbose_name='content', help_text='html is supported')
#     share = models.BooleanField(default=False)
#     published = models.BooleanField(default=False)
#     attachments_summary = models.TextField('attachments summary', blank=True)
#     videos_summary = models.TextField('videos summary', blank=True)
#     favorites = GenericRelation(Activity)
# 
#     class Meta:
#         verbose_name = "news"
#         verbose_name_plural = "news"
# 
#     def __str__(self):
#         return '{0}'.format(self.title)
# 
# class Category(models.Model):
#     name = models.CharField('name', max_length=50)
# 
#     class Meta:
#         verbose_name = "category"
#         verbose_name_plural = "categories"
# 
#     def __str__(self):
#         return "{0}".format(self.name)
# 
# class Attachment(models.Model):
#     news = models.ForeignKey(
#         News,
#         verbose_name='news',
#         on_delete=models.CASCADE,
#         related_name='attachments',
#     )
#     file = models.FileField(upload_to='news/img')
#     caption = models.TextField()
# 
#     class Meta:
#         verbose_name = "attachment"
#         verbose_name_plural = "attachments"
# 
#     def __str__(self):
#         return '{0}'.format(self.caption)
# 
# class Video(models.Model):
#     news = models.ForeignKey(
#         News,
#         verbose_name='news',
#         on_delete=models.CASCADE,
#         related_name='videos',
#     )
#     code = models.CharField('video code', max_length=50)
#     caption = models.TextField()
#     author_email = models.EmailField(blank=True, null=True)
# 
#     class Meta:
#         verbose_name = "video"
#         verbose_name_plural = "videos"
# 
#     def __str__(self):
#         return '{0}'.format(self.caption)
# 
# class Activity(models.Model):
#     FAVORITE = 'F'
#     LIKE = 'L'
#     UP_VOTE = 'U'
#     DOWN_VOTE = 'D'
#     ACTIVITY_TYPES = (
#         (FAVORITE, 'Favorite'),
#         (LIKE, 'Like'),
#         (UP_VOTE, 'Up Vote'),
#         (DOWN_VOTE, 'Down Vote'),
#     )
# 
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
#     activity_type = models.CharField(max_length=1, choices=ACTIVITY_TYPES)
#     date = models.DateTimeField(auto_now_add=True)
# 
#     # Below the mandatory fields for generic relation
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey()
# 
#     class Meta:
#         verbose_name = "activity"
#         verbose_name_plural = "activities"


import json
from django.contrib import admin
from django.utils.safestring import mark_safe
from django.contrib.contenttypes.admin import GenericStackedInline
from baton.admin import InputFilter, RelatedDropdownFilter
from rangefilter.filter import DateRangeFilter
from admin_auto_filters.filters import AutocompleteFilter
from .models import News, Category, Attachment, Video, Activity
from import_export import resources
from import_export.admin import ImportExportModelAdmin
            return queryset.filter(
                title__icontains=search_term
            )

class CategoryFilter(AutocompleteFilter):
    title = 'category' # display title
    field_name = 'category' # name of the foreign key field

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ('name', )
    search_fields = ('name', )


class AttachmentsInline(admin.TabularInline):
    model = Attachment
    extra = 1


class VideosInline(admin.StackedInline):
    model = Video
    extra = 1
    classes = ('collapse-entry', 'expand-first', )


class ActivitiesInline(GenericStackedInline):
    model = Activity
    extra = 1



# Path: baton/admin.py
# class InputFilter(admin.SimpleListFilter):
#     template = 'baton/filters/input_filter.html'
# 
#     def lookups(self, request, model_admin):
#         # Dummy, required to show the filter.
#         return ((),)
# 
#     def choices(self, changelist):
#         # Grab only the "all" option.
#         all_choice = next(super(InputFilter, self).choices(changelist))
#         all_choice['query_parts'] = (
#             (k, v)
#             for k, v in changelist.get_filters_params().items()
#             if k != self.parameter_name
#         )
#         yield all_choice
# 
# class RelatedDropdownFilter(RelatedFieldListFilter):
#     template = 'baton/filters/dropdown_filter.html'
# 
# Path: testapp/app/news/models.py
# class News(models.Model):
#     category = models.ForeignKey(
#         Category,
#         verbose_name='category',
#         on_delete=models.CASCADE,
#         related_name='news',
#     )
#     date = models.DateField('date')
#     datetime = models.DateTimeField('datetime', blank=True, null=True, help_text='insert date')
#     title = models.CharField('title', max_length=50, help_text='please insert a cool title')
#     link = models.URLField('link', blank=True, null=True)
#     image = FilerImageField(null=True, blank=True, on_delete=models.SET_NULL, related_name="news_image")
#     content = HTMLField(verbose_name='content', help_text='html is supported')
#     share = models.BooleanField(default=False)
#     published = models.BooleanField(default=False)
#     attachments_summary = models.TextField('attachments summary', blank=True)
#     videos_summary = models.TextField('videos summary', blank=True)
#     favorites = GenericRelation(Activity)
# 
#     class Meta:
#         verbose_name = "news"
#         verbose_name_plural = "news"
# 
#     def __str__(self):
#         return '{0}'.format(self.title)
# 
# class Category(models.Model):
#     name = models.CharField('name', max_length=50)
# 
#     class Meta:
#         verbose_name = "category"
#         verbose_name_plural = "categories"
# 
#     def __str__(self):
#         return "{0}".format(self.name)
# 
# class Attachment(models.Model):
#     news = models.ForeignKey(
#         News,
#         verbose_name='news',
#         on_delete=models.CASCADE,
#         related_name='attachments',
#     )
#     file = models.FileField(upload_to='news/img')
#     caption = models.TextField()
# 
#     class Meta:
#         verbose_name = "attachment"
#         verbose_name_plural = "attachments"
# 
#     def __str__(self):
#         return '{0}'.format(self.caption)
# 
# class Video(models.Model):
#     news = models.ForeignKey(
#         News,
#         verbose_name='news',
#         on_delete=models.CASCADE,
#         related_name='videos',
#     )
#     code = models.CharField('video code', max_length=50)
#     caption = models.TextField()
#     author_email = models.EmailField(blank=True, null=True)
# 
#     class Meta:
#         verbose_name = "video"
#         verbose_name_plural = "videos"
# 
#     def __str__(self):
#         return '{0}'.format(self.caption)
# 
# class Activity(models.Model):
#     FAVORITE = 'F'
#     LIKE = 'L'
#     UP_VOTE = 'U'
#     DOWN_VOTE = 'D'
#     ACTIVITY_TYPES = (
#         (FAVORITE, 'Favorite'),
#         (LIKE, 'Like'),
#         (UP_VOTE, 'Up Vote'),
#         (DOWN_VOTE, 'Down Vote'),
#     )
# 
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
#     activity_type = models.CharField(max_length=1, choices=ACTIVITY_TYPES)
#     date = models.DateTimeField(auto_now_add=True)
# 
#     # Below the mandatory fields for generic relation
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey()
# 
#     class Meta:
#         verbose_name = "activity"
#         verbose_name_plural = "activities"


# Path: testapp/app/news/admin.py
import json
from django.contrib import admin
from django.utils.safestring import mark_safe
from django.contrib.contenttypes.admin import GenericStackedInline
from baton.admin import InputFilter, RelatedDropdownFilter
from rangefilter.filter import DateRangeFilter
from admin_auto_filters.filters import AutocompleteFilter
from .models import News, Category, Attachment, Video, Activity
from import_export import resources
from import_export.admin import ImportExportModelAdmin

            return queryset.filter(
                title__icontains=search_term
            )

class CategoryFilter(AutocompleteFilter):
    title = 'category' # display title
    field_name = 'category' # name of the foreign key field

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ('name', )
    search_fields = ('name', )


class AttachmentsInline(admin.TabularInline):
    model = Attachment
    extra = 1


class VideosInline(admin.StackedInline):
    model = Video
    extra = 1
    classes = ('collapse-entry', 'expand-first', )


class ActivitiesInline(GenericStackedInline):
    model = Activity
    extra = 1



@admin.register(News)