Django OneToOneField RelatedObjectDoesNotExist
2023-01-31
#python
#django
#english
This is most useful as the primary key of a model which “extends” another model in some way;but sometimes it may cause RelatedObjectDoesNotExist if the certain one doesn't exist.
Example
take a example from stackoverflow Django : OneToOneField - RelatedObjectDoesNotExist
it will be ok,if we only use Answer:
when it comes to Vote:
Solution
How to avoid this ? Of course,you can catch the error simply
Also, use
hasattr
insteadRefences
Django : OneToOneField - RelatedObjectDoesNotExist