mirror of
https://github.com/pinry/pinry.git
synced 2025-11-13 16:45:41 +01:00
Started the creation of an API and implemented infinite scroll. Closes issue #7.
This commit is contained in:
21
pinry/api/views.py
Normal file
21
pinry/api/views.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from django.utils import simplejson
|
||||
from django.http import HttpResponse
|
||||
|
||||
from pinry.pins.models import Pin
|
||||
|
||||
|
||||
def pins_recent(request, page=1):
|
||||
start_pin = abs(int(page) - 1) * 25
|
||||
end_pin = int(page) * 25
|
||||
|
||||
pins = Pin.objects.order_by('-id')[start_pin:end_pin]
|
||||
recent_pins = []
|
||||
for pin in pins:
|
||||
recent_pins.append({
|
||||
'id': pin.id,
|
||||
'thumbnail': pin.image.url_200x1000,
|
||||
'original': pin.image.url,
|
||||
'description': pin.description,
|
||||
})
|
||||
|
||||
return HttpResponse(simplejson.dumps(recent_pins), mimetype="application/json")
|
||||
Reference in New Issue
Block a user