alanjds / drf-nested-routers

Nested Routers for Django Rest Framework
https://pypi.org/project/drf-nested-routers/
Apache License 2.0
1.68k stars 160 forks source link

NestedHyperlinkedIdentityField with allowed lookup_field=None (OneToOne Relations) #210

Open gretkierewicz opened 3 years ago

gretkierewicz commented 3 years ago

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

c17r commented 3 years ago

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

gretkierewicz commented 3 years ago

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.