Skip to content

Instantly share code, notes, and snippets.

@rmcauley
Created January 31, 2020 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmcauley/4e7397f7b2ac977c2c850045d5813d35 to your computer and use it in GitHub Desktop.
Save rmcauley/4e7397f7b2ac977c2c850045d5813d35 to your computer and use it in GitHub Desktop.
class AlbumRating(models.Model):
album = models.ForeignKey(Album, models.CASCADE, db_index=False)
user = models.ForeignKey(User, models.CASCADE, db_index=False)
rating_complete = models.BooleanField(
blank=True, null=True, db_column="album_rating_complete"
)
rating_user = models.FloatField(
blank=True, null=True, db_column="album_rating_user"
)
station_id = models.SmallIntegerField(db_column="sid")
class Meta:
managed = False
db_table = "r4_album_ratings"
index_together = [("album", "user", "station_id"), ("album_id", "station_id")]
class AlbumOnStationQuerySet(models.QuerySet):
# TODO: possible to have with_rating here? (probably not...)
pass
class AlbumOnStationManager(models.Manager):
def get_queryset(self):
queryset = super().get_queryset()
queryset = queryset.select_related('album')
return queryset
class AlbumOnStation(models.Model):
album = models.ForeignKey(Album, models.CASCADE)
station_id = models.SmallIntegerField(db_column="sid", db_index=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment