モデルがあるとしましょう:
class Ticket(models.Model):
client = models.ForeignKey(Client)
color = models.CharField(max_length=255)
def clean(self):
self.color = self.client.favorite_color
これを最新の Django (15 分前の SVN の先頭) で実行すると、 を選択せずに保存を押すとclient
、 (その部分の) DoesNotExist
clean メソッド内からエラーが発生します。self.client.favorite_color
モデルにはclient
属性が必要なので、カスタム検証の前にこれを処理する必要はありませんclean()
か?
私が読んでいるドキュメントは次のとおりです。http://docs.djangoproject.com/en/dev/ref/models/instances/#id1