login_required def genre_add_artist request slug kwargs parent get_obj

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
@login_required
def genre_add_artist(request, slug, **kwargs):
parent = get_object_or_404(Genre, slug=slug)
if request.method == 'POST':
child = get_object_or_404(Artist, pk=request.POST.get('child_id'))
parent.artists.add(child)
return HttpResponseRedirect(parent.get_absolute_url())
else:
ids = [i['id'] for i in parent.artists.values('id')]
kwargs['queryset'] = Artist.objects.filter(name__icontains=request.GET.get('filter', '')).exclude(id__in=ids)
kwargs['extra_context'] = {'parent': parent,
'child_type': Artist.__name__, 'parent_type': Genre.__name__}
kwargs['template_name'] = 'reference/genre_add_artist.html'
return object_list(request, **kwargs)