class Bookmark(models.Model):
user = models.ForeignKey(User)
profile = models.ForeignKey(OdeskProfileData)
url(r'^add_remove_bookmark/(\d+)/(\d+)/$', 'Registry.views.add_remove_bookmark'),
@login_required
def add_remove_bookmark(request,uid, qid):
try:
bookmark = Bookmark.objects.get(user=uid, profile=qid)
bookmark.delete()
except Bookmark.DoesNotExist:
bookmark = Bookmark.objects.create(
user=User.objects.get(id=uid),
profile=OdeskProfileData.objects.get(id=qid))
bookmark.save()
return HttpResponseRedirect('/bookmarks/' + qid)
Y2xhc3MgQm9va21hcmsobW9kZWxzLk1vZGVsKToKICAgIHVzZXIgPSBtb2RlbHMuRm9yZWlnbktleShVc2VyKQogICAgcHJvZmlsZSA9IG1vZGVscy5Gb3JlaWduS2V5KE9kZXNrUHJvZmlsZURhdGEpCiAgICAgCnVybChyJ15hZGRfcmVtb3ZlX2Jvb2ttYXJrLyhcZCspLyhcZCspLyQnLCAnUmVnaXN0cnkudmlld3MuYWRkX3JlbW92ZV9ib29rbWFyaycpLAogICAgIAogICAgIApAbG9naW5fcmVxdWlyZWQKZGVmIGFkZF9yZW1vdmVfYm9va21hcmsocmVxdWVzdCx1aWQsIHFpZCk6CiAgICB0cnk6CiAgICAgICAgYm9va21hcmsgPSBCb29rbWFyay5vYmplY3RzLmdldCh1c2VyPXVpZCwgcHJvZmlsZT1xaWQpCiAgICAgICAgYm9va21hcmsuZGVsZXRlKCkKICAgIGV4Y2VwdCBCb29rbWFyay5Eb2VzTm90RXhpc3Q6CiAgICAgICAgYm9va21hcmsgPSBCb29rbWFyay5vYmplY3RzLmNyZWF0ZSgKICAgICAgICAgICAgICAgICAgICAgICAgdXNlcj1Vc2VyLm9iamVjdHMuZ2V0KGlkPXVpZCksCiAgICAgICAgICAgICAgICAgICAgICAgIHByb2ZpbGU9T2Rlc2tQcm9maWxlRGF0YS5vYmplY3RzLmdldChpZD1xaWQpKQogICAgICAgIGJvb2ttYXJrLnNhdmUoKQogICAgcmV0dXJuIEh0dHBSZXNwb25zZVJlZGlyZWN0KCcvYm9va21hcmtzLycgKyBxaWQp