2012-04-04 20 views
0

Ich versuche, die Profildaten in der UserResource hinzufügen, aber ich kann den Weg nicht finden, es zu tun.Tastypie - Profil als verschachtelte Ressource

gezwickt ich ein wenig den Code auf dem docs gefunden, wie folgt aus:

class UserResource(ModelResource): 
    profile = fields.ForeignKey(UserProfile, 'profile', full=True) 

    class Meta: 
     queryset = User.objects.all() 
     resource_name = 'user' 
     excludes = ['email', 'password', 'is_active', 'is_staff', 'is_superuser'] 

     #authentication = BasicAuthentication() 
     authorization = DjangoAuthorization() 

    def dispatch(self, request_type, request, **kwargs): 

     kwargs['profile'] = request.user.get_profile() 
     return super(UserResource, self).dispatch(request_type, request, **kwargs) 

Aber wird mir diesen Fehler geben:

error_message: Cannot resolve keyword 'profile' into field. Choices are: date_joined, email, first_name, groups, id, is_active, is_staff, is_superuser, last_login, last_name, logentry, password... 

Irgendeine Idee, wie diese zu lösen?

Danke!

Antwort

0

Zuerst würde ich sicherstellen, dass Sie eine ProfileResource und nicht nur ein Modell verwenden. Zweitens, dass User.profile in das Profil aufgelöst wird. Also vielleicht etwas wie:

class UserResource(ModelResource): 
    profile = fields.ForeignKey('myapp.api.resources.ProfileResource', 'profile', full=True) 

    class Meta: 
     queryset = User.objects.all() 
     resource_name = 'user' 
     excludes = ['email', 'password', 'is_active', 'is_staff', 'is_superuser'] 

     #authentication = BasicAuthentication() 
     authorization = DjangoAuthorization() 
Verwandte Themen