Parcourir la source

Check if child has parent not only on ID

master
Viggo de Vries il y a 1 an
Parent
révision
9afb182d57
1 fichiers modifiés avec 4 ajouts et 2 suppressions
  1. 4
    2
      src/oscar/apps/catalogue/abstract_models.py

+ 4
- 2
src/oscar/apps/catalogue/abstract_models.py Voir le fichier

572
         """
572
         """
573
         Validates a child product
573
         Validates a child product
574
         """
574
         """
575
-        if not self.parent_id:
575
+        has_parent = self.parent or self.parent_id
576
+
577
+        if not has_parent:
576
             raise ValidationError(_("A child product needs a parent."))
578
             raise ValidationError(_("A child product needs a parent."))
577
-        if self.parent_id and not self.parent.is_parent:
579
+        if has_parent and not self.parent.is_parent:
578
             raise ValidationError(
580
             raise ValidationError(
579
                 _("You can only assign child products to parent products.")
581
                 _("You can only assign child products to parent products.")
580
             )
582
             )

Chargement…
Annuler
Enregistrer