def create_user_preference_serializer(user, preference_key, preference_value):
 try:
  existing_user_preference = UserPreference.objects.get(user=user, key=preference_key)
 except ObjectDoesNotExist:
  existing_user_preference = None
 new_data = {'user': user.id, 'key': preference_key, 'value': preference_value}
 if existing_user_preference:
  serializer = RawUserPreferenceSerializer(existing_user_preference, data=new_data)
 else:
  serializer = RawUserPreferenceSerializer(data=new_data)
 return serializer

def create_user_preference_serializer ( user , preference_key , preference_value ) : try : existing_user_preference = UserPreference . objects . get ( user = user , key = preference_key ) except ObjectDoesNotExist : existing_user_preference = None new_data = { 'user' : user . id , 'key' : preference_key , 'value' : preference_value } if existing_user_preference : serializer = RawUserPreferenceSerializer ( existing_user_preference , data = new_data ) else : serializer = RawUserPreferenceSerializer ( data = new_data ) return serializer
creates a serializer for the specified user preference .