class Customer(models.Model):
name = models.CharField(max_length=200)
time_categoty = models.IntegerField()
importance = models.IntegerField()
class Interaction(models.Model):
i_date = models.DateTimeField()
class Interaction_customer(models.Model):
interaction = models.ForeignKey(Interaction)
customer = models.ForeignKey(Customer)
假設:
c = Customer.objects.get(pk=1)
x = Interaction.objects.filter(interaction_person__person=c).latest('i_date').i_date
(即針對特定客戶最新的互動)
需要:名單所有的客戶,通過標準排序: time_category /(datetime.now() - X)* c.importance
請不要給我一個鏈接到djangoproject.com「額外」的,我很仔細地看過,但真的不知道如何實現它在我的情況。 (情況是艱苦的,一個星期沒有人可以幫助,Django的絕地被通緝) 任何有建設性的意見將不勝感激。 謝謝! //埃德
對不起,interaction_person__person = = interaction_customer__customer –
1.最好將計算保存在某個地方,以便於排序(沒有其他明確的方法可以做到這一點,而不會放棄某些效率)2.您的模型看起來像[ManyToMany with'through'](https ://docs.djangoproject.com/en/1.6/topics/db/models/#extra-fields-on-many-to-many-relationships)。我不知道這是否是'額外'的含義,如果不添加任何其他字段,我完全不瞭解您需要什麼Interaction_Customer。更好地直接鏈接它們 – yuvi
我已經刪除了所有與案例無關的字段,但真正的基礎只需要這樣的結構。 // Ed –