Browse Source

Allow unassigning categories from products

This has been impossible so far. It is easily achieved by setting
can_delete=True on the formset.

I spent some time trying to get the nice solution working, which would
be that assigning an empty category means deleting that ProductCategory
instance. But I haven't found a good solution that avoids problems like
in #1267. I have since come to the conclusion that enabling can_delete
is the right thing to do. One can then explicitly hide the checkbox,
but set the correct hidden field in Javascript on the client side if
an empty value is assigned.

The fields section has been moved from the factory declaration to the
ProductForm Meta class to allow for easier customisation.

Fixes #1289
master
Maik Hoepfel 12 years ago
parent
commit
3e4c2f73dd
2 changed files with 8 additions and 2 deletions
  1. 3
    0
      docs/source/releases/v0.7.rst
  2. 5
    2
      oscar/apps/dashboard/catalogue/forms.py

+ 3
- 0
docs/source/releases/v0.7.rst View File

@@ -173,7 +173,10 @@ Bugfixes
173 173
 * Suspended and consumed offers are no longer returned by the "active" offer
174 174
   manager. (`#1228`_).
175 175
 
176
+* Products can now be removed from categories (`#1289`_).
177
+
176 178
 .. _`#1228`: https://github.com/tangentlabs/django-oscar/issues/1228
179
+.. _`#1289`: https://github.com/tangentlabs/django-oscar/issues/1289
177 180
 .. _`be04d46639`: https://github.com/tangentlabs/django-oscar/commit/
178 181
 
179 182
 Backwards incompatible changes in 0.7

+ 5
- 2
oscar/apps/dashboard/catalogue/forms.py View File

@@ -387,16 +387,18 @@ class ProductCategoryForm(forms.ModelForm):
387 387
 
388 388
     class Meta:
389 389
         model = ProductCategory
390
+        fields = ('category', )
390 391
 
391 392
 
392 393
 BaseProductCategoryFormSet = inlineformset_factory(
393
-    Product, ProductCategory, form=ProductCategoryForm,
394
-    fields=('category',), extra=1, can_delete=False)
394
+    Product, ProductCategory, form=ProductCategoryForm, extra=1,
395
+    can_delete=True)
395 396
 
396 397
 
397 398
 class ProductCategoryFormSet(BaseProductCategoryFormSet):
398 399
 
399 400
     def __init__(self, product_class, user, *args, **kwargs):
401
+        # This function just exists to drop the extra arguments
400 402
         super(ProductCategoryFormSet, self).__init__(*args, **kwargs)
401 403
 
402 404
     def clean(self):
@@ -419,6 +421,7 @@ class ProductCategoryFormSet(BaseProductCategoryFormSet):
419 421
 
420 422
 
421 423
 class ProductImageForm(forms.ModelForm):
424
+
422 425
     class Meta:
423 426
         model = ProductImage
424 427
         exclude = ('display_order',)

Loading…
Cancel
Save