Search code examples
pythondjangodjango-oscar

In Oscar, what is a line?


I'm using the ecommerce package Django-Oscar. In Oscar there is an object related to Basket called a "Line" that I do not understand. What is a Line, what information does it convey and what is it meant to represent?


Solution

  • I've used Django-Oscar for 2 years. It was the very raw package. A line is one record in the Basket. You can see it in source model AbstractLine.

    
    class AbstractLine(models.Model):
        """
        A line of a basket (product and a quantity)
        """
        basket = models.ForeignKey('basket.Basket', related_name='lines',
                                   verbose_name=_("Basket"))

    # This is to determine which products belong to the same line
    # We can't just use product.id as you can have customised products
    # which should be treated as separate lines.  Set as a
    # SlugField as it is included in the path for certain views.
    line_reference = models.SlugField(_("Line Reference"), max_length=128,
                                      db_index=True)
    
    product = models.ForeignKey(
        'catalogue.Product', related_name='basket_lines',
        verbose_name=_("Product"))
    quantity = models.PositiveIntegerField(_('Quantity'), default=1)
    
    # We store the unit price incl tax of the product when it is first added to
    # the basket.  This allows us to tell if a product has changed price since
    # a person first added it to their basket.
    price_excl_tax = models.DecimalField(
        _('Price excl. Tax'), decimal_places=2, max_digits=12,
        null=True)
    price_incl_tax = models.DecimalField(
        _('Price incl. Tax'), decimal_places=2, max_digits=12, null=True)
    # Track date of first addition
    date_created = models.DateTimeField(_("Date Created"), auto_now_add=True)