Re: Add single object(most recent) from foreign key relationship to django queryset

2023-05-13 Thread Andrew Kos
Could you do a separate query or use select_related() to retrieve the most recent comment then combine the two in your table building logic? You're going to be constrained by the structure of the models anyways and so will probably have to make a couple queries to the DB. On Friday, May 12, 202

Re: django queryset - Get the data particular to current year only

2022-04-04 Thread Trippy Samurai
Thanks for the reply Brother but it's already solved On Sunday, 3 April 2022 at 12:05:39 UTC+5:30 sutharl...@gmail.com wrote: > I think this is related to your query > https://stackoverflow.com/a/28101722/8882295 > > On Thu, 31 Mar 2022 at 11:22, Trippy Samurai > wrote: > >> >>

Re: django queryset - Get the data particular to current year only

2022-04-02 Thread Lalit Suthar
I think this is related to your query https://stackoverflow.com/a/28101722/8882295 On Thu, 31 Mar 2022 at 11:22, Trippy Samurai wrote: > > > > I have my query written to get some thing from database and display on my > website that query is get

django queryset - Get the data particular to current year only

2022-03-30 Thread Trippy Samurai
I have my query written to get some thing from database and display on my website that query is getting all the data from db but what if i want to get the data particular to current year only def get(self, request, *args, **kwargs): filt

Re: What is the difference bulk_update() and update() in django queryset.

2021-08-18 Thread M. GW
bulk_update() is a method that updates the provided list of objects into the database with one query. and update() is just for one object ambiti...@gmail.com schrieb am Donnerstag, 12. August 2021 um 00:03:25 UTC+2: > What is the difference bulk_update() and update() in django query

What is the difference bulk_update() and update() in django queryset.

2021-08-11 Thread Am bition
What is the difference bulk_update() and update() in django queryset. -- 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...@google

Re: Django Queryset

2020-12-13 Thread Jorge Gimeno
On Sun, Dec 13, 2020 at 7:21 PM MAMADOU KANTE wrote: > Hi to everybody; > I have been trying to deploy an app through heroku for the past 7 days but > whenever I reach the final stage I receive a rejection message. > The message tells me the module "skbuild" was not imported or I should > upgrad

Re: Django Queryset

2020-12-13 Thread MAMADOU KANTE
Hi to everybody; I have been trying to deploy an app through heroku for the past 7 days but whenever I reach the final stage I receive a rejection message. The message tells me the module "skbuild" was not imported or I should upgrade my pip version. But when I check through the terminal I find th

Re: Django Queryset

