I have 2 tables as:-
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
I want to access packages in the admin panel in a listview with following properties shown:-
list_display('agent_name', 'date_of_inquiry', ##########) Note: the ##############field should be status of the recent followup of the same package.
How can this be achieved?? Would be grateful for your answer.
You can define a function in the model inside class Package. Since you need to know the status you can find status of the recent follow ups using
def get_status_name(self):
a = self.followup_set.latest('follow_up_date')
return a.status.status_name