Thursday, November 3, 2022

Merging two fields from different table

My models.py

class Regions(models.Model):
 region_name = models.CharField(max_length=255)

 class Locations(models.Model): 
 region = models.ForeignKey(Regions, on_delete=models.CASCADE,blank=True,null=True) name = models.CharField(max_length=255)



How to do this query in django?

select locations.name,regions.region_name
  from locations
 inner join regions on locations.region_id = regions.id order by locations.name;


I want to show this Location name,Region name in v-select tag like 
location name-region name



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f7645f5f-21f2-4245-adce-101bc243c0f8n%40googlegroups.com.

No comments:

Post a Comment