2020-11-04 Thread Walter Randazzo
Hi there. Did you try datatable Regards, El mié., 4 nov. 2020 8:30 a. m., lada...@gmail.com escribió: > Hello, Django Users please I need your help and it is urgent, > > I have this code: > *permit_cy = Permit.objects.values(* > > *'info__date_of_transaction__year', > 'info_

Django Queryset

2020-11-04 Thread lada...@gmail.com
Hello, Django Users please I need your help and it is urgent, I have this code: *permit_cy = Permit.objects.values(* *'info__date_of_transaction__year', 'info__country_destination__continent'* *).annotate(volume=Sum('volume')* *).order_by('info__country_destination__cont

Re: Django queryset filtering

2020-10-11 Thread Dvs Khamele
Hi do you hire contract based python/django freelancer? We can help you in this and related tasks at fair prices. Reply or send email to divy...@pythonmate.com Best Regards, Divyesh Khamele, Pythonmate On Thu, 25 Jun 2020, 3:55 am mtp...@gmail.com, wrote: > I have a queryset that returns all th

Re: Django queryset filtering

2020-10-06 Thread mtp...@gmail.com
Thanks guys this was very useful On Friday, June 26, 2020 at 6:27:23 PM UTC+3 Dan Madere wrote: > I'd make two queries. One to see which businesses currently have active > licenses, then a second to get the expired licenses, excluding the > businesses from the first query. Here's some example

Re: Django queryset filtering

2020-06-26 Thread Dan Madere
I'd make two queries. One to see which businesses currently have active licenses, then a second to get the expired licenses, excluding the businesses from the first query. Here's some example code, assuming the LicenseIssue model has a "business" foreign key field: *active_business_ids = Licen

Re: Django queryset filtering

2020-06-25 Thread Oleg Kishenkov
Hello, use a filtering chain, a refined queryset is itself a queryset so you can filter it further. Also, Django has extensive lookup support in its filtering methods. Let's assume LicenseIssue is related to Business as many to one (it is probably the case): class Business(models.Model): name

Django queryset filtering

2020-06-24 Thread mtp...@gmail.com
I have a queryset that returns all the expired licenses objects as shown below. *qs = LicenseIssue.objects.filter(expiry_date__lte=TODAY).order_by('-expiry_date')* Here is my situation: There exists multiple issued licenses of different businesses for year 2020 and their previous issued

Re: Django queryset result and mysql query are wrong after updating from 3.0.2 to 3.0.3

2020-02-19 Thread mohamed alisaleh...@gmail.com
بتاريخ الأربعاء، 19 فبراير، 2020 10:51:53 م UTC+3، كتب Ricardo H: > Hi Simon,  > > > It was ok on 2.2.6, only on 3.0.3 it fails. > > > I use BigIntegerField because I use it for some calculations after that, but > even if I try with DurationField it doens't assert right. > > > Definitely mus

Re: Django queryset result and mysql query are wrong after updating from 3.0.2 to 3.0.3

2020-02-19 Thread Simon Charette
Hello Ricardo, I suggest you follow these docs to submit your bug report and link to this thread. https://docs.djangoproject.com/en/3.0/internals/contributing/bugs-and-features/#reporting-bugs I'd mention that the issue is also present if you use `output_field=DurationField` as BigIntegerField

Re: Django queryset result and mysql query are wrong after updating from 3.0.2 to 3.0.3

2020-02-19 Thread Ricardo H
Hi Simon, It was ok on 2.2.6, only on 3.0.3 it fails. I use BigIntegerField because I use it for some calculations after that, but even if I try with DurationField it doens't assert right. Definitely must be caused by this patch, if I can't find another solution, where and how should I report

Re: Django queryset result and mysql query are wrong after updating from 3.0.2 to 3.0.3

2020-02-19 Thread Simon Charette
Hello Ricardo, This could be a regression caused by a patch addressing a regression in 3.0.3[0]. Did you also notice this behaviour on Django 2.2.x or was this project started from Django 3.0? >From what I can see though I find it strange that the ExpressionWrapper of end_total_time have an o

Django queryset result and mysql query are wrong after updating from 3.0.2 to 3.0.3

2020-02-19 Thread Ricardo H
Hello, after I updated django from 3.0.2 to 3.0.3 the result of the following code has changed when using a MySQL database. It produces a wrong sql query and also the wrong result for "*end_total_time"* attribute. Is this a bug ? also is there any other way to get the wright result using 3.0.3

Re: Django Queryset for Multiple set

2019-03-13 Thread Chetan Ganji
Hi Vaibhav, I think this would do what you want. Make sure too call the objects on the model name ( Modelname ) ;-) systems = ['windows', 'unix'] variable = Modelname.objects.filter(clientname=cname, clienttype__in=systems, errorcode='20') Regards, Chetan Ganji +91-900-483-4183 ganji.che...

Re: Django Queryset for Multiple set

2019-03-13 Thread Krishnasagar Subhedarpage
You could do using django ORM query expressions. Refer below link: https://docs.djangoproject.com/en/2.1/ref/models/expressions/ Regards, Krishnasagar Subhedarpage On Wed, 13 Mar 2019 at 17:14, Vaibhav Mishra wrote: > Hi All, > > I am trying to achieve below , > > variable = object.filter(cl

Django Queryset for Multiple set

2019-03-13 Thread Vaibhav Mishra
Hi All, I am trying to achieve below , variable = object.filter(clientname =cname , clienttype='windows' and clienttype='unix', errorcode='20') Notice that I want to filter by two or more values in second parameter.. How can we do this ? -- You received this message because you are subscr

How to fill empty months using Django queryset

2018-07-24 Thread Charles Sartori
I have the following: In [39]: from django.db.models.functions import TruncDate ...: p = Purchase.objects \ ...: .annotate(date=TruncDate('event_date')) \ ...: .values('date') \ ...: .annotate(total=Sum('quantity')) \ ...: .order_by('event_date') ...: .

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-06 Thread Web Architect
h more, since this is >>>>>>>> just a DB and not a Django ORM question. >>>>>>>> >>>>>>>> >>>>>>>> Am Freitag, 2. Februar 2018 14:47:45 UTC+1 schrieb Web Architect: >>>>>>

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-03 Thread Furbee
>>>>>>>> Hi, >>>>>>>> >>>>>>>> I am trying to optimise Django queries on my ecommerce website. One >>>>>>>> of the fundamental query is where I have no clue how to make >>>>&g

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-03 Thread Vijay Khemlani
;>>>> Django and would appreciate any help. This is primarily for one to many >>>>>>> or >>>>>>> many to many relations. >>>>>>> >>>>>>> Following is an example scenario: >>>>>>> (Ple

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Web Architect
and would appreciate any help. This is primarily for one to many >>>>>> or >>>>>> many to many relations. >>>>>> >>>>>> Following is an example scenario: >>>>>> (Please pardon my syntax as I want

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Web Architect
lly needed): >>>>> >>>>> Model A: >>>>> >>>>> class A(models.Model): >>>>> # Fields of model A >>>>> >>>>> Model B (which is related to A with foreign key): >>>>> >>>

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Furbee
t;>>>> >>>>> class A(models.Model): >>>>> # Fields of model A >>>>> >>>>> Model B (which is related to A with foreign key): >>>>> >>>>> class B(models.Model): >>>>> a = mode

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Vijay Khemlani
f model A >>>> >>>> Model B (which is related to A with foreign key): >>>> >>>> class B(models.Model): >>>> a = models.ForeignKey('A', related_name='bs') >>>> >>>> Now I would like to find out

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Andy
> class B(models.Model): >>> a = models.ForeignKey('A', related_name='bs') >>> >>> Now I would like to find out all As for which there is atleast one b. >>> The only way I know is as follows: >>> >>> A.objects.filter(bs__isn

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Web Architect
s__isnull=False) >> >> But the above isn't an optimal way as with large of records in A and B, >> the above takes lot of time. It gets more inefficient if it's a many to >> many relationship. >> >> Could anyone please let me know the most efficient

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Andy
t of time. It gets more inefficient if it's a many to > many relationship. > > Could anyone please let me know the most efficient way to use django > queryset for the above scenario? > > Thanks. > -- You received this message because you are subscribed to the Google Groups &

Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Web Architect
A and B, the above takes lot of time. It gets more inefficient if it's a many to many relationship. Could anyone please let me know the most efficient way to use django queryset for the above scenario? Thanks. -- You received this message because you are subscribed to the Goog

Re: Django queryset returning corrupted value

2017-10-09 Thread Web Architect
Hi Antonis, Thanks for your response. You are right, The issue wasn't in MySQL or even Django ORM. We were using Cachalot (http://django-cachalot.readthedocs.io/en/latest/) for query caching which was causing the issue. Disabling cachalot fixed the issue. Would need to look more into query cac

Re: Django queryset returning corrupted value

2017-10-08 Thread Antonis Christofides
Hi, this is very strange of course. I doubt it has anything to do with MySQL, because even if MySQL had done something wrong and had returned a long in place of a string, the Django ORM should have caught that and raised an error earlier. So the problem must be in Django. (But of course with such

Re: Django queryset returning corrupted value

2017-10-07 Thread Web Architect
Hi Antonis, Thanks for your response: Following is the model: from treebeard.mp_tree import MP_Node @python_2_unicode_compatible [docs] class AbstractCategory(MP_N

Re: Django queryset returning corrupted value

2017-10-06 Thread Antonis Christofides
Hi, could you show the code that defines the slugfield, the queryset that is returning the wrong value, full error message and traceback (if available), and the version of your OS and RDBMS? It doesn't matter if the problem is more general; let's focus on one specific manifestation of it. Reg

Django queryset returning corrupted value

2017-10-06 Thread Web Architect
Hi, We have running an ecommerce site using Django 1.8.13. It has been running fine for a year. But suddenly the django querysets are returning corrupted values. I am completely clueless why this is happening. Like a model field is of type SlugField but queryset is returning long. Would reall

Map Django QuerySet items

2017-09-24 Thread yluisrojo
Is there a way to map Django QuerySet items not triggering its evaluation <https://docs.djangoproject.com/en/1.11/ref/models/querysets/#when-querysets-are-evaluated> (returning a QuerySet)? -- You received this message because you are subscribed to the Google Groups "Django u

Re: From SQL to Django Queryset API

2017-03-29 Thread Simon Charette
Hello Mauro, The following should do from django.db.models import F Movimento.objects.values( 'anno','impianto' ).annotate( dare=Sum('dare), avere=Sum('avere), diff=Sum(F('dare') - F('avere)), ) Cheers, Simon Le mercredi 29 mars 2017 16:19:37 UTC-4, Mauro Ziliani a écrit : > >

From SQL to Django Queryset API

2017-03-29 Thread Mauro Ziliani
Hi all. My name's Mauro and I working on a DB (SQLite3 now and Postgres in the future). I have a table Movimento with the fields anno integer,impianto integer,dare decimal(10,2),avere decimal(10,2) BY hands I can run SELECT anno,impianto, sum(dare), sum(avere) FROM movimento GROUP BY anno,impi

Re: Questions on Django queryset iterator - wrt select_related and prefetch_related and how it works

2017-03-17 Thread knbk
Django uses client-side cursors. 1.11, which is currently in beta, switches to server-side cursors on PostgreSQL [1], but other databases still use client-side cursors. When a client-side cursor executes a query, it loads all results in memory before the results can be accessed. But that's just

Re: Questions on Django queryset iterator - wrt select_related and prefetch_related and how it works

2017-03-17 Thread Web Architect
Hi, Thanks for your response. But I have observed the following: Without Iterator: It takes a bit of a time before the for loop is executed and also the CPU spikes up during that period and so does the Memory - which implies the DB is accessed to fetch all the results. With iterator: The for l

Re: Questions on Django queryset iterator - wrt select_related and prefetch_related and how it works

2017-03-16 Thread Shawn Milochik
I think the benefit of using the iterator is best explained by an example: Without iterator: You loop through the queryset, using each item for whatever you're doing. As you do this, all the items are now in your local scope, using up RAM. If, after the loop, you should want to loop through the

Questions on Django queryset iterator - wrt select_related and prefetch_related and how it works

2017-03-16 Thread Web Architect
Hi, Could someone please let me know what the implications of Django queryset iterator on select_related and prefetch_related? Also, I am still not quite clear on the concept of iterator which I understand returns a Generator. Whenever a for loop is run on the Generator, the DB is queried

Re: Django queryset High CPU Usage

2017-03-14 Thread Vijay Khemlani
"In the above, the CPU was hitting almost 100% and was taking almost a second" So, your query was resolved in a second, that's normal, also the spike in cpu usage because... the cpu is working... Your problem seems to be in your for loop for a in As: retrieve other related data from associa

Re: Django queryset High CPU Usage

2017-03-13 Thread Web Architect
Hi Daniel, Thanks for the suggestion. Would look into django-import-export. Thanks. On Saturday, March 11, 2017 at 6:29:57 PM UTC+5:30, Daniel Hepper wrote: > > In additions to the suggestions you already received from others, have a > look at django-import-export. It allows you to easily expor

Re: Django queryset High CPU Usage

2017-03-13 Thread Web Architect
Hi Camilo, Thanks for your suggestion. Would certainly look for solutions outside Django if Django cannot suffice. But was trying to find something with Django since the web part was in Django and for easy of development. We are already using Celery Extensively but then high Resource Usage is n

Re: Django queryset High CPU Usage

2017-03-13 Thread Web Architect
On Sunday, March 12, 2017 at 4:53:25 AM UTC+5:30, James Schneider wrote: > > > > On Mar 11, 2017 12:01 PM, "Vijay Khemlani" > wrote: > > Am I the only one who thinks that generating a report over a set of > just 10.000 records could be done in 10 - 20 secs unless there are > some serious computa

Re: Django queryset High CPU Usage

2017-03-13 Thread Web Architect
Hi Vjiay, My apologies if the scenario is not clear. Following are the details: Lets say there is a Model A (with fields, foreignkeys and ManyToMany relationships with other models). There are 10k records for A. Lets say following is the pseudo code for the report: As = A.objects.all() for a

Re: Django queryset High CPU Usage

2017-03-11 Thread Melvyn Sopacua
On Saturday 11 March 2017 21:29:10 Vijay Khemlani wrote: > "But the CPU usage and time taken are high" <- I'm assuming high > enough to be problematic for OP. > > I'm seriously not following. Why are people suggesting reporting and > export software when OP hasn't even described the problem in det

Re: Django queryset High CPU Usage

2017-03-11 Thread Vijay Khemlani
"But the CPU usage and time taken are high" <- I'm assuming high enough to be problematic for OP. I'm seriously not following. Why are people suggesting reporting and export software when OP hasn't even described the problem in detail. It's not even clear whether the high cpu and time taken are du

Re: Django queryset High CPU Usage

2017-03-11 Thread James Schneider
On Mar 11, 2017 12:01 PM, "Vijay Khemlani" wrote: Am I the only one who thinks that generating a report over a set of just 10.000 records could be done in 10 - 20 secs unless there are some serious computations going on with that data? For a report I have to query around 200.000 records, with ag

Re: Django queryset High CPU Usage

2017-03-11 Thread Vijay Khemlani
Am I the only one who thinks that generating a report over a set of just 10.000 records could be done in 10 - 20 secs unless there are some serious computations going on with that data? For a report I have to query around 200.000 records, with aggregations, and it takes less than a minute using th

Re: Django queryset High CPU Usage

2017-03-11 Thread Daniel Hepper
In additions to the suggestions you already received from others, have a look at django-import-export. It allows you to easily export data in various formats. Hope that helps, Daniel Hepper https://consideratecode.com On Friday, March 10, 2017 at 12:06:13 PM UTC+1, Web Architect wrote: > > Hi J

Re: Django queryset High CPU Usage

2017-03-11 Thread Camilo Torres
Hi. You can probably use another web framework for that report, or even rethink your architecture and put the report creation outside Django and the web server without Django ORM. You may be interested in evaluating Celery and Django Celery. You can create a separate task outside Django to cre

Re: Django queryset High CPU Usage

2017-03-10 Thread Vijay Khemlani
This is what you said "There is a Model A with 1 records. Just a simple queryset - A.objects.all() is resulting in CPU hitting almost 100%. Is there a way to optimize this? But why would such a query result in high CPU Usage?" By that, I assume that you opened a shell and executed "A.objects

Re: Django queryset High CPU Usage

2017-03-10 Thread Web Architect
Hi, Thanks for your response. Well, its not just the queryset but when the query triggered by an if condition or a for loop - thats what I meant. I was doing some basic performance check as well while working on the report generation - I observed the issue. There's no manager other than the d

Re: Django queryset High CPU Usage

2017-03-10 Thread Web Architect
Hi Melvyn, Thanks for your response. We are using the Celery for all tasks which could be done offline or separately. Report generation is one of it. We trigger the task from Browser but the report creation is run via Celery which when completed sends the csv filepath to the browser to be down

Re: Django queryset High CPU Usage

2017-03-10 Thread Vijay Khemlani
There is something wrong in your setup I can query a 400.000 item table in less than a second with the typical "Model.objects.all()". Django does not convert all of the entries into objects just by that query. You don't have any managers, or anything that can result in a side-effect beyond the qu

Re: Django queryset High CPU Usage

2017-03-10 Thread Web Architect
Hi James, Thanks for the clarification. Much appreciated. Will follow your points for the reporting part considering the overheads in ORM. Thanks, On Friday, March 10, 2017 at 4:55:35 PM UTC+5:30, James Bennett wrote: > > If all you need is to export data from your database (with or without >

Re: Django queryset High CPU Usage

2017-03-10 Thread Melvyn Sopacua
On Friday 10 March 2017 03:06:12 Web Architect wrote: > Hi James, > > Thanks for your response. Melvyn also posed a similar point of not > loading the whole records. > > But all the records are needed for reporting purposes - where the data > is read from the DB and a csv report is created. I am

Re: Django queryset High CPU Usage

2017-03-10 Thread James Bennett
If all you need is to export data from your database (with or without transforming it along the way) to a CSV, using the normal QuerySet methods is probably the wrong approach; you don't need model objects to do that. Some options include: * Use raw SQL to query for the data and push it to CSV (al

Re: Django queryset High CPU Usage

2017-03-10 Thread Web Architect
Hi James, Thanks for your response. Melvyn also posed a similar point of not loading the whole records. But all the records are needed for reporting purposes - where the data is read from the DB and a csv report is created. I am not quite an expert on Django but I am not sure if there is a be

Re: Django queryset High CPU Usage

2017-03-10 Thread James Schneider
On Mar 9, 2017 9:37 PM, "Web Architect" wrote: Would like to further add - the python CPU Usage is hitting almost 100 %. When I run a Select * query on Mysql, its quite fast and CPU is normal. I am not sure if anything more needs to be done in Django. Ironically, things being done in Django is

Re: Django queryset High CPU Usage

2017-03-10 Thread Melvyn Sopacua
On Thursday 09 March 2017 21:25:51 Web Architect wrote: > I am a bit perplexed by this and not sure what the solution is. > Following is the scenario: > > There is a Model A with 1 records. Just a simple queryset - > A.objects.all() is resulting in CPU hitting almost 100%. What's the problem

Re: Django queryset High CPU Usage

2017-03-09 Thread Web Architect
Would like to further add - the python CPU Usage is hitting almost 100 %. When I run a Select * query on Mysql, its quite fast and CPU is normal. I am not sure if anything more needs to be done in Django. On Friday, March 10, 2017 at 10:55:51 AM UTC+5:30, Web Architect wrote: > > Hi, > > I am

Django queryset High CPU Usage

2017-03-09 Thread Web Architect
Hi, I am a bit perplexed by this and not sure what the solution is. Following is the scenario: There is a Model A with 1 records. Just a simple queryset - A.objects.all() is resulting in CPU hitting almost 100%. Is there a way to optimize this? But why would such a query result in high CPU

Re: django queryset/annotate get extra column

2016-05-20 Thread stunaz
Wonderfull (ps :sorry, I should have put the model) On Friday, May 20, 2016 at 2:40:33 AM UTC-4, James Schneider wrote: > > On Wed, May 18, 2016 at 9:54 PM, stunaz > > wrote: > >> Hi, >> I would like to write the following query using django orm. >> >> select * , >> (select image_url from blog_im

Re: django queryset/annotate get extra column

2016-05-19 Thread James Schneider
On Wed, May 18, 2016 at 9:54 PM, stunaz wrote: > Hi, > I would like to write the following query using django orm. > > select * , > (select image_url from blog_image bi where bi.blog_id = b.id and bi. > principal=1) as blog_main_imange > from blog b > > > Any idea, how to write the queryset ? >

django queryset/annotate get extra column

2016-05-18 Thread stunaz
Hi, I would like to write the following query using django orm. select * , (select image_url from blog_image bi where bi.blog_id = b.id and bi. principal=1) as blog_main_imange from blog b Any idea, how to write the queryset ? -- You received this message because you are subscribed to the Goog

WHEN EXISTS Query in SQL to Django Queryset

2015-08-20 Thread Dheerendra Rathor
"event_eventviews"."event_id"=("event_event"."id")) THEN True ELSE False END AS "liked", CASE WHEN EXISTS (SELECT * FROM "event_eventviews" WHERE "event_eventviews". "user_id" = 5 AND "event_eventviews".&q

Tricky Django QuerySet with Complicated ForeignKey Traversals

2014-11-19 Thread Rodney Lewis
Please check out my question on StackOverflow: http://stackoverflow.com/questions/27016026/tricky-django-queryset-with-complicated-foreignkey-traversals I really appreciate any help you can offer. -- Rodney Lewis http://www.youtube.com/pyrodney -- You received this message because you are

Re: Django Queryset with filtering on reverse foreign key failing

2014-07-31 Thread Anthony
Could not resolve tblconfigagentgroupmembers. I've resolved the issue now though. I moved the model to models.py from the models_auto.py file and was then getting some validation errors mostly missing id fields(just set primary keys on the generated models) and now it's working as expected. On F

Re: Django Queryset with filtering on reverse foreign key failing

2014-07-31 Thread cmawebsite
What does the FieldError say? -- 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 post to this group, send email to dja

Django Queryset with filtering on reverse foreign key failing

2014-07-24 Thread Anthony Hawkes
Hi All, I'm currently using a MSSQL DB to access some data and am using django's inspectdb results. I've had to tweak some of the model but so far things have been smooth sailing. Today I needed to run a lookup that spanned through some tables forward and reverse and tested the following in s

Mocking Django queryset

2014-06-01 Thread Boris Ozegovic
Hi I am having trouble mocking querysets which contains slice. Example qs = Thread.objects.filter(some_filter).order_by(some_order')[:app_settings.SEARCH_LIMIT] And in my test I have: Thread.objects.assert_has_calls([ mock.call.filter('some_filter'), mock.call.filter()

Re: Suggestions for Paginating a Growing Django Queryset

2014-05-30 Thread Babatunde Akinyanmi
Like someone said, you can consider caching the entire queryset. That will definitely impact memory. Another idea is to play with timestamps in your query since you don't care if the results are not accurate. Maybe you shouldn't paginate then you can draw out the whole queryset, render them on the

Suggestions for Paginating a Growing Django Queryset

2014-05-30 Thread Riegie Godwin
Hello everyone! I've been stuck for about a week trying to figure this out. Been on all sorts of blogs and asked questions on stackoverflow in hopes that it would lead in the right direction. I would like to know what you think I could do. Let's say I have 4 models, a User model, Blog

Re: Django queryset csv encode

2014-05-26 Thread hito koto
Hi, WongoBongo, Thanks 2014年5月26日月曜日 18時39分20秒 UTC+9 WongoBongo: > > If you want all the user_name's in Staff as UTF-8: > > staff = Staff.objects.all() > staff_list = [s.user_name.encode('utf-8') for s in staff] > > I'm not familiar with the encoding you mentioned in your last message. Try > i

Re: Django queryset csv encode

2014-05-26 Thread Kelvin Wong
If you want all the user_name's in Staff as UTF-8: staff = Staff.objects.all() staff_list = [s.user_name.encode('utf-8') for s in staff] I'm not familiar with the encoding you mentioned in your last message. Try it. K On Monday, May 26, 2014 2:12:14 AM UTC-7, hito koto wrote: > > Hi, > > this

Re: Django queryset csv encode

2014-05-26 Thread Kelvin Wong
Okay, I re-read your first post. You said that you wanted to get a UTF-8 string. name = [name.encode("utf8") for name in Staff.objects.filter(id = 3).values_list('user_name', flat=True)] This variable 'name' now contains a UTF-8 encoded string in a list-like object. Python 2.7.6 (default, Jan

Re: Django queryset csv encode

2014-05-25 Thread hito koto
Hi, I have this: >>> x = name >>> import locale >>> locale.getdefaultlocale()[1] 'UTF8' >>> print x ['\xe5\x93\x88\xe6\x96\xaf\xe6\x9c\x9d\xe9\xad\xaf'] after i try this : >>> name ['\xe5\x93\x88\xe6\x96\xaf\xe6\x9c\x9d\xe9\xad\xaf'] >>> type(name) Traceback (most recent call last): File "",

Re: Django queryset csv encode

2014-05-25 Thread WongoBongo
Python 2.7.6 (default, Jan 13 2014, 04:26:18) [GCC 4.2.1 (Apple Inc. build 5577)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x = u'\u54c8\u65af\u671d\u9b6f' >>> print(x) 哈斯朝魯 >>> import locale >>> locale.getdefaultlocale()[1] 'UTF-8' >>> K On Sunday, May

Re: Django queryset csv encode

2014-05-25 Thread hito koto
Hi, I'm try tha's but results: >>> b'\xe5\x93\x88\xe6\x96\xaf\xe6\x9c\x9d\xe9\xad\xaf'.decode('utf8') u'\u54c8\u65af\u671d\u9b6f' 2014年5月26日月曜日 14時10分44秒 UTC+9 WongoBongo: > > Python 3.4.0 (default, Mar 20 2014, 12:50:31) > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > Type "help", "copyri

Re: Django queryset csv encode

2014-05-25 Thread Kelvin Wong
Python 3.4.0 (default, Mar 20 2014, 12:50:31) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> b'\xe5\x93\x88\xe6\x96\xaf\xe6\x9c\x9d\xe9\xad\xaf'.decode('utf8') '哈斯朝魯' K On Sunday, May 25, 2014 9:23:47 PM UTC-7, hito koto

Re: Django queryset csv encode

2014-05-25 Thread hito koto
Hi, I7m try that's this time not the error but output the ['\xe5\x93\x88\xe6\x96\xaf\xe6\x9c\x9d\xe9\xad\xaf'] 2014年5月26日月曜日 13時15分41秒 UTC+9 WongoBongo: > > Try > > name = [name.encode("utf8") for name in Staff.objects.filter(id = > 3).values_list('user_name', *flat=True*)] > > The other

Re: Django queryset csv encode

2014-05-25 Thread Kelvin Wong
Try name = [name.encode("utf8") for name in Staff.objects.filter(id = 3).values_list('user_name', *flat=True*)] The other returns one-tuples in a list https://docs.djangoproject.com/en/dev/ref/models/querysets/#values-list K On Sunday, May 25, 2014 7:55:51 PM UTC-7, hito koto wrote: > > Hi, >

Django queryset csv encode

2014-05-25 Thread hito koto
Hi, I want to encode in utf8 but don't know how can i to ? i have the errors is here: AttributeError: 'tuple' object has no attribute 'encode' My code is here : name = [name.encode("utf8") for name in Staff.objects.filter(id = 3).values_list('user_name')] -- You received this message becaus

Re: How to create Union in Django queryset

2014-04-17 Thread Simon Charette
I'm not sure this will work but you could try creating a VIEW on the database side that does the union there and access it through an un-managed model. CREATE VIEW *view_name* AS SELECT id, name FROM *a* UNION SELECT id, name FROM *b*; class C(models.Model): name = models.CharField()

Re: How to create Union in Django queryset

2014-04-17 Thread Thomas Lockhart
On 4/16/14 11:51 PM, Shoaib Ijaz wrote: I don't want use SQL query in django OK. You *could* have class B inherit from class A: class B(A): link = models.IntegerField(blank=True, null=True) and then do your query on A: ulist = A.objects.all() hth - Tom On Th

Re: How to create Union in Django queryset

2014-04-16 Thread Shoaib Ijaz
I don't want use SQL query in django On Thursday, 17 April 2014 04:39:09 UTC+5, Russell Keith-Magee wrote: > > On Wed, Apr 16, 2014 at 9:30 PM, Shoaib Ijaz > > > wrote: > > Sorry for duplicate post How to create Union > > > > I am using Django REST Framework in project and I want to create un

Re: How to create Union in Django queryset

2014-04-16 Thread Russell Keith-Magee
On Wed, Apr 16, 2014 at 9:30 PM, Shoaib Ijaz wrote: > Sorry for duplicate post How to create Union > > I am using Django REST Framework in project and I want to create union two > different Models. > > My Models > > class A(models.Model): > name = models.CharField(max_length=240, blank=True) >

How to create Union in Django queryset

2014-04-16 Thread Shoaib Ijaz
Sorry for duplicate post How to create Union<http://stackoverflow.com/questions/23110658/how-to-create-union-in-django-queryset> I am using Django REST Framework in project and I want to create union two different Models. *My Models* class A(models.Model): name = models.Cha

Re: Django queryset 'in' operator fails on first call

2013-04-13 Thread Peter of the Norse
On Apr 10, 2013, at 7:44 AM, bradley griffiths wrote: > Corss posted from stack overflow > > When using the 'in' operator on a queryset, the first time the call is made > it fails. > > from django.db import models > > > class Category(models.Model): > name = models.CharField(max_length=1

Re: Django queryset 'in' operator on two querysets fails on first call

2013-04-10 Thread Tom Evans
On Wed, Apr 10, 2013 at 2:26 PM, bradley griffiths wrote: > Cross posted from: stack overflow. > > When using the 'in' operator on two querysets, the first time the call is > made it fails. > > … > > print category_list # [, ] > print other_cats # [] > print category_list[0] in other_cats # False

Re: Django queryset 'in' operator on two querysets fails on first call

2013-04-10 Thread carlos
maybe need read de docu https://docs.djangoproject.com/en/1.5/ref/models/querysets/#select-related Cheers On Wed, Apr 10, 2013 at 7:26 AM, bradley griffiths < bradley.griffi...@gmail.com> wrote: > Cross posted from: stack > overflow<http://stackoverflow.com/questions/15923809/

Django queryset 'in' operator fails on first call

2013-04-10 Thread bradley griffiths
Corss posted from stack overflow<http://stackoverflow.com/questions/15923809/django-queryset-in-operator-fails-on-first-call> When using the 'in' operator on a queryset, the first time the call is made it fails. from django.db import models class Category(models.

  1   2   >