from .models import * from rest_framework import serializers class Mnf_NotificationSerializer(serializers.ModelSerializer): class Meta: model = Mnf_Notification fields = '__all__' class Member_NewsSerializer(serializers.ModelSerializer): class Meta: model = Member_News fields = '__all__' class Mnf_getNews(serializers.ModelSerializer): class Meta: model = Mnf_Notification fields = '__all__' def to_representation(self, instance): representation = super().to_representation(instance) replacement_name = self.context.get('replacement_name', 'User') # Define a reusable replacement function def replace_words(text,name): if not text: return text # Perform replacements text = text.replace("your", f"{name}'s").replace("Your", f"{name}'s") text = text.replace("you", name).replace("You", name) return text # Update 'title' field if 'title' in representation: representation['title'] = replace_words(representation['title'],replacement_name) # Update 'content' field if 'content' in representation: representation['content'] = replace_words(representation['content'],replacement_name) return representation