def follow(request,object_id): '''用户(身份病人)follow''' result = {} dentistuser = User.objects.get(id=object_id) DentistProfileObj = DentistProfile.objects.get(user=dentistuser) PatientProfileObj = PatientProfile.objects.get(user=request.user) try: Relationship.objects.get(patient = PatientProfileObj,dentist = DentistProfileObj) result = { "msg":"Failure", "status":0, } except: RelationshipNew = Relationship(patient = PatientProfileObj,dentist = DentistProfileObj,status = 0) RelationshipNew.save() result = { "msg":"Success", "status":1, } return result
def connect(request,object_id): '''用户(身份病人)发送connect请求''' result = {} data = json.loads(request.POST['data']) msg = data['msg'] msg = msg.strip() receiver = User.objects.filter(id=object_id) dentistuser = receiver[0] patient = request.user DentistProfileObj = DentistProfile.objects.get(user=dentistuser) PatientProfileObj = PatientProfile.objects.get(user=request.user) try: RelationshipObj = Relationship.objects.get(patient = PatientProfileObj,dentist = DentistProfileObj) if RelationshipObj.status == 0: RelationshipObj.status=1 RelationshipObj.save() relation_type_object = ContentType.objects.get(model='relationship') Event.objects.filter(user=patient, content_type=relation_type_object, object_id=RelationshipObj.id).update(message=msg) result = { "msg":"Success", "status":1, } except: RelationshipNew = Relationship(patient = PatientProfileObj,dentist = DentistProfileObj,status = 1) RelationshipNew.save() relation_type_object = ContentType.objects.get(model='relationship') Event.objects.filter(user=patient, content_type=relation_type_object, object_id=RelationshipNew.id).update(message=msg) result = { "msg":"Success", "status":1, } return result