from nap import fields, api from nap.models import ModelPublisher from .models import Choice from .serialiser import PollSerialiser class PollPublisher(models.ModelPublisher) api_name = 'poll' serialiser = PollSerialiser() api.register('api', PollPublisher)
def test_register(self): self.assertTrue(len(api.APIS.keys()) == 0) api.register('v1', PollPublisher) self.assertTrue(len(api.APIS.keys()) == 1) self.assertTrue(len(api.patterns()) == 1)
from nap.models import ModelSerialiser from nap.serialiser import Serialiser from nap import fields, api from .models import Choice class ChoiceSerialiser(ModelSerialiser): class Meta: model = Choice exclude = ('poll,') class PollSerialiser(Serialiser): api_name = 'poll' question = fields.Field() published = fields.DateTimeField('pub_date') choices = fields.ManySerialiserField(serialiser=ChoiceSerialiser()) api.register('api', PollSerialiser)