mô hình đầu tiên:Django Tastypie: bài giá trị trong nhiều mô hình để một đơn Tastypie Resource
class Profile(models.Model):
username = models.CharField(
_('username'),
max_length=150,
unique=True,
help_text=_('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.'),
validators=[
validators.RegexValidator(
r'^[\[email protected]+-]+$',
_('Enter a valid username. This value may contain only '
'letters, numbers ' 'and @/./+/-/_ characters.')
),
],
error_messages={
'unique': _("A user with that username already exists."),
},
)
password = models.CharField(max_length=12, default='123456')
first_name = models.CharField(_('first name'), max_length=30, blank=True)
last_name = models.CharField(_('last name'), max_length=30, blank=True)
email = models.EmailField(_('email address'), blank=True)
date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
mô hình thứ hai:
class UserEbiz(models.Model):
user_id = models.ForeignKey('Profile')
password = models.CharField(max_length=12, default='123456')
Tastypie Resource:
class ProfileResources(ModelResource):
id = fields.CharField(attribute='id')
class Meta:
queryset = Profile.objects.all()
resource_name = 'profile'
filtering = {
"id": ALL,
}
Tôi muốn tạo một hàm có thể lưu giá trị cho cả hai bảng cùng một lúc bằng cách chỉ sử dụng một tài nguyên. Câu hỏi của tôi là làm thế nào để đăng giá trị vào các mô hình Profile và UserEbiz bằng cách sử dụng ProfileResources.
Tại sao bạn không tạo tài nguyên cho mô hình UserEbiz ...! – Satyajeet
Ok. Sau khi tạo tài nguyên cho mô hình UserEbiz, tôi nên làm gì cho bước tiếp theo. – nuriffah