[Fixed]-How to convert the Raw Sql query to Django Model

1👍

You can achieve this by making use of ManyToManyField.

Only two steps is needed:

  1. Create a ManyToManyField fields movieActiveDays for TheaterShowTimings.
  2. Make query with the new movieActiveDays field.

Model definition

class TheaterShowTimings(models.Model):
    showname = models.CharField(max_length=100)
    showtime = models.TimeField()  # stores only time
    theatershowtimingsid = models.CharField(primary_key=True, max_length=100)
    # many to many fields to MovieActiveDays
    movieActiveDays = models.ManyToManyField('MovieActiveDays', through='ActiveShowTimings')
    def __str__(self):
        return self.theatershowtimingsid

Query:

TheaterShowTimings.objects.filter(movieActiveDays__date='2016-12-19').distinct()
👤Enix

Leave a comment