Esempio n. 1
0
	def retrieve(self, request: Request, *args, **kwargs):
		instance = self.get_object()
		serializer = self.get_serializer(instance)
		data = serializer.data
		data['media'] = AbMedias.get_media(instance, 'App\\Company')

		related_models = ['country','city','state']
		
		for model in related_models:
			try:
				data[model] = to_dict(getattr(instance, model))
			except:
				data[model] = None
				
		return Response(data)
Esempio n. 2
0
 def to_representation(self, instance):
     representation = super(PlansSerializer,
                            self).to_representation(instance)
     try:
         representation['media'] = AbMedias.get_media(
             instance, 'App\\Plans')
     except:
         representation['media'] = None
     try:
         if instance.id == 2:
             print(self.context['request'].user.abcredits_set)
             representation['credits'] = CreditsSerializer(
                 self.context['request'].user.abcredits_set.filter(
                     plan=instance, is_active=1).order_by('-id')[:3],
                 many=True).data
     except:
         representation['credits'] = None
     return representation
Esempio n. 3
0
	def retrieve(self, request: Request, *args, **kwargs):
		instance = self.get_object()
		serializer = self.get_serializer(instance)
		data = serializer.data
		# serializer['companies'] = AbCompanies.available_companies(instance)
		data['media'] = AbMedias.get_media(instance, 'App\\Contact')
		try:
			data['user'] = to_dict(instance.user)
			try:
				data['user']['contact'] = to_dict(instance.user.contact)
			except:
				data['user']['contact'] = None
		except:
			data['user'] = None

		related_models = ['department','country','city','state']
		
		for model in related_models:
			try:
				data[model] = to_dict(getattr(instance, model))
			except:
				data[model] = None

		return Response(data)
Esempio n. 4
0
	def retrieve(self, request: Request, *args, **kwargs):
		instance = self.get_object()
		serializer = self.get_serializer(instance)
		data = serializer.data
		data['media'] = AbMedias.get_media(instance, 'App\\Country')
		return Response(data)