开发者

Accessing database objects in Django form cleaner

开发者 https://www.devze.com 2023-02-03 16:17 出处:网络
Is there a way to access the dat开发者_运维技巧abase object from the django form cleaner? Or at least the URL to which the form data was posted? If I can get the URL, I can query for the database obje

Is there a way to access the dat开发者_运维技巧abase object from the django form cleaner? Or at least the URL to which the form data was posted? If I can get the URL, I can query for the database object.

My use case is that, I have a form that should raise an error if the database object from which the form was generated is in some particular state.


Yes - take a look at self.instance from inside your form's clean method.

0

精彩评论

暂无评论...
验证码 换一张
取 消