From 46f1af7ab3ecc0eb05a4f855cf321d10ba735027 Mon Sep 17 00:00:00 2001 From: Calum Mackervoy <c.mackervoy@gmail.com> Date: Wed, 10 Jun 2020 17:06:03 +0000 Subject: [PATCH] update: defaults lookup_field to model meta setting --- djangoldp/views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/djangoldp/views.py b/djangoldp/views.py index e4dc7a11..1dd61ecf 100644 --- a/djangoldp/views.py +++ b/djangoldp/views.py @@ -250,6 +250,10 @@ class LDPViewSetGenerator(ModelViewSet): list_actions = {'get': 'list', 'post': 'create'} detail_actions = {'get': 'retrieve', 'put': 'update', 'patch': 'partial_update', 'delete': 'destroy'} + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.lookup_field = LDPViewSetGenerator.get_lookup_arg(**kwargs) + @classonlymethod def get_model(cls, **kwargs): '''gets the model in the arguments or in the viewset definition''' @@ -260,7 +264,8 @@ class LDPViewSetGenerator(ModelViewSet): @classonlymethod def get_lookup_arg(cls, **kwargs): - return kwargs.get('lookup_url_kwarg') or cls.lookup_url_kwarg or kwargs.get('lookup_field') or cls.lookup_field + return kwargs.get('lookup_url_kwarg') or cls.lookup_url_kwarg or kwargs.get('lookup_field') or \ + Model.get_meta(kwargs['model'], 'lookup_field', 'pk') or cls.lookup_field @classonlymethod def get_detail_expr(cls, lookup_field=None, **kwargs): -- GitLab