Retrieve and Update data in intermediate table in djnago

84 Views Asked by At

I want to retrieve the list of the intermediate table. here are my models with M2M relationship.

class ClinicHospital(models.Model):
    name = models.CharField(max_length=256)
    address = models.TextField()
    contact = models.CharField(max_length=15)
    lat = models.FloatField()
    lon = models.FloatField()

class Doctor(models.Model):
    name = models.CharField(max_length=256)

    speciality = models.CharField(max_length=256)
    contact = models.CharField(max_length=12)
    speciality = models.ForeignKey(Speciality, on_delete=models.CASCADE)
    clinic_hospital = models.ManyToManyField(ClinicHospital, through='DoctorHospital')

class DoctorHospital(models.Model):
    clinic = models.ForeignKey(ClinicHospital, on_delete=models.CASCADE)

    doctor = models.ForeignKey(Doctor, on_delete=models.CASCADE)
    shift = models.CharField(max_length=10)


views.py


class DoctorShiftListView(generic.ListView):
    model = DoctorHospital


    def get_queryset(self):
        return DoctorHospital.objects.all()

it returns none. How could I get the list of the custom intermediate table?

0

There are 0 best solutions below