Issue
Title. I'm trying to access the on_delete
argument of the field "org" here:
class OrgLocation(models.Model):
org = models.OneToOneField(
Org, primary_key=True, on_delete=models.CASCADE, blank=True
)
And I'm trying to access it with:
OrgLocation._meta.get_field("org").on_delete
But when I run this, I get an attribute error:
AttributeError: 'OneToOneField' object has no attribute 'on_delete'
Trying to access primary_key
works just fine though (and same for blank
). Not sure what's going on. Any suggestions?
Solution
You may need to use the remote_field
attribute on the field to access the on_delete
attribute, e.g.
OrgLocation._meta.get_field("org").remote_field.on_delete
Answered By - A. J. Parr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.