我正在使用tastypie並創建了我的第一個資源。但我該如何做到以下幾點:Django API tastypie和FK POST
用戶名在URL上傳遞,在帖子上我想'保存'之前做'的東西'。 tastypie有這個方法嗎?
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)
我們需要你的模型能夠看到你指的是什麼,你的問題不是那麼清楚。 –
增加了模型更新的問題:) – GrantU
目前仍不清楚你想要做什麼。你可以包含你試圖發送給你的服務器的Json,以及你試圖從FK創建的東西嗎? –