27๐
โ
You need to override get_object()
, not get_queryset()
for detail views. You still want the permission checking so I suggest going through the source. First remove your get_queryset()
method then try this for starters:
# inside OrganisationDetail
queryset = Organisation.objects.all()
def get_object(self):
queryset = self.filter_queryset(self.get_queryset())
# make sure to catch 404's below
obj = queryset.get(pk=self.request.user.organisation_id)
self.check_object_permissions(self.request, obj)
return obj
๐คmunsu
1๐
If you are using mixins, change the lookup_field to the right one
class OrganisationDetail(mixins.RetrieveModelMixin, mixins.UpdateModelMixin,generics.GenericAPIView):
serializer_class = OrganisationDetailSerializer
lookup_field = 'members'
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)
def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)
def patch(self, request, *args, **kwargs):
return self.partial_update(request, *args, **kwargs)
๐คKishan K
- Adding a "through" table to django field and migrating with South?
- Django CharField without empty strings
- Decoder JPEG not available error when following Django photo app tutorial
- Django-registration, force unique e-mail
- Verbose_name for a model's method
0๐
My solution was to change a parameter, it had id, instead of pk in the path that should only show one element, when changing it to <int: pk>, it has worked wonderfully
from the django.urls import path
from rest_framework.urlpatterns import format_suffix_patterns
from posts import views
urlpatterns = [
path ('posts /', views.PublicationList.as_view ()),
path ('posts / <int: id> /', views.Publication_detail.as_vi`enter code here`ew ()),
]
urlpatterns = format_suffix_patterns (urlpatterns)
๐คAllisLove
- Coverage in parallel for django tests
- Uwsgi segmentation fault when serving a django application
- Send email to bcc and cc in django
Source:stackexchange.com