def __new__(cls, name, bases, attrs): # Only assign new attrs if not a proxy model. if not ("Meta" in attrs and getattr(attrs["Meta"], "proxy", False)): for option in settings.SHOP_OPTION_TYPE_CHOICES: attrs["option%s" % option[0]] = fields.OptionField(option[1]) args = (cls, name, bases, attrs) return super(ProductVariationMetaclass, cls).__new__(*args)
def __new__(cls, name, bases, attrs): # Only assign new attrs if not a proxy model. if not ("Meta" in attrs and getattr(attrs["Meta"], "proxy", False)): for option in settings.CB_EMBROIDERY_CHOICES: attrs["option%s" % option[0]] = fields.OptionField(option[1]) args = (cls, name, bases, attrs) return super(PersonalizationMetaclass, cls).__new__(*args)
def option_fields(cls): """ Returns each of the model files created from CB_EMBROIDERY_CHOICES """ templ = 'option%s' attrs = tuple(fields.OptionField(option[1], name=templ % option[0]) for option in settings.CB_EMBROIDERY_CHOICES) for opt in attrs: opt.model = cls return cls._meta.fields + attrs
class ProductOption(models.Model): """ A selectable option for a product such as size or colour. """ type = models.IntegerField(_("Type"), choices=settings.SHOP_OPTION_TYPE_CHOICES) name = fields.OptionField(_("Name")) objects = managers.ProductOptionManager() def __unicode__(self): return "%s: %s" % (self.get_type_display(), self.name) class Meta: verbose_name = _("Product option") verbose_name_plural = _("Product options")
class PersonalizationOption(models.Model): """ A selectable option for a personalization such as thread color or size """ type = models.IntegerField(_("Type"), choices=settings.CB_EMBROIDERY_CHOICES) name = fields.OptionField(_("Name")) objects = PersonalizationOptionManager() def __str__(self): return "%s: %s" % (self.get_type_display(), self.name) def match_option(self, option_name): for obj in self.objects.all(): if obj.type == option_name.lstrip('option'): return obj return None class Meta: verbose_name = _("Personalization option") verbose_name_plural = _("Personalization options")
def __new__(cls, name, bases, attrs): for option in settings.SHOP_OPTION_TYPE_CHOICES: attrs["option%s" % option[0]] = fields.OptionField(option[1]) args = (cls, name, bases, attrs) return super(ProductVariationMetaclass, cls).__new__(*args)