How add raw query in a Model

2021-02-28 Thread Asaduzzaman Sohel
;) if len(status_list) > 0 or len(order_list) > 0: orders = orders.filter( Q(status__in=status_list) | Q(id__in=order_list), Q(payment_details__status__in=[PaymentStatus.PAY_LATER, PaymentStatus.CONFIRMED]) ) else: orders = orders.filter( Q(status=OrderStatus.UNFULFILLED), Q(payme

Merging or joining raw query set results.

2019-09-14 Thread ML
Hi, I have a raw query which takes in 4 ids within a for loop. It therefore returns 4 query set results. I put the result of each query set into a dictionary and append it to a list. The result looks something like this: [{'first_name': u'John'}, {'first_name': u

Re: Django sql raw query to queryset

2019-08-22 Thread Suraj Thapa FC
Invalid field name error On Fri, 23 Aug, 2019, 11:58 AM Sipum, wrote: > You can use Queryset like - > > course_review_report.objects.select_related('courses') > > On Fri, 23 Aug, 2019, 11:07 AM Suraj Thapa FC, > wrote: > >> SELECT * >> FROM course_review_report LEFT JOIN courses ON course_revie

Re: Django sql raw query to queryset

2019-08-22 Thread Sipum
You can use Queryset like - course_review_report.objects.select_related('courses') On Fri, 23 Aug, 2019, 11:07 AM Suraj Thapa FC, wrote: > SELECT * > FROM course_review_report LEFT JOIN courses ON course_review_report.cid = > courses.cid > > > Can anyone pls write the querryset for the above sq

Django sql raw query to queryset

2019-08-22 Thread Suraj Thapa FC
SELECT * FROM course_review_report LEFT JOIN courses ON course_review_report.cid = courses.cid Can anyone pls write the querryset for the above sql query -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop r

Re: Raw query returns 1 row but outputting multiple rows in template

2016-10-06 Thread Andromeda Yelton
What's in the get_digital_client_summary() function? On Thu, Oct 6, 2016 at 6:18 AM, Thomas Brightwell < thomas.brightw...@gmail.com> wrote: > Hi, > > I have a raw query returning one row which is then shown 8 times in the > template. I have debugged and there is onl

Raw query returns 1 row but outputting multiple rows in template

2016-10-06 Thread Thomas Brightwell
Hi, I have a raw query returning one row which is then shown 8 times in the template. I have debugged and there is only one line when this is executed in the shell and I do a simple for loop print output. So it seems to be something about the template tags? The raw query which definitely only

Re: Hebrew in Raw Query Like Clause

2016-07-08 Thread Art Zemon
Michal, Actually, your syntax didn't quite work. It threw a couple of warnings and seemed to match all records in the database. But you got me on the right track. This syntax does work properly: select ... where word like concat('%%', %s, '%%') Thanks for getting me pointed in the right direc

Re: Hebrew in Raw Query Like Clause

2016-07-08 Thread Art Zemon
On Friday, July 8, 2016 at 8:34:00 AM UTC-5, Michal Petrucha wrote: > > I may be wrong, but it seems to me that you're using wrong quoting in > that raw query; I think it should be:: > > select sortkey, book, chapter, verse, hebrew_text > from bible_bible >

Re: Hebrew in Raw Query Like Clause

2016-07-08 Thread Michal Petrucha
de that, and take a look at the actual SQL query generated for that; maybe it will reveal some oddity. > I tried a raw query in a custom manager: > > class BibleManager(models.Manager): > def contains_hebrew_word(self, word='דֶּשֶׁא'): > sql = "&qu

Hebrew in Raw Query Like Clause

2016-07-08 Thread Art Zemon
Bible.objects.filter(hebrew_text__contains('דֶּשֶׁא') and I get nothing back. I tried a raw query in a custom manager: class BibleManager(models.Manager): def contains_hebrew_word(self, word='דֶּשֶׁא'): sql = """select sortkey, book, chapter, verse

Re: "Raw query must include the primary key" when inheriting models

2014-10-30 Thread Collin Anderson
Hi Tobias, Based on your database query, it looks like you are not doing multiple table inheritance, but your models are set up for multiple table inheritance. https://docs.djangoproject.com/en/dev/topics/db/models/#model-inheritance Why not just have a status field on your Campaign model? Djan

"Raw query must include the primary key" when inheriting models

2014-10-29 Thread Tobias Wolff
f.to_native(item)foritem inobj] File".../env/lib/python3.4/site-packages/rest_framework/serializers.py"in 570.self._data =[self.to_native(item)foritem inobj] File".../env/lib/python3.4/site-packages/django/db/models/query.py"in__iter__ 1553.raiseInvalidQuery('Raw query m

Re: Correctly passing parameters to raw query

2014-09-24 Thread James Brewer
Also, it is worth mentioning that the RawQuerySet object looks to have been refactored in the latest development release. I have not verified this issue on the development branch. On Wed, Sep 24, 2014 at 3:53 PM, James Brewer wrote: > This is going to depend on the version of Django you're using

Re: Correctly passing parameters to raw query

2014-09-24 Thread James Brewer
This is going to depend on the version of Django you're using. Accord to the docs for 1.7[1], this should work fine. After playing around in the shell for a bit, I found I was getting an error complaining about arguments not being converted during string formatting. It seems the problem occurs whe

Re: Correctly passing parameters to raw query

2014-09-24 Thread Collin Anderson
Interesting. I don't use raw queries, but I wonder if Django doesn't support lists as parameters to raw() -- 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

Correctly passing parameters to raw query

2014-09-24 Thread termopro
Hello, I am constructing raw query which looks like the following: "SELECT * FROM some_table WHERE id IN (1,3,5);" So inside my view i write: entities = Entity.objects.raw(""" SELECT * FROM some_table WHERE id IN (%s); """, [ids_list]) How should i corr

Raw query

2014-06-16 Thread Ahmed Adam
I want to create series of tables using mysql raw query with multiple lines in django view. Please 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

Re: Casting a raw query set as a list for pagination

2014-04-26 Thread Matt Buck
I've created a paginator for RawQuerySets. https://github.com/seamusmb/django-paginator-rawqueryset On Tuesday, March 26, 2013 5:51:41 AM UTC-4, chambe...@gmail.com wrote: > > I'm trying to implement Django's built in pagination feature with a raw > query set. I've

Re: RAW query to non default DB

2014-03-07 Thread Tom Evans
On Fri, Mar 7, 2014 at 3:31 PM, bikeridercz wrote: > Dear colleagues, > > I'm trying to do a direct select do database other than the default one. But > it fails with error. > > Note 1: "ASSETS.objects.using('vodb').filter(...)" works fine > Note 2: the select is little tricky and unfortunately ca

RAW query to non default DB

2014-03-07 Thread bikeridercz
Dear colleagues, I'm trying to do a direct select do database other than the default one. But it fails with error. Note 1: "ASSETS.objects*.using('vodb')*.filter(...)" works fine Note 2: the select is little tricky and unfortunately cannot be replaced by a database view, because I have no acces

Re: Problem with raw query and using in

2013-11-19 Thread huw_at1
Hi, I think I had something similar and followed this thread: http://stackoverflow.com/questions/4574609/executing-select-where-in-using-mysqldb I think this is what Dennis has already said so apologies if it isn't helpful. Kindest regards On Saturday, 16 November 2013 12:40:52 UTC, Thorsten

Re: Problem with raw query and using in

2013-11-17 Thread Thorsten Sanders
meter differently -- along with the query string. MySQL, and most other SQL systems, as I recall, expect to see ... needle in (first, second, ..., last) MySQLdb sanitizes parameters by converting them to a string representation, escaping any special characters, and wrapping it is

Re: Problem with raw query and using in

2013-11-16 Thread Thorsten Sanders
I am using mysql and when I write it like (1) then I get int is not iterable on the first one, but the raw works, if I do it like (1,) the first one works, but the raw one gets again the comma at the end, tried several ways always one of both not working, for me it looks kinda there is some mag

Re: Problem with raw query and using in

2013-11-16 Thread Javier Guerra Giraldez
On Sat, Nov 16, 2013 at 7:40 AM, Thorsten Sanders wrote: > realms=[1] > data = AuctionData.objects.filter(itemid__exact=itemid,realm__in=realms) > data2 = AuctionData.objects.raw('SELECT * FROM auctiondata_auctiondata WHERE > itemid_id=%s AND realm_id in %s ',[itemid,realms]) not sure if it's re

Problem with raw query and using in

2013-11-16 Thread Thorsten Sanders
Hello, wondering if I am doing something wrong or it is a bug, using django 1.5.5, but also tried with 1.6 resulting in the same problem. When I do the following: realms=[1] data = AuctionData.objects.filter(itemid__exact=itemid,realm__in=realms) data2 = AuctionData.objects.raw('SELECT * FROM

Re: Casting a raw query set as a list for pagination

2013-03-26 Thread Bill Freeman
7;m trying to implement Django's built in pagination feature with a raw > query set. I've researched the issue and the answer is I need to cast my > set as a list. Something like this: > > paginator = Paginator(refg, 100) # Show 100 contacts per page > paginator._count = len

Casting a raw query set as a list for pagination

2013-03-26 Thread chambers24889
I'm trying to implement Django's built in pagination feature with a raw query set. I've researched the issue and the answer is I need to cast my set as a list. Something like this: paginator = Paginator(refg, 100) # Show 100 contacts per page paginator._count = len(list(r

Raw query with "where-in" clause

2013-02-10 Thread Thanos Diacakis
Hey all, I have the following query: cursor.execute( "select * from MyTable where Foo=%s or Bar in %s", [some_id, some_array] ) This seems to work fine if len(some_array) > 1 but it blows up if there are zero or one items in the array (invalid SQL syntax). Is there a better way to do this? T

Re: raw query placeholder "%(key)s" supported in django?

2012-01-03 Thread Bill Freeman
I have used this in a raw query. But it depends on the DB backend of Django. If I'm remembering correctly, it worked with PostgreSQL/psycopg2, but not with SQLite/whatever_back_end when I was using it. Bill On Sun, Dec 25, 2011 at 3:58 AM, ali alizadeh wrote: > hi. > > in psycop

Re: raw query placeholder "%(key)s" supported in django?

2012-01-03 Thread Andre Terra
If you're talking about string formatting operations, Django is just Python, so %(key)s will work. Cheers, AT On Wed, Dec 28, 2011 at 9:01 AM, ali alizadeh wrote: > > hi. > > in psycopg module, when composing a query, you can use "%(key)s" in your > query instead of "%s", and pass a dictionary

raw query placeholder "%(key)s" supported in django?

2011-12-28 Thread ali alizadeh
hi. in psycopg module, when composing a query, you can use "%(key)s" in your query instead of "%s", and pass a dictionary instead of a list for actual parameter. django docs mention the "%s" syntax for raw queries. i was just wondering if the other syntax is supported or not, because it can be han

raw query placeholder "%(key)s" supported in django?

2011-12-25 Thread ali alizadeh
hi. in psycopg module, when composing a query, you can use "%(key)s" in your query instead of "%s", and pass a dictionary instead of a list for actual parameter. django docs mention the "%s" syntax for raw queries. i was just wondering if the other syntax is supported or not, because it can be han

Re: custom template tags with a raw query

2010-06-16 Thread Cole743
The first link I had seen and used. My custom query works, I had just been having issues with the tags. I had been through the docs and seen a different one on tags, but apparently passed over the one you posted in the link. It filled in some of the gaps I was missing, thanks. Very helpful. -- Yo

Re: custom template tags with a raw query

2010-06-15 Thread Vasil Vangelovski
To use custom SQL see this for reference: http://docs.djangoproject.com/en/dev/topics/db/sql/ To create a templatetag see this for reference: http://docs.djangoproject.com/en/dev/howto/custom-template-tags/ On Mon, Jun 14, 2010 at 10:08 PM, Cole743 wrote: > Hello again, > > My last question

custom template tags with a raw query

2010-06-14 Thread Cole743
Hello again, My last question may have been unclear, so I'm going to be more specific. I want to use the results of this: cursor.execute("SELECT * from sp_getreport(""varchar"" %s)", [usr]) (or something similar) In a custom template tag to display in a template. The results of the query are: a