Skip to content

Instantly share code, notes, and snippets.

@aitzol
Created September 18, 2014 10:51
Show Gist options
  • Save aitzol/1ca7d2fe8f3f15d345eb to your computer and use it in GitHub Desktop.
Save aitzol/1ca7d2fe8f3f15d345eb to your computer and use it in GitHub Desktop.
models.py
class TribualUserInTribe(models.Model):
user = models.ForeignKey(TribualUser)
tribe = models.ForeignKey(Tribe)
#Unique together
played = models.IntegerField(default=0)
elo = models.IntegerField(default=2000,db_index=True)
k = models.IntegerField(default=40)
win = models.IntegerField(default=0)
loose = models.IntegerField(default=0)
draw = models.IntegerField(default=0)
def get_tribe_id(self):
return self.tribe.id
def get_tribe_title(self):
return self.tribe.title
serializer.py
class TribualUserInTribeSerializer(serializers.ModelSerializer):
id = serializers.Field(source='get_tribe_id')
title = serializers.Field(source='get_tribe_title')
class Meta:
model = TribualUserInTribe
fields = ('id','title','elo')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment