So i have 2 models:
class Artist(models.Model):
"""Artist model."""
name = models.CharField('Artist name', max_length=255)
genre = models.CharField('Music genre', max_length=255)
class Event(models.Model):
"""Event model."""
name = models.CharField('Event name', max_length=255)
description = models.TextField('Description')
localization_name = models.CharField('Localization name', max_length=255)
longitude = models.FloatField('Longitude', default=0.0)
latitude = models.FloatField('Latitude', default=0.0)
artists = models.ManyToManyField(Artist, verbose_name='Artists')
date = models.DateTimeField('Event date')
And i need to get for one artist, every other artist that was with him on events.
I made this on Artist model:
@property
def get_participate_artists(self):
return list(self.event_set.all().values_list('artists__event__artists__name', 'artists__event__artists__genre', named=True).distinct())
but i wanna get queryset or list of Artist objects.
question from:
https://stackoverflow.com/questions/65831854/how-to-get-all-objects-from-many-to-many-relation 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…