[Answered ]-Get all related objects with filter on through model

1👍

You can use related name:

class ArtistArtwork(models.Model): 
    ...
    artwork = models.ForeignKey('gql_service.Artwork', related_name='artwork_artistartwork')

And then in the ArtworkService

class ArtworkInfo(object):
    @property
    def main_artist(self):
        artist = self.artwork.objects.filter(artwork_artistartwork__is_main_artist=True).first()
        return artist

0👍

Did it as:

    @property
    def main_artist(self):
        return self.artwork.artists.filter(
            artistartwork__is_main_artist=True
        ).first()

Leave a comment