Skip to content

Instantly share code, notes, and snippets.

@TarCV
Created June 4, 2018 10:54
Show Gist options
  • Save TarCV/03f35115e827c89cd19ab4df3cb8068d to your computer and use it in GitHub Desktop.
Save TarCV/03f35115e827c89cd19ab4df3cb8068d to your computer and use it in GitHub Desktop.
from django.db import models
class Match(models.Model):
roundlimit = models.IntegerField()
scorelimit = models.IntegerField()
class Score(models.Model):
match = models.ForeignKey(Match, on_delete=models.PROTECT)
name = models.CharField(max_length=30)
score = models.IntegerField()
from tastypie import fields
from tastypie.resources import ModelResource
from tastypie.authorization import Authorization
from results.models import Match, Score
class MatchResource(ModelResource):
scores = fields.ToManyField('results.api.resources.ScoreResource', 'score_set', full=True)
class Meta:
queryset = Match.objects.all()
allowed_methods = ['get', 'post']
authorization = Authorization()
class ScoreResource(ModelResource):
class Meta:
queryset = Score.objects.all()
allowed_methods = ['get']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment