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
- [Django]-How to ignore a specific migration?
- [Django]-Using Validators in Django not working properly
- [Django]-Error while Installing Packages from requirements.txt in python 3.9
- [Django]-How to lock access to django redis cache
- [Django]-How do i split a very long string into a list of shorter strings in python
Source:stackexchange.com