2011-02-04 34 views

回答

5

使用unique_together

content_type字段的任何組合和ID字段是用於一個對象的唯一標識符,因此1比1。

http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together

+1

我也有同樣的問題。使用unique_together強制關係在數據庫中的唯一性,但我仍然需要將其稱爲my_foreign_key.objects.all()[0]。有沒有什麼辦法像my_foreign_key那樣引用它,就像正常的OneToOne字段一樣? – duduklein 2012-01-13 14:44:28