小编Aad*_*ikh的帖子

此数据库后端不支持 DISTINCT ON 字段

我正在使用 distinct 来获取不同的最新值,但它给了我一个错误:

此数据库后端不支持 DISTINCT ON 字段

views.py

class ReportView(LoginRequiredMixin, generic.TemplateView):
    template_name = 'admin/clock/report.html'

    def get_context_data(self, **kwargs):
        context = super(ReportView, self).get_context_data(**kwargs)
        context['reports'] =  TimesheetEntry.objects.filter(
                                  timesheet_jobs__job_company = self.request.user.userprofile.user_company,
                              ).distinct('timesheet_users')
        return context
Run Code Online (Sandbox Code Playgroud)

基本上我想查询TimesheetEntry模型,其中会有很多条目userUser内置模型中的外键。

所以我想用不同的用户查询,以便显示用户的最新条目。获取用户的最新条目对我来说非常重要。

models.py

class TimesheetEntry(models.Model):
    timesheet_users = models.ForeignKey(User, on_delete=models.CASCADE,related_name='timesheet_users')
    timesheet_jobs = models.ForeignKey(Jobs, on_delete=models.CASCADE,related_name='timesheet_jobs')
    timesheet_clock_in_date = models.DateField()
    timesheet_clock_in_time = models.TimeField()
Run Code Online (Sandbox Code Playgroud)

django django-templates django-models django-forms django-views

10
推荐指数
1
解决办法
1万
查看次数

“错误”:“invalid_client”django-oauth-toolkit

我正在使用带有 django-oauth-toolkit 的 django rest 框架。当我在本地主机上请求访问令牌时,它会为我提供访问令牌,如下所示

~/django_app$ curl -X POST -d "grant_type=password&username=<Your-username>&password=<your-password>" -u"<client-id>:<client-secret>" http://localhost:8000/o/token/
{"access_token": "8u92BMmeZxvto244CE0eNHdLYWhWSa", "expires_in": 36000, "refresh_token": "faW06KKK71ZN74bx32KchMXGn8yjpV", "scope": "read write", "token_type": "Bearer"}
Run Code Online (Sandbox Code Playgroud)

但是当我从实时服务器上托管的同一个项目中请求访问令牌时,它给我的错误是 invalid_client。

~/django_app$ curl -X POST -d "grant_type=password&username=<Your-username>&password=<your-password>" -u"<client-id>:<client-secret>" http://<your-domain>/o/token/ 
{
    "error": "invalid_client"
}
Run Code Online (Sandbox Code Playgroud)

我无法理解问题出在哪里。我搜索了很多,没有找到正确的答案。请告诉我该怎么做才能摆脱这个错误。

django django-rest-framework django-oauth

1
推荐指数
1
解决办法
2845
查看次数