Итак, мне не удалось превратить это представление в вызов Ajax:
def company_single(request, slug):
company = get_object_or_404(CompanyProfile, slug=slug)
company_list = CompanyProfile.objects.get(slug=slug)
try:
tcompany = CompanyLikes.objects.get(company=company_list)
total_likes = tcompany.likes
user_liked = CompanyLikes.objects.get(user=request.user)
except:
total_likes = 0
instance, created = CompanyLikes.objects.get_or_create(company=company_list)
likes_form = CompanyLikesForm(request.POST or None, instance=instance)
if likes_form.is_valid():
this = likes_form.save(commit=False)
try:
if user_liked:
this.likes -=1
this.user.remove(request.user)
except:
this.user.add(request.user)
this.likes += 1
this.save()
return render_to_response('company.html', locals(), context_instance=RequestContext(request))
Мне кажется, мне нужны jQuery и JSON, но я не уверен, как реализовать его здесь, чтобы создать свою собственную "понравившуюся кнопку" для моего сайта. Любые мысли/предложения?