I have three models
class Customer(models.Model):
created = models.DateTimeField(auto_now_add=True)
# some other fields, which don't matter
class ActivityStatus(models.Model):
created = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=5)
class Activities(models.Model):
created = models.DateTimeField(auto_now_add=True)
status = models.ForeignKey(ActivityStatus)
planned_execution_date = models.DateField()
also I have two them in admin
class CustomerAdmin(admin.ModelAdmin):
fields = () # doesn't matter really
list_display() # doesn't matter really
class ActivityAdmin(admin.ModelAdmin):
fields = () # doesn't matter really
list_display() # doesn't matter really
I want to add custom field (last_activity_planned_date) to be displayed and sorted on changelist_view of CustomerAdmin. Here is the condition: - show planned execution date of latest activity of Customer but only if this activity has status_id = 2. Otherwise show nothing
Example 1
Customer 1 has 2 activities - the latest has status_id = 2 and planned_execution_date = 2017-09-17
changelist_view:
|id|last_activity_planned_date|
|1|2017-09-17|
Example 2
Customer 1 has 2 activities - the latest has status_id = 3 and planned_execution_date = 2017-09-27
|id|last_activity_planned_date|
|1|null|