from django.contrib import admin
from django.db import models
from django.forms import Textarea, TextInput, URLInput

from newsreader.news.core.models import Category, Post


class PostAdmin(admin.ModelAdmin):
    list_display = ("publication_date", "rule", "title")
    list_display_links = ("title",)
    list_filter = ("rule",)

    ordering = ("-publication_date", "title")

    fields = (
        "remote_identifier",
        "rule",
        "url",
        "title",
        "body",
        "publication_date",
        "author",
    )

    readonly_fields = ("remote_identifier", "rule")
    search_fields = ("title", "author", "rule__name")

    formfield_overrides = {
        models.CharField: {"widget": TextInput(attrs={"size": "100"})},
        models.URLField: {"widget": URLInput(attrs={"size": "100"})},
        models.TextField: {"widget": Textarea(attrs={"rows": 10, "cols": 100})},
    }


class CategoryAdmin(admin.ModelAdmin):
    pass


admin.site.register(Post, PostAdmin)
admin.site.register(Category, CategoryAdmin)
