5👍
✅
You can get to related object fields by using __
.
qs = self.model.objects.filter(
date__range=(start_date, end_date)
).values(
"customer__name"
)
👤Anna
1👍
You can also use __
within your values like this .values("customer__name")
to select field on related table.
- [Django]-PythonAnywhere + virtualenv: "Could not find platform dependent libraries <exec_prefix>…"
- [Django]-Django ORM: Joining QuerySets
- [Django]-Set language of template in Django by clicking on <a> link from Bootstrap Dropdown menu
0👍
Use this code to get all related customer names.
class Totals(Manager):
def by_customer_and_date(self, start_date, end_date):
name_list = self.model.objects.filter(
date__range=(start_date, end_date)
).values("customer__name", flat=True)
return name_list
- [Django]-Pagination in django rest, ListAPIView
- [Django]-How to get tests coverage using Django, Jenkins and Sonar?
- [Django]-DJANGO – Change text color based on value (HTML & JS)
- [Django]-Python: how to use variables as a string?
Source:stackexchange.com