python - For Django Rest Framework, what is the difference in use case for HyperLinkedRelatedField and HyperLinkedIdentityField? -
i've of course reviewed docs, wondering if more succinctly explain difference in use case , application between these fields. why 1 use 1 field on other? there difference between these fields onetoone relationship?
you use hyperlinkedidentityfield
link object being serialized , hyperlinkedrelatedfield
link objects related 1 being serialized.
so one-to-one relationship, foreign key relationship, many-to-many relationship , else involving relationships (in django models), want use hyperlinkedrelatedfield
. time hyperlinkedrelatedfield
used url
field can include on serializer point current object.
in django rest framework 3.0.0, there only 2 differences between hyperlinkedrelatedfield
, hyperlinkedidentityfield
.
- the
source
automatically set*
(the current object) - it set
read_only=true
, can't changed
which means setting hyperlinkedrelatedfield
properties exactly same having hyperlinkedidentityfield
.
in older versions of django rest framework (before 3.0.0), hyperlinkedidentityfield
used dedicated field resolving url current object. accepted slightly different set of parameters , not subclass of hyperlinkedrelatedfield
.
Comments
Post a Comment