0

我有 2 张桌子:-

class Package(models.Model):

    '''Model to represent details of the packae booking'''
    date_of_inquiry = models.DateField(blank=True, null=True)
    agent_name = models.CharField(max_length=200, blank=True)
    type_of_booking = models.ForeignKey(TypeOfBooking, blank=True, null=True)
    no_of_pax = models.IntegerField(null=True)
    source_of_inquiry = models.CharField(max_length=100, blank=True)
    business_vendor = models.CharField(max_length=100, blank=True)
    travel_date = models.DateField(null=True, blank=True)
    reply_date = models.DateField(null=True, blank=True)
    client_name = models.CharField(max_length=500, blank=True)
    client_email = models.EmailField(blank=True)
    client_contacts = models.CharField(max_length=200, blank=True)
    inquiry_assigned_to = models.ForeignKey(User, blank=True, null=True)

    def __unicode__(self):
        return str(self.date_of_inquiry) + "  " + self.client_name


class FollowUp(models.Model):

    '''Model to represent follow-ups of the clients'''
    follow_up_date = models.DateField(blank=True, null=True)
    remarks = models.TextField(max_length=500, blank=True)
    package = models.ForeignKey(Package, blank=True, null=True)
    status_inquiry = models.ForeignKey(StatusInquiry, blank=True, null=True)
    followup_done_by = models.ForeignKey(User, blank=True, null=True)

    def __unicode__(self):
        return str(self.follow_up_date) + " " + self.status_inquiry.status_name

我想在列表视图中访问管理面板中的软件包,并显示以下属性:-

list_display('agent_name', 'date_of_inquiry', ##########) 注意:##############字段应该是同一个包最近跟进的状态.

这怎么可能实现??将不胜感激您的回答。

4

1 回答 1

1

您可以在类包内的模型中定义一个函数。由于您需要知道状态,因此您可以使用以下方式找到最近跟进的状态

def get_status_name(self):
    a = self.followup_set.latest('follow_up_date')
    return a.status.status_name
于 2013-11-13T07:13:10.300 回答