【发布时间】:2013-12-16 17:16:16
【问题描述】:
我无法理解 TastyPie ModelResource 和 Django Model 之间的联系。我看过食谱,但无法理解。
我有一个NotificationData 类,其中每个实例都属于一个 Django 用户(使用 ForeignKey)。
我只想要 CRUD NotificationData 对象的经过身份验证的用户,这将通过本机应用程序完成。我使用 oauth2 进行身份验证,因此您可以假设每个请求都将使用带有访问令牌的身份验证标头发送。
如何使用NotificationDataResource 为经过身份验证的用户创建NotificationData 对象?我如何获得该用户的NotificationData 对象列表?
models.py:
class NotificationData(models.Model):
user = models.ForeignKey(User)
notification = models.OneToOneField(Notification)
shortcut = models.CharField(max_length=200)
api.py:
class NotificationDataResource(ModelResource):
class Meta:
queryset = NotificationData.objects.all()
resource_name = 'notification_data'
authorization = DjangoAuthorization()
authentication = OAuth20Authentication()
【问题讨论】:
标签: python django oauth-2.0 tastypie