Django Rest 框架分析

发布于 2025-01-11 16:41:40 字数 713 浏览 3 评论 0原文

我已经在互联网上搜索了几个小时,但找不到答案,所以这是我最后的手段。

你们知道捕获用户发送了多少数据(假设对特定端点的获取请求)的最佳方法是什么吗?我还希望能够通过用户是在移动应用程序还是在网站(同一端点)上发送请求来区分。

我想过制作一个类似的模型:

class Visit(models.Model)
    product = models.ForeignKey('Product')
    user = models.ForeignKey('User')
    on_mobile = models.BooleanField(default='False')
    on_website = models.BooleanField(default='False')
    times_visit = models.IntegerField(default=0)

然后拍摄

if Visit.objects.get(user=self.request.user, product=self.kwargs['pk']).exists():
    times_visit += 1 
Visit.objects.create(user=self.request.user, product=self.kwargs['pk'])

你知道如何“检查”用户是否通过移动应用程序或网站发送它吗? 或者也许还有其他更好的方法? 我将感谢任何形式的帮助。

I've been searching the internet for hours and can't find answer so this is my last resort.

Do you guys have any idea what's the best way to capture how much a user has sent let's say get request for a specific endpoint? I also want it to be distinguishable by whether the user sent a request on a mobile app or on a website (the same endpoint).

I thought about making a model something like:

class Visit(models.Model)
    product = models.ForeignKey('Product')
    user = models.ForeignKey('User')
    on_mobile = models.BooleanField(default='False')
    on_website = models.BooleanField(default='False')
    times_visit = models.IntegerField(default=0)

and shooting

if Visit.objects.get(user=self.request.user, product=self.kwargs['pk']).exists():
    times_visit += 1 
Visit.objects.create(user=self.request.user, product=self.kwargs['pk'])

Do you have any idea how "check" whether user sent it through mobile app or website?
Or maybe there is some other better way?
I would be thankful for any kind of help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

像极了他 2025-01-18 16:41:40

您应该解析用户代理。有一些库可以做到这一点。

我使用这个库。

https://pypi.org/project/user-agents/

You should parse user agent. There is some library for that.

I use this library.

https://pypi.org/project/user-agents/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文