admin.py 944 Bytes
from django.contrib import admin
from django.db.models import Q

from .models import Organismo, Dependencia
from core.querysets import filter_queryset_by_permissions

# Register your models here.


@admin.register(Organismo)
class OrganismoAdmin(admin.ModelAdmin):
    model = Organismo
    list_display = ('short_name', )
    list_filter = ('short_name',)
    search_fields = ('short_name', )

    def get_queryset(self, request):
        qs = super().get_queryset(request)
        qs = filter_queryset_by_permissions(qs, request.user)
        return qs


@admin.register(Dependencia)
class DependenciaAdmin(admin.ModelAdmin):
    model = Dependencia
    list_display = ('short_name', 'organismo',)
    list_filter = ('organismo', 'short_name',)
    search_fields = ('short_name',)

    def get_queryset(self, request):
        qs = super().get_queryset(request)
        qs = filter_queryset_by_permissions(qs, request.user)
        return qs