2013-08-07 6 views
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 ', #########) 참고 : ############ 필드는 동일한 패키지의 최근 후속 조치의 상태 여야합니다.

어떻게 달성 할 수 있습니까 ?? 당신의 대답에 감사 할 것입니다.

답변

1

클래스 패키지 안에있는 모델에서 함수를 정의 할 수 있습니다. 상태를 알아야하기 때문에 최근 후속 조치 상태를 확인할 수 있습니다.

def get_status_name(self): 
    a = self.followup_set.latest('follow_up_date') 
    return a.status.status_name 
+0

감사합니다. –