Created
November 16, 2019 23:41
-
-
Save mayela/e192903a09b6b1c8951481e170a0227d to your computer and use it in GitHub Desktop.
Como obtener multiples argumentos desde la url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# view | |
def imprescindibles_playlist(request, id_category, id_parent): | |
playlist = None | |
parent = None | |
last_categoty = None | |
audios = None | |
paginator = None | |
page = 1 | |
try: | |
category = Category.objects.get(id=id_category) | |
parent = Category.objects.get(id=id_parent) | |
if request.GET.has_key('page'): | |
page = request.GET.get('page') | |
try: | |
playlist = Playlist.objects.filter(owner=request.user) | |
except Exception as e: | |
playlist = None | |
if parent.name == 'Música de concierto': | |
if request.GET['last'] is not None: | |
last_categoty = Category.objects.get(id=request.GET['last']) | |
audios = AssetMedia.objects.filter( | |
Q(categories__exact=id_category) | |
& Q(parent_categories__exact=last_categoty.id) | |
& Q(is_in_essential=True) | |
& Q(qa_revision=True) | |
& Q(published=True) | |
).order_by('title', 'track') | |
else: | |
audios = AssetMedia.objects.filter( | |
categories__in=[id_category], | |
is_in_essential=True, | |
qa_revision=True, | |
published=True | |
) | |
paginator = Paginator(audios, 15) | |
except Exception as e: | |
logging.error(e.message) | |
if request.is_ajax(): | |
template_file = 'without_content.html' | |
else: | |
template_file = 'base.html' | |
ctx = { | |
'category': Category.objects.get(id=id_category), | |
'audio_list': paginator.page(page), | |
'playlist': playlist, | |
'parent': parent, | |
'last_categoty': last_categoty, | |
'total_page': range(1, paginator.num_pages + 1), | |
'page': int(page), | |
'template_file': template_file | |
} | |
return render(request, 'musicassets/imprescindible_playlist.html', ctx) | |
#urls.py | |
url(r'^imprescindibles_playlist/(?P<id_category>.+?)/(?P<id_parent>.+?)/$', 'musicassets.views.imprescindibles_playlist', name='imprescindibles_playlist'), | |
""" Otro ejemplo en https://stackoverflow.com/questions/48048066/django-rest-framework-multiple-url-arguments""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment