irfanpule / django-form-surveys

Django form survey is an application Django to easier create form survey and easy integrated for your project.
MIT License
56 stars 19 forks source link

Restrict surveys by role or by user #78

Closed xmnlab closed 7 months ago

xmnlab commented 7 months ago

Hi everyone!

first of all, this is a very nice and useful django project.

I would like to know if there is a way to restrict specific surveys by users or roles. if not, do you have any recommendation for extending this app in a way that I could do it?

All the best,

irfanpule commented 7 months ago

Hi @xmnlab

To restrict specific surveys by users or roles you can extending use views class. There will definitely be a lot of overriding.

for example on your project

from djf_surveys.views import SurveyListView

class NewSurveyListView(SurveyListView):
    def dispatch(self, request, *args, **kwargs):
        # your code to handle restrict roles
        return super().dispatch(request, *args, **kwargs)

or get specific data by user

from djf_surveys.views import SurveyListView

class NewSurveyListView(SurveyListView):
    def get_queryset(self):
        queryset = super().get_queryset()
        survey_by_user = queryset.filter(user=self.request.user)
        return survey_by_user

and many thing you can do.

xmnlab commented 7 months ago

great! thank you so much. I will try that! appreciate your quick response.