vendredi 11 septembre 2015

Django Rest framework pagination by choices

I have pagination problem. My api has a model product which contains a field which has 5 choices.

I have already entered 30 entries in product each choices has 6 entries, page size which I've set is 5, my requirement is if at first I call 127.0.0.1:8000/api/product/ I want 1 entry from each choice, no matter whether first page has only entries on choice 1.

I'm not sure this has to be done through pagination or filtering but I'm unable to figure it out.

class Product(models.Model):
    item_category_choices = (('MU','Make Up'), ('SC','Skin Care'),   ('Fra','Fragrance'), ('PC','Personal Care'),('HC','Hair Care'))
    item_category = models.CharField(max_length=20,choices = item_category_choices)

now on hitting url /api/product I need a response something like

{"count":30,"next":"127.0.0:8000/api/product/?page=2","previous":null,"results":[{"id":1,"item_category":'Personal Care',},{"id":2,"item_category":'Hair Care'},{"id":3,"item_category":MakeUp},{"id":4,"item_category":"SkinCare},{"id":5,"item_category":"'Fragrance"}}]}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire