我们知道django 没有实现奇偶数的模板 ,所以我们自己写一个方法实现一个 类似奇偶数实现的效果
model.py 如下
class CustomerDetail(models.Model):
customer = models.ForeignKey(CustomerInfo)
contact_time= models.DateTimeField('联系日期',auto_now_add=False,db_index = True)
detail = models.TextField('联系详情',max_length=256,help_text='联系过程记录')
class Meta:
app_label = 'customer'
def __unicode__(self):
return self.detail
联系日期按倒序排列,然后左边或者右边跟上对应的联系详情,
try:
customerDetail=CustomerDetail.objects.filter(customer_id=cid).order_by('-contact_time')//按倒序得到一个查询集
customerDetail = list(customerDetail)//将查询集对象转为list对象,,然后我们可以用list一些方法了
for k in xrange(len(customerDetail))://xrange和range用法完全相同,只是