Home>

Question of pure logic of work (without code). For example we have a basket attached to the user

Class Cart (Models.Model):
    "" "" Cart "" "
    Profile= Models.ForeignKey (Profile, On_delete= Models.cascade, Verbose_Name= 'Buyer')
    Products= Models.manyTomanyField ('CartProduct', Blank= True, Related_Name= 'Related_Cart')
    Final_Price= Models.integerfield (default= 0, verbose_name= 'Total price')
    DEF __STR __ (SELF):
        RETURN STR (Self.ID)
    Class Meta:
        verbose_name= 'basket'
        Verbose_Name_Plural= 'Baskets'
Class Cartproduct (Models.Model):
    "" "Basket Object" ""
    Profile= Models.ForeignKey (Profile, On_delete= Models.cascade, Verbose_Name= 'Buyer')
    Product= Models.ForeignKey (Product, On_Delete= Models.cascade)
    quantity= models.positiveIntegerfield (default= 1, blank= true)
    Final_Price= Models.integerfield (Verbose_name= 'Total price', blank= true)
    DEF SAVE (Self, * Args, ** kwargs):
        self.final_price= Self.Quantity * Self.Product.price
        Super (). Save (* Args, ** kwargs)
    DEF __STR __ (SELF):
        Return "Object: {} (for basket)". Format (Self.Product.title)
    Class Meta:
        Verbose_Name= 'Basket Object'
        Verbose_Name_Plural= 'Basket Objects'
Class ORDER (Models.Model):
    "" "Order" ""
    Profile= Models.ForeignKey (Profile, On_delete= Models.cascade, Verbose_Name= 'Buyer')
    Products= Models.ManyTomanyField ('OrderItem', Blank= True, Related_Name= 'Related_Order')
    Billid= Models.charfield (Max_Length= 200)
    comment= models.textfield (default= 'bagleyecommerce')
    Final_Price= Models.integerfield (default= 1)
    Paid= Models.Booleanfield (Default= False)
    Created= Models.dateTimeField (Auto_Now_add= True)
    Updated= Models.dateTimeField (AUTO_NOW= TRUE)
    DEF __STR __ (SELF):
        RETURN STR (Self.ID)
    Class Meta:
        verbose_name= 'order'
        Verbose_Name_Plural= 'Orders'
Class OrderItem: Models.Model:
    "" "Order of the order" ""
    Profile= Models.ForeignKey (Profile, On_delete= Models.cascade, Verbose_Name= 'Buyer')
    Product= Models.ForeignKey (Product, On_Delete= Models.cascade)
    quantity= models.positiveIntegerfield (default= 1, blank= true)
    Final_Price= Models.integerfield (Verbose_name= 'Total price', blank= true)
    DEF SAVE (Self, * Args, ** kwargs):
        self.final_price= Self.Quantity * Self.Product.price
        Super (). Save (* Args, ** kwargs)
    DEF __STR __ (SELF):
        Return "Object: {} (order)". Format (Self.Product.title)
    Class Meta:
        verbose_name= 'Order Object'
        Verbose_Name_Plural= 'Order Objects

Question: Is it possible to bind Order at once to the basket? Or a man pressed the payment button (created Order tied to the basket) After a person added to the basket more goods and paid. After the purchase, it will be given a commodity that in the basket (was before payment or after?) Or then you need to duplicate the order in ORDER like me?

If you do not understand it in the comments, I will try to answer.

  • Answer # 1

    I, too, once wrote the online store of books, but did not add it. He made only the possibility of buying goods not registered by the user. Here is my repository, can help what> https://github.com/zheniagreentea/online-store.
    there the basket is not described as a model, but is delivered to a separate service.py file

    Even I remember that I had to teach the basics of Java Script to add and remove The goods happened beautifully without rebooting the page.

    This cool question you asked "after the purchase it will be given a product that In the basket (was before payment or after?). "It pursues to what should be The payment system is thought out: online card, delivery by mail, courier, pickup. And if so, the order statuses should also be in the order: paid, awaiting payment, not paid, delivered.

    Regarding "or then you need to duplicate the order in ORDER like me?". In general, the idea is also healthy. My teacher insisted to make a copy of the order, because when he was brought by the wrong product that he ordered. Changed the product description on the site and he had to pull out the old page from Kesha, To prove that the product description on the site has been changed after the purchase.

  • Answer # 2

    I, too, once wrote the online store of books, but did not add it. He made only the possibility of buying goods not registered by the user. Here is my repository, can help what> https://github.com/zheniagreentea/online-store.
    there the basket is not described as a model, but is delivered to a separate service.py file

    Even I remember that I had to teach the basics of Java Script to add and remove The goods happened beautifully without rebooting the page.

    This cool question you asked "after the purchase it will be given a product that In the basket (was before payment or after?). "It pursues to what should be The payment system is thought out: online card, delivery by mail, courier, pickup. And if so, the order statuses should also be in the order: paid, awaiting payment, not paid, delivered.

    Regarding "or then you need to duplicate the order in ORDER like me?". In general, the idea is also healthy. My teacher insisted to make a copy of the order, because when he was brought by the wrong product that he ordered. Changed the product description on the site and he had to pull out the old page from Kesha, To prove that the product description on the site has been changed after the purchase.