Re: merge fields from different table

2022-11-04 Thread DUSHYANT SINGH
hello i am not from the py community so please remove me from this section.
   thanks

On Sat, Nov 5, 2022 at 12:06 AM Ammar Mohammed 
wrote:

> *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,  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
>> 
>> .
>>
> --
> 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
> 
> .
>

-- 
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/CABqedVMga-e5uE-aNaZfEwxhX3j_LBP%2B3mYiOxCJKPwB2cGsaw%40mail.gmail.com.


Re: merge fields from different table

2022-11-04 Thread Ammar Mohammed
*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,  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
> 
> .
>

-- 
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.


Merging two fields from different table

2022-11-04 Thread Kala Rani
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+unsubscr...@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.


psycopg 3 - getting attributeError

2022-11-04 Thread Brian Nabusiu
[image: attribute_error.png]Hello, 

I wanted to migrate my app to using psycopg 3. However, I got an error that 
insists using psycopg2, even when it was not installed in venv. So I 
decided to ammend some django code as illustrated by the inventor of 
psycopg3. However, 

   1. django complained of not knowing how to import Text from 
   django.db.utils. So I inspected the utils.py, there was class Text. I 
   created one and the error went away. I know I am very much likely wrong 
   doing that
   2. django started but I could not connect to querry relations with 
   attribute error that objects do not have status attribute as shown in the 
   image attached

Anyone using django 4.1, python 3.11.0 and psycopg3 to help?


-- 
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/7189f73f-d2ce-4cbf-9a72-350202158ec0n%40googlegroups.com.


merge fields from different table

2022-11-04 Thread Kala Rani
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.


Re: Loop through QuerySet in Django

2022-11-04 Thread Marcelo Robin
I have a problem

El jue., 3 nov. 2022 16:40, subin  escribió:

> Please let me know if that is okay.
>
> On Wed, Nov 2, 2022 at 5:03 PM Marcelo A. Robin 
> wrote:
>
>> I have a processors.py file where I generate a context processor to load
>> static data into my project's base template. I have posts and I want to
>> generate as a kind of archive in a aside, where you can access through a
>> link, the posts that were created in the month of August 2022 (for example)
>> and that will take me to a page where I will see the entire list of posts.
>> To build that list, from this kind of file, I do the following in the
>> processors.py file:
>>
>> def ctx_dic_history(request):
>> ctx_history = {} ctx_history['dates'] =
>> Post.objects.dates('created','month').distinct()
>> return ctx_history
>>
>> If I put {{ dates }} in the aside, it returns the following:
>>
>> > datetime.date(2022, 9, 1), datetime.date(2022, 10, 1)]>
>>
>> Now I want to go through that queryset, but I can't get what I need: I
>> want them to be sorted descending first, that is, the most recent month on
>> top. Second, I want to access the month and the year, that is, something
>> like "August 2022" appears.
>>
>> {% for item in dates %} Probando {% endfor %}
>>
>> With that I can iterate over the items that this queryset brings me, but
>> I don't know how to access the date in question for each item in the
>> queryset. If you can give me a hand I would appreciate it in advance. If I
>> manage to get it to work, I'll definitely post the answer that worked for
>> me. Thank you so much
>>
>> --
>> 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/96f58712-88e9-4eae-94f6-909918f2045en%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/H1o_Zpd47jk/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAJnMy6ch9TUmu01%2BTw65jApLasVXSvMPu7%2BmMKWi6O-BFW10VA%40mail.gmail.com
> 
> .
>

-- 
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/CAH25kbSLMg2%3Dnb2ridu_91W9K%2BnLMs38G1ZaMY5fLVSZxX46zw%40mail.gmail.com.