我有一個非常基本的聯繫模式。該模型有以下字段:查詢過濾器中的上下文?
class Entry(models.Model):
name = models.CharField(max_length=64, unique=False)
organization = models.CharField(max_length=100, unique=False, blank=True, null=True)
team = models.CharField(max_length=64, unique=False, blank=True, null=True)
position = models.CharField(max_length=64, unique=False, blank=True, null=True)
address = models.CharField(max_length=130, unique=False, blank=True, null=True)
...
def __unicode__(self):
return u'%s' % self.name
我有不同的模板來顯示/編輯單個條目。我想完成以下內容。 查看單個記錄時,我希望用戶能夠單擊「組織」並將其重定向到一個模板,該模板列出該組織中數據庫中的所有現有記錄。我已經構建了模板,但我不確定視圖代碼。
我覺得它應該是這樣的東西,但我不認爲這是合法的。
def display_organization(request):
records = Entry.objects.filter(organization__exact=Context)
t = get_template('org_list.html')
html = t.render(Context({'records': records}))
return HttpResponse(html)
任何人都可以協助嗎?
拋出類型錯誤。 「 」display_organization()只需要2個參數(給出1)「 似乎不喜歡的語法。謝謝。 – kjarsenal 2009-12-14 19:23:16
您必須對URL進行相應的更改才能生效。您如何期望您的模板知道*要使用哪個組織? – jcdyer 2009-12-14 21:14:08