api.py 1.3 KB
Newer Older
Guyzmo's avatar
Guyzmo committed
1
2
3
#from django.contrib.auth.models import User
from tastypie import fields
from tastypie.authorization import DjangoAuthorization
4
5
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
from bt.models import Violation, Operator
Guyzmo's avatar
Guyzmo committed
6
7
8
9
10
11
12
13


#class UserResource(ModelResource):
#    class Meta:
#        queryset = User.objects.all()
#        resource_name = 'auth/user'
#        excludes = ['email', 'password', 'is_superuser']

14
15
16
17
18
19
20
21
22
23
24
25
class OperatorResource(ModelResource):

    class Meta:
        queryset = Operator.objects.all()
        list_allowed_methods = ['get', 'post']
        detail_allowed_methods = ['get', 'post', 'put', 'delete']
        resource_name = 'operators'
        authorization = DjangoAuthorization()
        filtering = {
            'name': ALL,
        }

Guyzmo's avatar
Guyzmo committed
26
27

class APIResource(ModelResource):
28
    operator = fields.ForeignKey(OperatorResource, 'operator_ref')
Guyzmo's avatar
Guyzmo committed
29
30
31
32
33
34
35
36
37
38
#    user = fields.ForeignKey(UserResource, 'user')

    class Meta:
        queryset = Violation.objects.all()
        list_allowed_methods = ['get', 'post']
        detail_allowed_methods = ['get', 'post', 'put', 'delete']
        resource_name = 'violations'
        authorization = DjangoAuthorization()
        filtering = {
            'country': ALL,
39
            'operator_ref': ALL_WITH_RELATIONS,
Guyzmo's avatar
Guyzmo committed
40
41
            'activationid': ALL,
        }