from tastypie.resources import ModelResource

from models import Station


class StationResource(ModelResource):
    class Meta:
        allowed_methods = ['get']
        queryset = Station.objects.all()
        resource_name = 'station'


from tastypie.resources import ModelResource

from models import Station, Update


class StationResource(ModelResource):
    def dehydrate(self, bundle):
        update = Update.objects.filter(station__id=bundle.data['id']).latest()
        bundle.data['nb_bikes'] = update.nb_bikes
        bundle.data['nb_empty_docks'] = update.nb_empty_docks
        return bundle

    class Meta:
        allowed_methods = ['get']
        queryset = Station.objects.all()
        resource_name = 'station'


Include the number of available bikes and docks from the latest update.
Include the number of available bikes and docks from the latest update.
