11
11
12
12
13
13
class UnionResource (ModelResource ):
14
- # clubs = fields.ToManyField('handball.api.ClubResource', 'clubs', full=True)
15
- managers = fields .ToManyField ('handball.api.PersonResource' , 'managers' )
16
-
17
14
class Meta :
18
15
queryset = Union .objects .all ()
19
16
allowed_methods = ['get' ]
@@ -30,7 +27,7 @@ def obj_create(self, bundle, request=None, **kwargs):
30
27
31
28
32
29
class DistrictResource (ModelResource ):
33
- union = fields .ForeignKey (UnionResource , 'union' , full = True )
30
+ union = fields .ForeignKey (UnionResource , 'union' )
34
31
35
32
class Meta :
36
33
queryset = District .objects .all ()
@@ -57,6 +54,7 @@ class Meta:
57
54
class ClubResource (ModelResource ):
58
55
district = fields .ForeignKey (DistrictResource , 'district' , full = True )
59
56
# teams = fields.ToManyField('handball.api.TeamResource', 'teams')
57
+ managers = fields .ToManyField ('handball.api.PersonResource' , 'managers' )
60
58
61
59
class Meta :
62
60
queryset = Club .objects .all ()
@@ -75,8 +73,9 @@ def obj_create(self, bundle, request=None, **kwargs):
75
73
76
74
class TeamResource (ModelResource ):
77
75
club = fields .ForeignKey (ClubResource , 'club' , full = True )
78
- league = fields .ForeignKey (LeagueResource , 'league' , full = True )
79
- players = fields .ManyToManyField ('handball.api.PersonResource' , 'players' , full = True )
76
+ players = fields .ManyToManyField ('handball.api.PersonResource' , 'players' )
77
+ coaches = fields .ManyToManyField ('handball.api.PersonResource' , 'coaches' )
78
+ managers = fields .ManyToManyField ('handball.api.PersonResource' , 'managers' )
80
79
81
80
class Meta :
82
81
queryset = Team .objects .all ()
@@ -97,7 +96,10 @@ def dehydrate(self, bundle):
97
96
class PersonResource (ModelResource ):
98
97
user = fields .OneToOneField (UserResource , 'user' , blank = True , null = True )
99
98
clubs = fields .ManyToManyField (ClubResource , 'clubs' )
100
- # teams = fields.ManyToManyField(TeamResource, 'teams')
99
+ clubs_managed = fields .ManyToManyField (ClubResource , 'clubs_managed' , blank = True )
100
+ teams = fields .ManyToManyField (TeamResource , 'teams' , blank = True )
101
+ teams_managed = fields .ManyToManyField (TeamResource , 'teams_managed' , blank = True )
102
+ teams_coached = fields .ManyToManyField (TeamResource , 'teams_coached' , blank = True )
101
103
102
104
class Meta :
103
105
queryset = Person .objects .all ()
@@ -106,12 +108,22 @@ class Meta:
106
108
excludes = ['activation_key' , 'key_expires' ]
107
109
filtering = {
108
110
'user' : ALL_WITH_RELATIONS ,
111
+ 'clubs' : ALL_WITH_RELATIONS ,
112
+ 'clubs_managed' : ALL_WITH_RELATIONS ,
113
+ 'teams' : ALL_WITH_RELATIONS ,
114
+ 'teams_managed' : ALL_WITH_RELATIONS ,
115
+ 'teams_coached' : ALL_WITH_RELATIONS ,
109
116
'first_name' : ['exact' ],
110
117
'last_name' : ['exact' ]
111
118
}
112
119
113
120
def dehydrate (self , bundle ):
114
121
bundle .data ['display_name' ] = str (bundle .obj )
122
+ # del bundle.data['clubs']
123
+ del bundle .data ['clubs_managed' ]
124
+ del bundle .data ['teams' ]
125
+ del bundle .data ['teams_managed' ]
126
+ del bundle .data ['teams_coached' ]
115
127
return bundle
116
128
117
129
0 commit comments