Django Query Set

45 views
Skip to first unread message

Ajay M

unread,
Feb 11, 2015, 9:20:59 AM2/11/15
to django...@googlegroups.com
I'm on a Django Project, I'm stuck with this situation. I've 3 Models, records,users and towns. Records are posted by users who belongs to towns. User may be a mobile user or a web user. Primary key of users is a foreign key in records, primary key of towns is a foreign key in users. I need to find the total number of posts made by web users and mobile users, who belongs to the top 5 towns by numbers of records. Can any one help me to find that?

C. Kirby

unread,
Feb 11, 2015, 10:58:58 AM2/11/15
to django...@googlegroups.com
I'm sure someone can help you, but you need to post some more information to get useful support. Please post the models that you are dealing with, as well as maybe an example of the result you are trying to get.

Chew Kok Hoor (gMail)

unread,
Feb 12, 2015, 7:28:33 AM2/12/15
to django...@googlegroups.com
Hi all,

    I am using:

with transaction.atomic()

    And in the with block, sometimes I use django query like: models.Customer.objects.count()

    and sometimes I use cursor, example:

    with transaction.atomic():
        count_customers = models.Customer.objects.count()
        with connection.cursor() as c:
            r = c.execute(“SELECT * FROM Customer Inner Join Items ON Customer.Id = Items.FK_Customer")

    So my question is, is it necessary to close to use with connection.cursor() ? Do I actually need to close the cursor or it doesn’t matter? What is impact of closing cursor? Does it means the recordset returned gets closed as well?

    Will closing the cursor affects the connection? What about executing INSERT and UPDATEs?

Thanks.

Regards,
    Kok Hoor
        
Reply all
Reply to author
Forward
0 new messages