Sort Custom method with Inlines

3 views
Skip to first unread message

DAVID MATEO BOHORQUEZ GALEANO

unread,
Sep 11, 2015, 2:51:51 AM9/11/15
to Django users
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




Antes de imprimir este mensaje, asegúrese que es indispensable. >>>> ¡Proteger el medio ambiente también está en sus manos! <<<<

El servicio de correo itfip.edu.co es soportado tecnológicamente por ©Google y ofrecido por la Institución de Educación Superior – ITFIP de manera gratuita a toda la población ITFIP (Estudiantes, Egresados, Administrativos, inscritos, docentes y funcionarios) . Los contenidos, textos, imágenes, archivos y puntos de vista enviados en este mensaje son responsabilidad exclusiva del remitente y no reflejan ni comprometen oficialmente a la institución. No se autoriza el uso de esta herramienta para el intercambio de correos masivos, cadenas o spam, ni de mensajes ofensivos, de carácter político, sexual o religioso, con fines de lucro, con propósitos delictivos o cualquier otro mensaje que se considere indebido o que vaya en contra de la Ley.

MATEO BOHORQUEZ

unread,
Sep 11, 2015, 2:51:51 AM9/11/15
to Django users
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!

Reply all
Reply to author
Forward
0 new messages