内联为list_filter

时间:2012-08-02 14:09:05

标签: python django django-admin

我有以下代码:

admin.py

from django import template
from django.shortcuts import render_to_response
from django.contrib import admin
from models import *
from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin
from django.contrib.auth.models import User
from actions import export_as_csv_action
from django import forms

class TelefoneIPInline(admin.StackedInline):
        model = MovimentoTelefoneIP
        extra = 1
        list_filter = ['cliente']

class TelefoneIPAdmin(admin.ModelAdmin):
        actions = [export_as_csv_action("Exportar para Excel", fields=['mac','modelo','fornecedor','get_clientes'])]
        list_display = ('mac', 'modelo','get_clientes')
        search_fields = ['mac']
        list_filter = ['modelo','fornecedor']

        def get_clientes(self, obj):
                clientes = [m.cliente for m in obj.movimentotelefoneip_set.all()]
                if clientes:
                        return (clientes[-1])
                else:
                        return "Selecione um local"
        get_clientes.short_description = 'Clientes'

        inlines = [TelefoneIPInline]

我使用get_clientes来显示list_display中内联类的字段,我可以在list_filter中使用ir吗?

这是我的models.py

# -*- coding: UTF-8 -*-
from django.db import models
from detalhamento.models import *
from django.contrib.auth.models import User

class TelefoneIP(models.Model):
        mac = models.CharField(max_length=12, help_text="Este campo deve ter 12 digitos", unique=True)
        modelo = models.ForeignKey(ModeloTelefoneIP)
        fornecedor = models.ForeignKey(Fornecedor)
        obs = models.TextField(max_length=500, null=True, blank=True)

class MovimentoTelefoneIP(models.Model):
        equipamento = models.ForeignKey(TelefoneIP)
        cliente = models.ForeignKey(Cliente)
        sentido = models.ForeignKey(sentido)
        nfentrada = models.IntegerField(verbose_name="Nota fiscal de entrada", null=True, blank=True)
        dataentrada = models.DateField(verbose_name="Data de entrada", null=True, blank=True)
        nfvenda = models.IntegerField(verbose_name="Nota fiscal de saída", null=True, blank=True)
        datavenda = models.DateField(verbose_name="Data de saída", null=True, blank=True)

我已经添加了导入。

0 个答案:

没有答案