I wanna build this bookmarking system like in Instagram, I'm having problems writing the logic in views.py and displaying it. So what I want is to bookmark "Act" based on "act-id's" to Wishlist model if a user is authenticated and it would be better if we use Ajax for the post-call(when clicked on the bookmark icon) or open to new options really. Here's my current code... Please help me! if you need any extra bit of code just lemme know.
models.py
class Act(models.Model):
label1 = models.CharField(max_length=50, blank=False)
label2 = models.ImageField(blank=False, null=True)
label3 = models.IntegerField(('year'), choices=YEAR_CHOICES, default=datetime.datetime.now().year)
label4 = models.CharField(max_length=80)
def __str__(self):
return self.Name
class Wishlist(models.Model):
user_id = models.ForeignKey(User, on_delete=models.CASCADE,null=True)
act_id = models.ForeignKey(Act, on_delete=models.DO_NOTHING)
views.py
@csrf_exempt
def wishlist(request):
act_id = request.POST.get('act_id')
if not act_id:
raise ValueError("Required act_id to set wishlist")
user_id = request.user.pk
try:
act_id = Act.objects.get(pk=act_id)
wishlist_obj = {
'user_id': user_id,
'act_id': act_id
}
Wishlist(**wishlist_obj).save()
except ObjectDoesNotExist:
return HttpResponse('Some error occured, unable to add to wishlist')
return HttpResponse('Added to wishlist')
urls.py
urlpatterns = [
path('signup/', views.signup, name='signup'),
path('login/', views.login_req, name='login'),
path("logout/", views.logout_req, name="logout"),
path('home/', views.home, name='home'),
path('wishlist/', views.wishlist, name='wishlist'),
]
for more context here's a conceptual pic of home.html

[![enter image description here][3]][3]
