开发者

Django - access m2m objects (or raw pks) from ``clean`` before model is saved

开发者 https://www.devze.com 2023-02-06 12:28 出处:网络
Of course you can\'t just use self.related_field.objects.all(), or you\'ll get a ...needs to have a primary key... error, but if I want to run custo开发者_运维知识库m validation inside of Model.clean,

Of course you can't just use self.related_field.objects.all(), or you'll get a ...needs to have a primary key... error, but if I want to run custo开发者_运维知识库m validation inside of Model.clean, there appears to be no way to access this data. Of course you can use Form.clean to do this, but I'm not always using forms.


What you are asking for is impossible - the M2M records cannot exist until the main object has a primary key value. There is no way to access the data because it does not exist.

0

精彩评论

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