示例#1
0
        class Book(Resource):
            isbn = fields.CharField(primary_key=True)
            title = fields.CharField()
            author = fields.ToOneField('author', Author, get_author_id)

            class Meta:
                list = r'^book/$'
                item = r'^book/(?P<isbn>\d)$'
                client = self.client
示例#2
0
class Subscription(Resource):
    VENDOR_CHOICES = (
        ('smartfocus', 'Smart Focus'),
    )
    id = fields.IntegerField(primary=True, editable=False)
    profile = fields.ToOneField('profile', Profile)
    vendor_slug = fields.CharField(required=True, choices=VENDOR_CHOICES)
    vendor_name = fields.CharField(editable=False)
    enabled = fields.BooleanField(default=True)

    created_by = fields.CharField(editable=False)
    created_at = fields.CharField(editable=False)
    modified_by = fields.CharField(editable=False)
    modified_at = fields.CharField(editable=False)

    class Meta:
        resource_name = 'subscription'
        list = r'^subscriptions/$'
        item = r'^subscriptions/(?P<id>\d)/$'
        client = profiles_client
示例#3
0
        class Book(Resource):
            some_class_attribute = 'foobar'

            isbn = fields.CharField(primary_key=True)
            title = fields.CharField()
            author = fields.ToOneField('author', Author, get_author_id)

            objects = BookManager()

            class Meta:
                resource_name = 'book'
                list = r'^book/$'
                item = r'^book/(?P<isbn>\d)$'
                client = self.client

            def __init__(self, *args, **kwargs):
                self.some_instance_attribute_before_init = 'foobar'
                super(Book, self).__init__(*args, **kwargs)
                self.some_instance_attribute_after_init = 'foobar'

            def get_title(self):
                return self.title.title()