Skip to content

Possible replacement of `nested_fields`

There are times where I want to set a nested field in another model, and have the reverse set. Currently I need to set this property in nested_fields of both models, which can be problematic if the models are in different packages

DjangoLDP supports a USER_NESTED_FIELDS for example in settings to extend the nested fields of the user model https://git.startinblox.com/djangoldp-packages/djangoldp-circle/blob/5421cfd5684cdfa05d2470f35e724f7aa402e956/djangoldp_circle/settings.py#L1

In https://git.startinblox.com/djangoldp-packages/djangoldp-circle/merge_requests/24/ the issue came up because I want DjangoLDP-Profile to have a nested_field for Circle, but only if DjangoLDP-Circle is installed. This could be achieved by implementing a clone of the user model solution, but it involves code duplication & isn't generalised

A generalised solution would mean being able to define a nested field for profile, from circle. I think simply doing this with some kind of reverse_nested_fields property would be confusing

This needs research, but it may be possible to base a solution on Manager from Django- where in the foreign key I am able to define related_name in Circle.profile and Profile has access to a manager with profile.circles.all()

It may be possible to automatically build a list of nested_fields on the model for all related objects from Django's Manager (although this just moves the issue when I want to exclude a nested field).. or alternatively to implement a kind of NestedFieldManager

This may be a solution for #248 (closed)