drf-nested-routers icon indicating copy to clipboard operation
drf-nested-routers copied to clipboard

NestedHyperlinkedIdentityField with allowed lookup_field=None (OneToOne Relations)

Open gretkierewicz opened this issue 4 years ago • 2 comments

Hi!

I would like to suggest some minor update for NestedHyperlinkedIdentityField in terms of OneToOne relations.

As there is no need of providing lookup_field in such scenario, allowing lookup_field=None field's kwarg could provide url just fine.

Example url patterns: /basic_resource/ /basic_resource/{basic_resource_lookup}/ /basic_resource/{basic_resource_lookup}/nested_OneToOne_resource/

As parent_lookup_kwargs pointing basic_resource_lookup would be declared in nested serializer - it is just enough to get exact instance of nested resource for each basic_recource

gretkierewicz avatar Feb 01 '21 16:02 gretkierewicz

For that particular use case, it doesn't seem like you'd use nested routers because a OneToOne isn't nested.

c17r avatar Feb 01 '21 17:02 c17r

Not sure how would you pass OneToOne resource's parent lookup. I'm building OneToOne relation in nested resource so it is even more complicated there.

Here is the pull request. Update for allowing to pass lookup_field=None #211

It should be fully back-compatible.

gretkierewicz avatar Feb 01 '21 17:02 gretkierewicz