I have a serializer
class MappingSerializer(ExtendedModelSerializer):
default_landing_page_url = serializers.URLField(read_only=True)
class Meta:
model = models.Mapping
fields = ('id', 'name', 'settings', 'campaign','default_landing_page_url')
def create(self, validated_data):
instance = super().create(validated_data)
profile_id = instance.settings.integration.profile_id
instance.default_landing_page_url = helpers.get_landing_page_url(profile_id, instance.campaign)
instance.save()
return instance
In this case, there is a 2 queries into db,first when calling super().create(validated_data) and second is instance.save(). How can I avoid doing 2 queries with the same logic.
I could add extra field validated["default_landing_page_url"] = helpers.get_landing_page_url(profile_id, instance.campaign)
and then call super().create() but in this case I can't reach profile_id, which can be accessible only after instance is created