Django - access m2m objects (or raw pks) from ``clean`` before model is saved
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.
精彩评论