Martín Miranda

Arregla TipoOrganismoAdmin

... ... @@ -37,9 +37,14 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# Aplicaciones de tercero
'django_extensions',
# Aplicaciones propias
'persona',
'organismo',
'core',
]
MIDDLEWARE = [
... ...
... ... @@ -3,17 +3,18 @@ from django.db.models import Count
from organismo.models import Organismo, TipoOrganismo
@admin.register(TipoOrganismo)
class TipoOrganismoAdmin(admin.ModelAdmin):
list_display = ('nombre', 'es_activo', 'cantidad_organismo')
search_fields = ('nombre',)
actions = ('desactivar_seleccionados', )
actions = ('desactivar_seleccionados',)
def get_queryset(self, request):
queryset = super().get_queryset(request).values('organismos').annotate(cantidad_organismo=Count('organismos')).all()
queryset = super().get_queryset(request).annotate(cantidad_organismo=Count('organismos'))
if request.user.is_superuser:
return queryset
return queryset.filter(es_activo=True)
def desactivar_seleccionados(self, request, queryset):
... ... @@ -21,12 +22,10 @@ class TipoOrganismoAdmin(admin.ModelAdmin):
def cantidad_organismo(self, tipo):
return tipo.cantidad_organismo
@admin.register(Organismo)
class OrganismoAdmin(admin.ModelAdmin):
list_display = ('nombre', 'tipo')
search_fields = ('nombre', 'tipo__nombre')
autocomplete_fields = ('tipo',)
\ No newline at end of file
autocomplete_fields = ('tipo',)
... ...
# Generated by Django 3.2.7 on 2021-09-29 12:56
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('organismo', '0003_tipoorganismo_es_activo'),
]
operations = [
migrations.AlterField(
model_name='organismo',
name='tipo',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='organismos', to='organismo.tipoorganismo'),
),
]
... ...
django==3.2.7
\ No newline at end of file
django==3.2.7
... ...
-r base.txt
django-extensions==3.1.3
\ No newline at end of file
... ...