@@ -59,7 +59,8 @@ class Meta:
59
59
class ClubResource (ModelResource ):
60
60
district = fields .ForeignKey (DistrictResource , 'district' , full = True )
61
61
# teams = fields.ToManyField('handball.api.TeamResource', 'teams')
62
- managers = fields .ToManyField ('handball.api.PersonResource' , 'managers' )
62
+ # members = fields.ToManyField('handball.api.PersonResource', 'members', blank=True)
63
+ managers = fields .ToManyField ('handball.api.PersonResource' , 'managers' , blank = True )
63
64
64
65
class Meta :
65
66
queryset = Club .objects .all ()
@@ -75,11 +76,15 @@ def obj_create(self, bundle, request=None, **kwargs):
75
76
bundle .data ['managers' ] = ['/handball/api/v1/person/' + str (request .user .get_profile ().id ) + '/' ]
76
77
return super (ClubResource , self ).obj_create (bundle , request )
77
78
79
+ def dehydrate (self , bundle ):
80
+ del bundle .data ['managers' ]
81
+ return bundle
82
+
78
83
79
84
class TeamResource (ModelResource ):
80
85
club = fields .ForeignKey (ClubResource , 'club' , full = True )
81
- players = fields .ManyToManyField ('handball.api.PersonResource' , 'players' )
82
- coaches = fields .ManyToManyField ('handball.api.PersonResource' , 'coaches' )
86
+ # players = fields.ManyToManyField('handball.api.PersonResource', 'players')
87
+ # coaches = fields.ManyToManyField('handball.api.PersonResource', 'coaches')
83
88
managers = fields .ManyToManyField ('handball.api.PersonResource' , 'managers' )
84
89
85
90
class Meta :
@@ -99,12 +104,12 @@ def dehydrate(self, bundle):
99
104
100
105
101
106
class PersonResource (ModelResource ):
102
- user = fields .OneToOneField (UserResource , 'user' , blank = True , null = True )
103
- clubs = fields .ManyToManyField (ClubResource , 'clubs' )
107
+ user = fields .OneToOneField (UserResource , 'user' , blank = True , null = True , related_name = 'handball_profile' )
108
+ # clubs = fields.ManyToManyField(ClubResource, 'clubs', blank=True )
104
109
clubs_managed = fields .ManyToManyField (ClubResource , 'clubs_managed' , blank = True )
105
- teams = fields .ManyToManyField (TeamResource , 'teams' , blank = True )
110
+ # teams = fields.ManyToManyField(TeamResource, 'teams', blank=True)
106
111
teams_managed = fields .ManyToManyField (TeamResource , 'teams_managed' , blank = True )
107
- teams_coached = fields .ManyToManyField (TeamResource , 'teams_coached' , blank = True )
112
+ # teams_coached = fields.ManyToManyField(TeamResource, 'teams_coached', blank=True)
108
113
109
114
class Meta :
110
115
queryset = Person .objects .all ()
@@ -113,22 +118,30 @@ class Meta:
113
118
excludes = ['activation_key' , 'key_expires' ]
114
119
filtering = {
115
120
'user' : ALL_WITH_RELATIONS ,
116
- 'clubs' : ALL_WITH_RELATIONS ,
121
+ # 'clubs': ALL_WITH_RELATIONS,
117
122
'clubs_managed' : ALL_WITH_RELATIONS ,
118
- 'teams' : ALL_WITH_RELATIONS ,
123
+ # 'teams': ALL_WITH_RELATIONS,
119
124
'teams_managed' : ALL_WITH_RELATIONS ,
120
- 'teams_coached' : ALL_WITH_RELATIONS ,
125
+ # 'teams_coached': ALL_WITH_RELATIONS,
121
126
'first_name' : ['exact' ],
122
127
'last_name' : ['exact' ]
123
128
}
129
+ always_return_data = True
124
130
125
131
def dehydrate (self , bundle ):
126
132
bundle .data ['display_name' ] = str (bundle .obj )
133
+
134
+ bundle .data ['clubs' ] = []
135
+ resource = ClubResource ()
136
+ for membership in ClubMemberRelation .objects .filter (member = bundle .obj ):
137
+ clubBundle = resource .build_bundle (obj = membership .club , request = bundle .request )
138
+ bundle .data ['clubs' ].append (resource .full_dehydrate (clubBundle ))
139
+
127
140
# del bundle.data['clubs']
128
- del bundle .data ['clubs_managed' ]
129
- del bundle .data ['teams' ]
130
- del bundle .data ['teams_managed' ]
131
- del bundle .data ['teams_coached' ]
141
+ # del bundle.data['clubs_managed']
142
+ # del bundle.data['teams']
143
+ # del bundle.data['teams_managed']
144
+ # del bundle.data['teams_coached']
132
145
return bundle
133
146
134
147
@@ -189,6 +202,16 @@ class Meta:
189
202
include_resource_uri = False
190
203
191
204
205
+ class ClubMemberRelationResource (ModelResource ):
206
+ club = fields .ForeignKey (ClubResource , 'club' , full = True )
207
+ member = fields .ForeignKey (PersonResource , 'member' , full = True )
208
+
209
+ class Meta :
210
+ queryset = ClubMemberRelation .objects .all ()
211
+ authorization = Authorization ()
212
+ authentication = Authentication ()
213
+ always_return_data = True
214
+
192
215
"""
193
216
Non-resource api endpoints
194
217
"""
0 commit comments