0
私はdjangoで新しく、オブジェクトのページ付けに少し問題があります。djangoのページネーション、ListAPIView
私のモデル:
class FacebookBien(models.Model):
uid = models.IntegerField(primary_key=True)
ref_agence = models.IntegerField()
loyer = models.FloatField()
prix = models.FloatField()
ville = models.CharField(max_length=200)
code_postal = models.CharField(max_length=200)
ref_type_bien = models.IntegerField()
surface_totale = models.FloatField()
source = models.CharField(max_length=200)
nombre_de_pieces = models.IntegerField()
date_modification = models.DateTimeField()
class Meta:
managed = False
# db_table = 'public\".\"bien_recherche'
db_table = 'recette_facebook\".\"vue_facebook_bien_recherche'
私の見解:
class BienAgence(generics.ListAPIView):
queryset = FacebookBien.objects
pagination_class = SmallPagesPagination
def get(self, request, *args, **kwargs):
res = request.GET
if FacebookBien.objects.filter(ref_agence=int(kwargs['ref_agence'])).exists():
toto = self.queryset.filter(ref_agence=int(kwargs['ref_agence']))
if (res['type'] == 'bien'):
toto = toto.filter(prix__gte=int(res['p_mini']))
toto = toto.filter(prix__lte=int(res['p_maxi']))
if (res['prix'] == 'croissant'):
toto = toto.order_by('prix')
elif (res['prix'] == 'decroissant'):
toto = toto.order_by('-prix')
else:
toto = toto.filter(loyer__gte=int(res['p_mini']))
toto = toto.filter(loyer__lte=int(res['p_maxi']))
if (res['prix'] == 'croissant'):
toto = toto.order_by('loyer')
elif (res['prix'] == 'decroissant'):
toto = toto.order_by('-loyer')
if (res['surface'] == 'croissant'):
toto = toto.order_by('surface_totale')
elif (res['surface'] == 'decroissant'):
toto = toto.order_by('-surface_totale')
elif (res['date'] == 'croissant'):
toto = toto.order_by('date_creation')
elif (res['date' == 'decroissant']):
toto = toto.order_by('-date_creation')
toto = toto.filter(surface__gte=int(res['s_mini']))
toto = toto.filter(surface__lte=int(res['s_maxi']))
serializer = FacebookBienSerializer(toto, many=True) # noqa
return Response(serializer.data)
else:
return Response(None)
私pagination.py:
class SmallPagesPagination(PageNumberPagination):
page_size = 6
問題は、それはすべて6つのオブジェクトあたりで私を入れていないということですページ。私はgetメソッドをオーバーライドしない場合、それは動作します。
あなたは最高です;)とてもTHX –