S
S
Sergey Ganzhela2016-11-08 12:53:11
Django
Sergey Ganzhela, 2016-11-08 12:53:11

How to organize a wishlist in a django online store project?

Good afternoon, in my own interests, I am writing a store engine, tell me how to organize a wishlist, or tell me some thread of a tablet for this? I tried to use django-wishlist but as they say it didn't work right out of the box ^(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2016-11-08
@sergey-gornostaev

Why a battery for such a simple thing?

class Wish(models.Model):
    customer = models.ForeignKey(User)
    item = models.ForeignKey(Product)

    class Meta:
        unique_together = ['customer', 'item']

class WishCreate(CreateView):
    model = Wish
    fields = ['item']

    def form_valid(self, form):
        obj = form.save(commit=False)
        obj.customer = self.request.user
        obj.save()        
        return http.HttpResponseRedirect(self.get_success_url())


class WishDelete(DeleteView):
    model = Wish
    success_url = reverse_lazy('wish-list')


class WishList(ListView):
    model = Wish

    def get_queryset(self):
        return Wish.objects.filter(customer=self.request.user)

Everything. It remains only to make templates.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question