Is there a way to get all the values of a field form queryset without looping through and adding to array?
I would do like below as simple example.
I have a Report class with a visit FK field.
results = Report.objects.all() visits = [] for res in results: visits.append(res.visit) But is there as a way to do something like:
visits = results.visit (and have the same result i would from query loop above).
Edit:
Classes below.
class Report(models.Model): ... completed_at = models.DateTimeField() due_date = models.DateField() planned_date = models.DateTimeField() visit = models.ForeignKey(ReportVisit) class ReportVisit(models.Model): contact_name = models.CharField() time_in = models.DateTimeField() lat_in = models.CharField() long_in = models.CharField()
Reportmodel and the model ofres.visit.related_namein yourForeignKey?