【发布时间】:2013-06-12 12:45:08
【问题描述】:
我正在使用tastepie,我已经创建了我的第一个资源。但是我该怎么做:
用户名在 URL 上传递,在帖子中我想在保存之前“做一些事情”。 sweetpie 有这个方法吗?
class CommonMeta:
authentication = ApiKeyAuthentication()
authorization = UserObjectsOnlyAuthorization()
class SMSResource(ModelResource):
class Meta(CommonMeta):
queryset = Batch.objects.all()
resource_name = 'sms'
list_allowed_methods = ['get', 'post']
detail_allowed_methods = ['get']
型号:
content = models.TextField(validators=[validate_GSM_characters])
type = models.CharField(max_length=16, choices=TYPES,
default="Standard", null=True, blank=True)
priority = models.CharField(max_length=16, choices=PRIORITIES,
default="Normal", null=True, blank=True)
status = models.CharField(max_length=16, choices=STATUSES,
default="Pending", null=True, blank=True)
created = models.DateTimeField(auto_now_add=True, help_text="Shows when object was created.")
schedule = models.DateTimeField(blank=True, null=True, help_text="Shows when object was created.")
#FK
sender_name = models.ForeignKey(Originator)
user = models.ForeignKey(User)
【问题讨论】:
-
我们需要您的模型能够看到您所指的内容,您的问题并不清楚。
-
添加模型更新问题:)
-
目前还不清楚您要做什么。您能否包含您尝试发送到服务器的 Json 以及您尝试从 FK 创建的内容?