我是tryig从功能创建Oauth2应用程序。 AbstractApplication是处理client_id client secret
的模型,这是参考-https://django-oauth-toolkit.readthedocs.io/en/latest/models.html#oauth2_provider.models.AbstractApplication。
但这给了我错误-
如果value不为None并且不是isinstance(value, self.field.remote_field.model._meta.concrete_model):
AttributeError:'str'对象没有属性'_meta'
from django.shortcuts import render
from oauth2_provider.models import AbstractApplication
from django.shortcuts import render, redirect
import pdb
def CreateApplicationIdSecret(request):
# pdb.set_trace()
# company_name = request.user.userprofile.user_company.company_name
obj = AbstractApplication(
user = request.user,
client_type = 'public',
authorization_grant_type = 'client-credentials',
name = 'Added BY Func',
)
obj.save()
return redirect('dashboard')
答案 0 :(得分:0)
有效。我必须将AbstractApplication更改为Application。就是有经理,这就是为什么要给出错误
def CreateApplicationIdSecret(request):
# pdb.set_trace()
# company_name = request.user.userprofile.user_company.company_name
obj = Application(
user = request.user,
client_type = 'public',
authorization_grant_type = 'client-credentials',
name = 'Added BY Func',
)
obj.save()
return redirect('dashboard')
class Application(AbstractApplication):
objects = ApplicationManager()
class Meta(AbstractApplication.Meta):
swappable = "OAUTH2_PROVIDER_APPLICATION_MODEL"
def natural_key(self):
return (self.client_id,)