Many to many relationship MongoDB
I'm trying to make a many to many relationship in mongodb using tastypie and mongoengine. But I'm having some difficulty.
I have players that can have various clubs and clubs that have multiple players.
What I'm doing is this:
class Club(mongoengine.Document):
ClubName = StringField()
class Player(mongoengine.Document):
PlayerName = StringField()
PlayerAge = IntField()
PlayerClub = fields.ListField(fields.ReferenceField(Club,
reverse_delete_rule=CASCADE, dbref=False))
---------------------------
class PlayerResource(resources.MongoEngineResource):
PlayerClub = fields.ReferencedListField(of='Rela.Resource.ClubResource',
attribute='PlayerClub', full=True, null=True)
class Meta:
queryset = Player.objects.all()
allowed_methods = ('get', 'post', 'put', 'delete')
list_allowed_methods = ['get', 'post','put', 'delete']
authorization = Authorization()
resource_name = 'Player'
class ClubResource(resources.MongoEngineResource):
class Meta:
queryset = Club.objects.all()
allowed_methods = ('get', 'post', 'put', 'delete')
list_allowed_methods = ['get', 'post','put', 'delete']
authorization = Authorization()
resource_name = 'Club'
Just know, when I query the players clubs they have, but how can players have the club?
I made myself clear? Someone can help me?
-- You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home