Wednesday, January 2, 2019

Re: OneToOneField value must be a model instance, not a value?

From official documentation "to_field is the field on the related object that the relation is to. By default, Django uses the primary key of the related object. If you reference a different field, that field must have unique=True." May be read it once, you will get some clearance.
I didn't quite understand your use-case though. Can you explain it, which field are you using OneToOneField for and why?


On Wednesday, 2 January 2019 21:57:09 UTC+5:45, regtech wrote:
Hello everyone!
I am a junior who is first using OneToOneField, I found that the value which is giving to the field only could be a instance of the related model, can't be a value of the field which is specifed by the "to_field" ( else django will raise excption ).
In the other word, "to_field" does not make effect, django performing OneToOneField use PK.
I feel incomprehension and it makes me trouble on working.
Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6b8ccd34-b703-49c6-ad61-d40a3a6e2e9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment