I have a model (Points) which saves the points based on the purchase made by a user. I have made in such a way that when order is made (orderapi is called), a signal is passed with order instance and points are calculated based on the amount and it is saved using the **save** method.

Alothugh Order object is created, I dont see the points being saved in the database. I am not sure what is the issue.

My models:

```
class Order(models.Model):
    ORDER_STATUS = (
        ('To_Ship', 'To Ship',),
        ('Shipped', 'Shipped',),
        ('Delivered', 'Delivered',),
        ('Cancelled', 'Cancelled',),
    )
    user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True)   
    order_status = models.CharField(max_length=50,choices=ORDER_STATUS,default='To_Ship')
    ordered_date = models.DateTimeField(auto_now_add=True)
    ordered = models.BooleanField(default=False)   

    @property
    def total_price(self):
        # abc = sum([_.price for _ in self.order_items.all()])
        # print(abc)
        return sum([_.price for _ in self.order_items.all()])

    def __str__(self):
        return self.user.email

    class Meta:
        verbose_name_plural = "Orders"
        ordering = ('-id',)

class OrderItem(models.Model):       
    orderItem_ID = models.CharField(max_length=12, editable=False, default=id_generator)
    order = models.ForeignKey(Order,on_delete=models.CASCADE, blank=True,null=True,related_name='order_items')
    item = models.ForeignKey(Product, on_delete=models.CASCADE,blank=True, null=True)
    order_variants = models.ForeignKey(Variants, on_delete=models.CASCADE,blank=True,null=True)
    quantity = models.IntegerField(default=1)    

    @property
    def price(self):
        total_item_price = self.quantity * self.order_variants.price
        # print(total_item_price)
        return total_item_price    

class Points(models.Model):
    order = models.OneToOneField(Order,on_delete=models.CASCADE,blank=True,null=True)
    points_gained = models.IntegerField(default=0)

    def collect_points(sender,instance,created,**kwargs):
        total_price = instance.total_price
        if created:
            if total_price <= 10000:
                abc = 0.01 * total_price
            else:
                abc = 0.75 * total_price
            return abc

    post_save.connect(collect_points,sender=Order)

    def save(self,*args,**kwargs):
        self.points_gained = self.collect_points()
        super(Points, self).save(*args, **kwargs)

```

I am actually confused here. Can we access property total\_price using instance.total\_price??

My serializers:

```
class OrderSerializer(serializers.ModelSerializer):
    billing_details = BillingDetailsSerializer()
    order_items = OrderItemSerializer(many=True)
    user = serializers.PrimaryKeyRelatedField(read_only=True, default=serializers.CurrentUserDefault())
    #total_price = serializers.SerializerMethodField(source='get_total_price')
    class Meta:
        model = Order
        fields = ['id','user','ordered_date','order_status', 'ordered', 'order_items','total_price', 'billing_details']
        # depth = 1   

    def create(self, validated_data):
        user = self.context['request'].user
        if not user.is_seller:
            order_items = validated_data.pop('order_items')
            billing_details = validated_data.pop('billing_details')
            order = Order.objects.create(user=user,**validated_data)
            BillingDetails.objects.create(user=user,order=order,**billing_details)
            for order_items in order_items:
                OrderItem.objects.create(order=order,**order_items)
            order.save()
            return order
        else:
            raise serializers.ValidationError("This is not a customer account.Please login as customer.")

```

**My updated code:**

```
class Order(models.Model):
total_price = models.FloatField(blank=True,null=True)

    def final_price(self):      
        return  sum([_.price for _ in self.order_items.all()])

    def save(self, *args, **kwargs):
        self.total_price = self.final_price()
        super(Order, self).save(*args, **kwargs)

class Points(models.Model):
    order = models.OneToOneField(Order,on_delete=models.CASCADE,blank=True,null=True)
    points_gained = models.FloatField(default=0)

    def collect_points(sender,instance,created,**kwargs):
        total_price = instance.total_price
        print(total_price)
        if created:
            if total_price <= 10000:
                abc = 0.01 * total_price
            else:
                abc = 0.75 * total_price
        new_point = Points.objects.create(order=instance, points_gained=abc)

    post_save.connect(collect_points,sender=Order)

```

**Focused on this part**

```
Class Order(models.Model):
    total_price = models.FloatField(blank=True,null=True)

    def final_price(self):
        # abc = sum([_.price for _ in self.order_items.all()])
        # print(abc)
        return  sum([_.price for _ in self.order_items.all()])

    def save(self, *args, **kwargs):
        self.total_price = self.final_price()
        super(Order, self).save(*args, **kwargs)

```