0
tastypie我想與調用任何其它功能 在api.py 類UserResource(ModelResource)分配ID分配默認值: 類UserResource(ModelResource):Django的tastypie如何ID
class Meta:
collection_name="data"
queryset = User.objects.all()
resource_name = 'user'
authorization = Authorization()
def dehydrate(self, bundle):
bundle.data['user_id'] = "1" # want to call one function here
return bundle
但不工作和錯誤是
IntegrityError at /v0/user
(1048, "Column 'user_id' cannot be null")
我的模型代碼
class User(models.Model):
user_id = models.IntegerField(primary_key=True)
mobile_country_code = models.CharField(max_length=10L, blank=True)
mobile_no = models.CharField(max_length=15L)
email = models.CharField(max_length=75L, blank=True)
email_phone = models.CharField(max_length=75L, blank=True)
gcm_regid = models.TextField()
class Meta:
db_table = 'users'
如何調用一個函數獲取id從其他表
感謝名單爲我工作 – RahulG
很高興我能幫助! –