*Get your Locations object :*
obj = Locations.objects.get(pk=1)
*Then get the region:*

obj.region.region_name

On Fri, 4 Nov 2022, 7:29 PM Kala Rani, <ranimc...@gmail.com> wrote:

> 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 in select tag like country-city
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/29b954e2-646d-4b58-ba0d-381660ba2f33n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/29b954e2-646d-4b58-ba0d-381660ba2f33n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHs1H7t8M2L_P-xwUBD3B_3VWT_JwOgYRsFiXnTLcBq%2BsdfDhw%40mail.gmail.com.

Reply via email to