from django.contrib import admin
from animalitos.models import Animal, Adoptante, Adoptar
from django.db import models
#Animal > Table of cardinality N, the primary key is idAnimal
#Adoptante > Table of cardinality N, the primary key is idAdoptante
#Adoptar > is a table created of N:N relationship, This table contains foreigns keys named as(Animal_idAnimal)(Adoptante_idAdoptante)
# Adoptar has attributes as date, foreigns keys....
class AdoptarInLine(admin.StackedInline):
model = Adoptar
@admin.register(Animal)
class AnimalInline(admin.ModelAdmin):
inlines = [AdoptarInLine]
list_display = ('Custom_method')
def Custom_method(self,Animal):
adoptante = Adoptar.objects.filter(Animal_idAnimal = Animal.idAnimal).order_by('-date').first()
return adoptante.date
Custom_method.admin_order_field = 'date' # This is a problem, i want use date, but the django say's that I only can use attributes of animal.. as name.. birth... color...
#I need can Sort my Custom_method by date of Adoptar table
#Help me please.... :D Greettings!