我正在使用tastepie,并且创建了我的第一个资源。但是我该怎么做:
用户名在 URL 上传递,在帖子上我想在保存之前“做一些事情”。美味派有这个方法吗?
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)