def create_contact(contact_data, validated_data): try: return Contact.objects.get(contact=contact_data["contact"]) except Contact.DoesNotExist: contact_data = inject_audit_fields(contact_data, validated_data) contact = ContactSerializer(data=contact_data) return contact.save() if contact.is_valid() else inlining_errors.append(json.dumps(contact.errors))
def create_contact(self, contact_data): try: return Contact.objects.get(contact=contact_data["contact"]) except Contact.DoesNotExist: contact = ContactSerializer( data=contact_data, context=self.context) return contact.save() if contact.is_valid() else \ self.inlining_errors.append(json.dumps(contact.errors))
def create_contact(contact_data, validated_data): try: return Contact.objects.get(contact=contact_data["contact"]) except Contact.DoesNotExist: contact_data = inject_audit_fields(contact_data, validated_data) contact = ContactSerializer(data=contact_data) return contact.save() if contact.is_valid() else \ inlining_errors.append(json.dumps(contact.errors))
def create_contact(self, contact_data): try: return Contact.objects.get(contact=contact_data["contact"]) except Contact.DoesNotExist: contact = ContactSerializer(data=contact_data, context=self.context) if contact.is_valid(): return contact.save() else: self.inlining_errors.update(contact.errors) except Contact.MultipleObjectsReturned: return Contact.objects.filter( contact=contact_data["contact"]).first()
def create_contact(self, contact_data): try: if 'id' in contact_data: contact = Contact.objects.get(id=contact_data['id']) contact.contact = contact_data['contact'] contact.contact_type_id = contact_data['contact_type'] contact.save() return contact else: contact = Contact.objects.get(contact=contact_data['contact']) return contact except Contact.DoesNotExist: contact = ContactSerializer(data=contact_data, context=self.context) return contact.save() if contact.is_valid() else \ self.inlined_errors.update(contact.errors)
def create_contact(self, contact_data): try: if 'id' in contact_data: contact = Contact.objects.get( id=contact_data['id'] ) contact.contact = contact_data['contact'] contact.contact_type_id = contact_data['contact_type'] contact.save() return contact else: contact = Contact.objects.get( contact=contact_data['contact'] ) return contact except Contact.DoesNotExist: contact = ContactSerializer( data=contact_data, context=self.context) return contact.save() if contact.is_valid() else \ self.inlined_errors.update(contact.errors)
class ProjectSerializer(serializers.ModelSerializer): descriptions = serializers.SerializerMethodField() members = serializers.SerializerMethodField() media = MediaSerializer(many=True, ) contacts = ContactSerializer(many=True, ) abilities = AbilitySerializer(many=True, ) keywords = KeywordSerializer(many=True, ) schedule = ProjectScheduleSerializer() location = LocationSerializer() class Meta: model = Project fields = ( 'id', 'title', 'descriptions', 'profile_image', 'started_at', 'ends_at', 'media', 'contacts', 'abilities', 'keywords', 'schedule', 'location', 'members', ) def get_descriptions(self, obj): descriptions = ProjectDescription.objects.filter(project=obj.id) return ProjectDescriptionSerializer(descriptions, many=True).data def get_members(self, obj): members = ProjectMember.objects.filter( project=obj.id, is_active=True, ) return ProjectMemberSerializer(members, many=True).data