【问题标题】:Creating objects from ModelResources in Django Tastypie在 Django Tastypie 中从 ModelResources 创建对象
【发布时间】: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


    【解决方案1】:

    您是否阅读了“入门”文档?

    它解释了你在问什么;您只需要设置 URL 处理程序

    http://django-tastypie.readthedocs.org/en/latest/tutorial.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多