I have two models:
callrecords
and
callbackrequest
Callrecords stores details of a customer.
Callackrequest stores dates and times of when we need to call the
customer back
So, if a customer calls we create a record in callrecords. The
callrecords admin interface also has
inlines = [CallBackInline]
This means the user can enter customer details for the callrecords
data as well as call back requests within the same page.
Now, the list_display for callrecords uses a callable to fetch the
last callback record (based on date of call back required):
# next_call_back_due will return the maximum date/time for any
callbacks that exist against the customer
def next_call_back_due(self, obj):
# max_call_record =
CallBackRequest.objects.filter(CallRecord.id =
obj.id).filter(call_back_date=CallBackRequest.objects.filter(CallRecord.id=obj.id).aggregate(Max('call_back_date'))
['call_back_date__max'])
# callback_date = max_call_record.call_back_date
call_records =
CallBackRequest.objects.filter(CallRecord=obj.id).order_by('-
call_back_date')
if call_records.count() > 0:
return call_records[0].call_back_date
else:
return None
# return callback_date
list_display = ('number', 'call_date', 'call_back_required',
'next_call_back_due')
the problem is, I really, really need the next_call_back_due date to
be sortable for the user - or at least if it can't be sortable by the
user, then the entire list should be ordered based on the
next_call_back_date.
I have tried a few things, including:
next_call_back_due.admin_order_field = 'call_back_date'
But that doesn't work.
This feature is really important for the users so any help would be
hugely appreciated.
Snipped of the models:
class CallBackRequest(models.Model):
CallRecord = models.ForeignKey(CallRecord, null=True)
call_back_date = models.DateTimeField(null=True, blank=True)
user = models.ForeignKey(User, null=True, blank=True)
class CallRecord(models.Model):
number = models.CharField(max_length=18, help_text="Please set to
the CLI of the premise <BR> where Broadband is to be provided.")
call_date = models.DateTimeField(auto_now=True)
call_back_required = models.BooleanField(blank=True, default=True)
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.