2

より多くの値を保持するために auth_user と別のカスタム モデルを使用しました

私のモデルは次のとおりです

class ExProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    cell_phone = models.CharField(max_length=200, blank=True)
    api_key=      models.CharField(max_length=200, blank=True)
    termination_date=models.DateField()
    picture=models.ImageField(upload_to='profile',blank=True)
    homeAddress=models.CharField(max_length=200,blank=True)
    homeNumber=models.CharField(max_length=200,blank=True)

auth_user と Exprofile の両方を使用する登録目的の REST API を作成したいのですが、直面している問題は、tastypie でリソースを設計して、両方のテーブルに一緒に挿入できるようにする方法です。

資力

class UserResource(ModelResource):
        class Meta:
            queryset = User.objects.all()
            resource_name = 'user'
            excludes = ['email', 'password', 'is_active', 'is_staff', 'is_superuser']
            filtering = {
               }
            #authorization = Authorization()
            #authentication=MyAuthentication()


class ProfileResource(ModelResource):

        username = fields.CharField(attribute='user__username', readonly=True)
        class Meta:
             queryset =ExProfile.objects.select_related('User')
             resource_name = 'entry'
             #authorization = Authorization()
             #authentication = MyAuthentication()
             fields = ['username','api_key','email','homeAddress']
             filtering = {
                 'username':ALL,
                 'api_key': ALL,
                 'homeAddress': ALL,
                 'email': ALL,
                 'query': ['icontains',],
                 }

投稿データ........

curl -v -H "Content-Type: application/json" -X POST --data '{"username":"test", "password":"123456", "entry":{"cell_phone":"somewhere","api_key":"7378237827827".....}}' http://myhost:8000/api/user/
4

0 に答える 0