[Django]-Django model get field method

4๐Ÿ‘

โœ…

you can use the property method of the class. Which will access through the objects. You can just include that fields in the serializer.

class Lead(models.Model):
    price = models.IntegerField(_('price'), default=10)

   @property
   def total_price(self):
      ''' Looking for something like this '''
      .. Logic ...
      return self.price

now you can include total_prcie field in serializer.

class LeadSerializer(serializers.ModelSerializer):
     class Meta:
          model = Lead
          fields = ('total_prize', )
๐Ÿ‘คaman kumar

0๐Ÿ‘

I completed this task in a very different way, I had to create another table known as TrackLead Table to track when changes where made.

Later in __init__ function i updated the price field when required. I didnt find anyother way to complete it. However its working now .

๐Ÿ‘คSeshadri VS

Leave a comment