Answer the question
In order to leave comments, you need to log in
Getting a list of field values for a GenericForeignKey relationship?
There is a model associated with another via GenericForeignKey
models.py
class Report(models.Model):
....
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
usage_id = models.PositiveIntegerField(verbose_name='ID', db_column='id')
usage = GenericForeignKey('content_type', 'usage_id')
....
Models. objects.all().values_list('usage', flat=True)
only working with GenericForeignKey ?
Answer the question
In order to leave comments, you need to log in
`usage` is not a field, but a key
, I think that's how it should be
Report.objects.all().prefetch_related('usage')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question