0
當我提交我的表單我有一個獨特的設置爲我的領域,所以我得到這樣的:唯一字段返回詳細視圖提交
擁有這個全名,國家和出生日期已經存在
如何將它發送給現存的詳細視圖?
class Person(models.Model):
full_name = models.CharField(
max_length=50,
)
country = models.ForeignKey(
Country,
default='FIXED',
)
date_of_birth = models.DateField(
null=True,
)
def __unicode__(self):
return self.full_name
class Meta:
unique_together = (("full_name", "country", "date_of_birth"),)
@models.permalink
def get_absolute_url(self):
return ("checker:detail",(), {
"pk": self.pk
})
Views.py
class PersonTest(CreateView):
model = Person
class PersonTestDetail(DetailView):
model = Person
什麼,什麼時候「用戶」進入這個? @DanielRoseman – JamesJGarner 2014-10-18 20:47:19
人,不管。重點在於你正在使用創建一個新視圖的視圖,然後抱怨你正在獲得唯一性錯誤。只是不要創建一個新的。 – 2014-10-18 20:50:30
但是,如果它不存在,我希望它創建對象?如果我不應該使用CreateView,我應該使用什麼? @DanielRoseman – JamesJGarner 2014-10-18 20:52:01