K
K
Konstantin Malyarov2018-03-13 10:52:12
Django
Konstantin Malyarov, 2018-03-13 10:52:12

How to serialize id in django?

There is a standard serializer.

def patients_department(request):
    stories_department = serializers.serialize('json', Disaese_history.objects.filter(exit_day=None),
                                               use_natural_foreign_keys=True, use_natural_primary_keys=True)
    return HttpResponse(stories_department)

The answer comes like this:
department:(...)
doctor:(...)
enter_day:(...)
exit_day:(...)
number:(...)
patient:(...)
pay:(...)

The model itself.
class Disaese_history(models.Model):
    patient = models.ForeignKey(Patient, default=None, null=True, on_delete=models.CASCADE)
    department = models.ForeignKey(Department, default=None, null=True, on_delete=models.CASCADE)
    number = models.CharField(max_length=10)
    pay = models.ForeignKey(Pay, default=None, on_delete=models.CASCADE)
    enter_day = models.DateField()
    exit_day = models.DateField(default=None, null=True)
    doctor = models.ForeignKey(User, default=None, null=True, on_delete=models.CASCADE)

    def __str__(self):
        return '{0}'.format(self.number)

    class Meta:
        verbose_name = 'Исория болезни'
        verbose_name_plural = "Медицинские карты"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question