Wednesday, February 19, 2020

Help on passing model field as function argument

Hi All,

Views.py :
class DASDataViewSet(viewsets.ModelViewSet):
    queryset = DASData.objects.all()
    serializer_class = DASDataSerializer

    def create(self, request, *args, **kwargs):
        try:
            das_data = {
                'patient': request.data['patient'],
                'hexa_data': request.data['hexa_data'],
                'device_id': request.data['device_id'],
            }
            serializer = DASDataSerializer(data=das_data)
            if serializer.is_valid():
                serializer.save()
                self._numeric_conversion(serializer)
                #self._start_monitoring(request.data['patient'])
            return Response("Success", status=status.HTTP_201_CREATED)
        except DASData.DoesNotExist:
            return Response("Failed to persist device data", status=status.HTTP_400_BAD_REQUEST)

    @staticmethod
    def _start_monitoring(patient_id, presentation_mode):# should be like this
        with open(os.path.join(constants.LOG_DIR, "%s.lck" % str(patient_id)), 'w+'):
            pass
        p = Pipeline()
       # p.startmonitor(patient_id)
        p.startmonitor(patient_id, presentation_mode) # should be like this
-----------------------------------------------------------------------------------------------------------
models.py:

class Patients(models.Model):
    GENDER_CHOICES = (
        ('M', 'Male'),
        ('F', 'Female'),
    )
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255)
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    age = models.IntegerField()
    height = models.IntegerField()
    weight = models.DecimalField(max_digits=5, decimal_places=2)
    bmi = models.DecimalField(max_digits=5, decimal_places=2, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    presentation_mode = models.CharField(max_length=20, default='sleeping')

Doubt :
In the view.py, i would like to add "presentation_mode" in  p.startmonitor(patient_id) like p.startmonitor(patient_id, presentation_mode) but "presentation_mode" is the field of Patients model as shown above but DASDataViewSet we are using "DASData" model.

How can i fetch "presentation_mode" as argument to p.startmonitor(patient_id) which is field of Patients model.?



Thanks,
Saswat



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEhPkLFs3imguC4SXahLHy6aM1-sGWc0wu22CTtX553skF%2Bgyg%40mail.gmail.com.

No comments:

Post a Comment