jose-lpa / django-tracking-analyzer

User actions tracking and analytics for Django sites :bar_chart:
GNU General Public License v3.0
96 stars 32 forks source link

Support for Django Rest Framework Views #6

Open anniethiessen opened 6 years ago

anniethiessen commented 6 years ago

DRF views don't inherit from HttpRequest class. Is there a work around?

MAsifOfficial commented 4 years ago

@anniethiessen I discovered a work-around, might not be useful for you after 2 years but just putting it here so that someone from the future can use it. Instead of Tracker.objects.create_from_request(self.request, obj)

use

Tracker.objects.create_from_request(self.request._request, obj)

This will give you the underlying WSGIRequest object which works perfectly.

emranbm commented 4 years ago

@anniethiessen I discovered a work-around, might not be useful for you after 2 years but just putting it here so that someone from the future can use it. Instead of Tracker.objects.create_from_request(self.request, obj)

use

Tracker.objects.create_from_request(self.request._request, obj)

This will give you the underlying WSGIRequest object which works perfectly.

The workaround doesn't help. It faces another error:

'WSGIRequest' object has no attribute 'user_agent'