示例#1
0
    include = list(StatisticsBaseResource.include) + ['home_goals', 'guest_goals']


class PlayerResource(StatisticsBaseResource):
    model = Player
    include = list(StatisticsBaseResource.include) + ['team_name', 'goals', 'assists',
                                             'penalties', 'points']

class GoalResource(StatisticsBaseResource):
    model = Goal


class PenaltyResource(StatisticsBaseResource):
    model = Penalty


urlpatterns = patterns('',
    url(r'league$', ListSearchModelView.as_view(resource=LeagueResource)),
    url(r'league/(?P<pk>[^/]+)/$', MyInstanceModelView.as_view(resource=LeagueResource)),
    url(r'team$', ListSearchModelView.as_view(resource=TeamResource)),
    url(r'team/(?P<pk>[^/]+)/$', MyInstanceModelView.as_view(resource=TeamResource)),
    url(r'game$', ListSearchModelView.as_view(resource=GameResource)),
    url(r'game/(?P<pk>[^/]+)/$', MyInstanceModelView.as_view(resource=GameResource)),
    url(r'player$', ListSearchModelView.as_view(resource=PlayerResource)),
    url(r'player/(?P<pk>[^/]+)/$', MyInstanceModelView.as_view(resource=PlayerResource)),
    url(r'goal$', ListSearchModelView.as_view(resource=GoalResource)),
    url(r'goal/(?P<pk>[^/]+)/$', MyInstanceModelView.as_view(resource=GoalResource)),
    url(r'penalty$', ListSearchModelView.as_view(resource=PenaltyResource)),
    url(r'penalty/(?P<pk>[^/]+)/$', MyInstanceModelView.as_view(resource=PenaltyResource)),
)
    
示例#2
0
from djangorestframework.resources import ModelResource
from djangorestframework.views import ListOrCreateModelView
from events.models import Event, OsallistujatEvent, SportsEvent
from statistics.rest.views import ListSearchModelView, MyInstanceModelView

class BaseResource(ModelResource):
    """ Exclude only pk so that id is shown """
    exclude = ('pk')
    allow_unknown_form_fields = True


class EventResource(BaseResource):
    include = ('duration', 'url', )
    model = Event

class SportsEventResource(BaseResource):
    model = SportsEvent

class OsallistujatEventResource(BaseResource):
    model = OsallistujatEvent


urlpatterns = patterns('',
    url(r'event$', ListSearchModelView.as_view(resource=EventResource)),
    url(r'event/(?P<pk>[^/]+)/$', MyInstanceModelView.as_view(resource=EventResource)),
    url(r'sportsevent$', ListSearchModelView.as_view(resource=SportsEventResource)),
    url(r'sportsevent/(?P<pk>[^/]+)/$', MyInstanceModelView.as_view(resource=SportsEventResource)),
    url(r'oevent$', ListSearchModelView.as_view(resource=OsallistujatEventResource)),
    url(r'oevent/(?P<pk>[^/]+)/$', MyInstanceModelView.as_view(resource=OsallistujatEventResource)),
)