add public field to Product

This commit is contained in:
Thomas Steen Rasmussen 2016-05-17 15:09:31 +02:00
parent adfca40062
commit 9cce10c281
2 changed files with 11 additions and 0 deletions

View file

@ -98,6 +98,7 @@ class Order(CreatedUpdatedModel):
def get_absolute_url(self): def get_absolute_url(self):
return str(reverse_lazy('shop:order_detail', kwargs={'pk': self.pk})) return str(reverse_lazy('shop:order_detail', kwargs={'pk': self.pk}))
class ProductCategory(CreatedUpdatedModel, UUIDModel): class ProductCategory(CreatedUpdatedModel, UUIDModel):
class Meta: class Meta:
verbose_name = 'Product category' verbose_name = 'Product category'
@ -140,6 +141,11 @@ class Product(CreatedUpdatedModel, UUIDModel):
'(Format: YYYY-MM-DD HH:MM) | Only one of start/end is required' '(Format: YYYY-MM-DD HH:MM) | Only one of start/end is required'
) )
) )
public = models.BooleanField(
default=True,
help_text='Is this product publicly available in the webshop?'
)
objects = ProductQuerySet.as_manager() objects = ProductQuerySet.as_manager()

View file

@ -168,6 +168,11 @@ class ProductDetailView(LoginRequiredMixin, FormView, DetailView):
form_class = AddToOrderForm form_class = AddToOrderForm
context_object_name = 'product' context_object_name = 'product'
def dispatch(self, request, *args, **kwargs):
if not self.get_object().public:
### this product is not publicly available
raise Http404("Product not found")
def form_valid(self, form): def form_valid(self, form):
product = self.get_object() product = self.get_object()
quantity = form.cleaned_data.get('quantity') quantity = form.cleaned_data.get('quantity')