Re: Queryset in settings.py?

2022-01-28 Thread Fabio C. Barrionuevo da Luz
The solution I think of for this is to overwrite get_template_names https://ccbv.co.uk/projects/Django/4.0/django.views.generic.base/TemplateView/#get_template_names I quickly made a draft implementation (which I couldn't test) from django.core.exceptions import ImproperlyConfigured from django

Re: Queryset in settings.py?

2022-01-28 Thread Sebastian Jung
Hello Fabio, i want that admin can make in database a entry to a field in my own settings model in field standardtemplatepath for example /newtemplate/ in my views.py there are exists a normal CBV Templateview with template_name = 'Testtemplate.html' and in settings.py i have a entry TEMPLATES = [

Re: Queryset in settings.py?

2022-01-28 Thread Fabio C. Barrionuevo da Luz
Hi Sebastian, I guess this is not possible. But the real question is: why do you need a queryset to perform in the settings? Perhaps if you explain what problem you want to solve, we can give you some options for other possible solutions. Em sex., 28 de jan. de 2022 às 20:00, sebasti...@gmail.

Re: QuerySet performance on large datasets

2021-04-11 Thread Peter of the Norse
Follow up to my own message. I found a way of testing this that I think everyone should look at: $ ./manage.py shell Python 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)] on darwin Type "help", "copyright", "credits" or "license" for more information. (InteractiveCons

Re: QuerySet performance on large datasets

2021-02-12 Thread Peter of the Norse
bool(qs) is recommended when the queryset has already been run. If you do something like val = qs.earliest(some_property) if bool(qs) else None then there isn’t a performance gain because it still has to run qs.exists() to even see if there is a value. Later things like that will be cach

Re: QuerySet not iterable

2019-10-10 Thread Abhijeet Viswa
Hey there guys, I'm happy to say that we've finally figured out the bug. It was never an error with the underlying DBMS or Django itself. It was our code. It's sad that we didn't figure it out sooner and had to spend so many man hours on this. As I said, the *select_for_update *was never a pr

Re: QuerySet not iterable

2019-10-08 Thread Abhijeet Viswa
Hello, Thank your for your reply. I'm not using Python 2. I have attached the traceback as is emailed by Django to the Admin. Traceback: > > File > "/home/user/api/env/lib/python3.6/site-packages/django/core/handlers/exception.py" > > in inner > 34. response = get_response(req

Re: QuerySet not iterable

2019-10-08 Thread Simon Charette
Hello there, >From looking at your code (super() calls) it seems like your are using Python 2. We've seen similar reports about stdlib functions hiding system level exceptions instead of surfacing them[0] so that might it. It's hard to tell without the full traceback though. Best, Simon [0]

Re: Queryset - exclude one data over two

2019-01-26 Thread Stéphane Manguette
Thanks ! It works perfectly ! Le vendredi 25 janvier 2019 17:07:05 UTC+1, C. Kirby a écrit : > > You can use islice from itertools in this way > > islice('ABCDEFG', 0, None, 2) --> A C E G > > In your case you would replace > chart = temp_db.objects.filter(date__gte=beg_range) > > with > chart =

Re: Queryset - exclude one data over two

2019-01-25 Thread C. Kirby
You can use islice from itertools in this way islice('ABCDEFG', 0, None, 2) --> A C E G In your case you would replace chart = temp_db.objects.filter(date__gte=beg_range) with chart = [x for x in islice(temp_db.objects.filter(date__gte=beg_range), 0, None, 2)] That will give you every other

Re: Queryset calculation and then filter/exclude/limit data rendered

2018-06-30 Thread rod termaat
I figured it out. Probably not the ideal solution, but it works for now. I did not realize you could use an IF tag in the the template. I then passed the fromDate and toDate into the template and used that to limit the records to only that particular month. Hopefully as my skills increase I w

Re: Queryset calculation and then filter/exclude/limit data rendered

2018-06-29 Thread rod termaat
I totally get what you are saying and thanks. I tried a similar strategy. I do qs = Check.objects.all() and then I have to do the calculation as there is no balance in the model so I generate it on the fly in the for loop. My hope was to then filter qs like you show. It works, but my balan

Re: Queryset calculation and then filter/exclude/limit data rendered

2018-06-29 Thread Derek
Its not completely clear what you are doing. You need to avoid logic in your template; but you say "excluding data from the the queryset in the for loop which is easy in other languages, but this also seemed to be a no go". That is not the case if your logic is written in the correct way. In

Re: QuerySet for related models

2016-08-05 Thread M Hashmi
Thanks Todor/Constantine for your help, I've added a field in my Product models with generic relations like: hitcounts = GenericRelation(HitCount, content_type_field='content_type', object_id_field='object_pk',) In my view: object_list = Product.objects.order_by('-hitcounts__hits')[:6] In my tem

Re: QuerySet for related models

2016-08-05 Thread M Hashmi
Todor, You have access to my complete repo but still I will post answer here for others to learn. Regards, Mudassar On Fri, Aug 5, 2016 at 6:06 AM, Todor Velichkov wrote: > Honestly, now Idea why you get this error, can you paste some more code? > And maybe some stack trace? > > On Friday, Aug

Re: QuerySet for related models

2016-08-05 Thread Todor Velichkov
Honestly, now Idea why you get this error, can you paste some more code? And maybe some stack trace? On Friday, August 5, 2016 at 2:20:25 PM UTC+3, M Hashmi wrote: > > 1.8.13 as its LTS. > > On Fri, Aug 5, 2016 at 3:54 AM, Todor Velichkov > wrote: > >> Whats your Django version? >> >> On Friday,

Re: QuerySet for related models

2016-08-05 Thread M Hashmi
1.8.13 as its LTS. On Fri, Aug 5, 2016 at 3:54 AM, Todor Velichkov wrote: > Whats your Django version? > > On Friday, August 5, 2016 at 1:42:48 PM UTC+3, M Hashmi wrote: >> >> I did the same thing while working with the contenttype except I did used >> default filters .all(), .filter(), .get(),

Re: QuerySet for related models

2016-08-05 Thread Todor Velichkov
Whats your Django version? On Friday, August 5, 2016 at 1:42:48 PM UTC+3, M Hashmi wrote: > > I did the same thing while working with the contenttype except I did used > default filters .all(), .filter(), .get(), annotations and aggregations > etc. Todor each product shows multiple hits if I log

Re: QuerySet for related models

2016-08-05 Thread M Hashmi
I did the same thing while working with the contenttype except I did used default filters .all(), .filter(), .get(), annotations and aggregations etc. Todor each product shows multiple hits if I log out and hit it and login back to hit it shows more than one hits. Hits are being recoreded for each

Re: QuerySet for related models

2016-08-05 Thread Todor Velichkov
Constantine Covtushenko, HitCount is a model from a 3rd party app, so the OP can't change it. However the way HitCount is implemented I don't think one there is a way for one product to have more than one `HitCount` objects. So I don't think any aggregations are needed. Lets the Product cla

Re: QuerySet for related models

2016-08-04 Thread M Hashmi
Thanks for reply and I tried this before same exact code but I got stuck at "unhashable type" error. I searched it thoroughly but then I gave up on it to have some guidance from kind people like you. If you believe this is how it should work then please provide me some quick ref for the error.

Re: QuerySet for related models

2016-08-04 Thread Constantine Covtushenko
Hi M Hashmi, I believe that you are looking a way to use aggregation on related model. You should try the following snitppet: `trending_products = Product.objects.aggregate(hit=Max('hits__hits'))[:6]` (see more info here ) This will gi

Re: QuerySet for related models

2016-08-04 Thread M Hashmi
Hello Todor, I followed your directions and used https://docs.djangoproject.com/ja/1.9/ref/contrib/contenttypes/ for reference but I got stuck at error 'GenericForeignKey' object has not attribute 'get_lookup'. I tried Product.objects.aggregate(Count('hits'))[:6]. In my models.py I got follow

Re: QuerySet for related models

2016-08-04 Thread M Hashmi
Thank you Constantine, I got this mistake fixed and this was really bad mistake from my side. Now with your proposed scenario I am trying to get it work with "trending_products = Product.objects.all().order_by('hits__hits')[:6]" but still it isn't giving me sort by max hits as I used annotate m

Re: QuerySet for related models

2016-08-04 Thread M Hashmi
Thanks Todor as this make senseall I need is to get the Hitcount's hits presented as local variable to Product model so in queryset I can set order_by. I will try this and will post results. On Thursday, August 4, 2016 at 2:07:53 PM UTC-7, Todor Velichkov wrote: > > My field hits=models.Fore

Re: QuerySet for related models

2016-08-04 Thread Constantine Covtushenko
Please check my notes below: On Thu, Aug 4, 2016 at 10:42 PM, M Hashmi wrote: > My field hits=models.ForeignKey(Hitcount) means that my Product model has > a related model with multiple fields and all the products in Product model > will have one or more hit records. > Sorry but I do not see ho

Re: QuerySet for related models

2016-08-04 Thread Todor Velichkov
> > My field hits=models.ForeignKey(Hitcount) means that my Product model has > a related model with multiple fields and all the products in Product model > will have one or more hit records. Instance of Product model will save a > hit from end user by session/ip/user etc. Honestly, I don't u

Re: QuerySet for related models

2016-08-04 Thread M Hashmi
My field hits=models.ForeignKey(Hitcount) means that my Product model has a related model with multiple fields and all the products in Product model will have one or more hit records. Instance of Product model will save a hit from end user by session/ip/user etc. -- You received this message

Re: QuerySet for related models

2016-08-04 Thread Constantine Covtushenko
Hi M Hashmi, As I see your model scheme built with meaning that 1 record of HitCount relates to many records of Product. And in your queries you try to select all products that relate to 5 topmost HitCounts. Am I correct? Will be waiting for your response. On Thu, Aug 4, 2016 at 6:41 PM, M Has

Re: QuerySet values() or values_list() with some RelatedObjectDoesNotExist records returns only those records with valid related intances

2015-11-18 Thread Steve W
Solved or Work-Around: #Include a 'select_related()' invocation in the queryset chain, against the related model(s): cases = Case.objects.select_related('release').all() cases.count() 228 fieldnames = ('reference','release__release') records = cases.values(*fieldnames) records.count() 228 #OK,

Re: queryset: LEFT OUTER JOIN with extra conditions in django ORM

2015-06-06 Thread Michael Palumbo
Yes, I tried removing the all() but that does not change anything. On Sat, Jun 6, 2015 at 3:57 PM, James Schneider wrote: > Have you tried taking out the .all()? You don't need that if you're using > filter(). I don't think that will help though. > > -James > On Jun 6, 2015 12:42 PM, "Michael"

Re: queryset: LEFT OUTER JOIN with extra conditions in django ORM

2015-06-06 Thread James Schneider
Have you tried taking out the .all()? You don't need that if you're using filter(). I don't think that will help though. -James On Jun 6, 2015 12:42 PM, "Michael" wrote: > Just to give more information about the solution using Case, When, etc. > Here is what I tried: > > qs = User.objects.all().

Re: queryset: LEFT OUTER JOIN with extra conditions in django ORM

2015-06-06 Thread Michael
Just to give more information about the solution using Case, When, etc. Here is what I tried: qs = User.objects.all().annotate(modela__count=models.Count(Case(When( modela__deleted_at__isnull=True, then=1 which turns into the following SQL query: SELECT COUNT(CASE WHEN "modela"."deleted_at"

Re: Queryset .count() breaks when counting distinct values generated by .extra()

2015-01-21 Thread Collin Anderson
Hi, I don't use extra() a lot, but it could be that count() clears out extra. This doesn't exactly answer your question, but you may want to try your query on the 1.8 alpha using the new available expressions. You might be able to do this without needing extra() at all in 1.8. Collin On Sunda

Re: QuerySet doubt

2014-04-11 Thread Rafael E. Ferrero
I think, for what i see on his docs, that https://github.com/chrisglass/django_polymorphic can help in my task. Saludos Cordiales, -- Rafael E. Ferrero 2014-04-11 2:35 GMT-03:00 Rafael E. Ferrero : > Found a bug in that view (see revision 3 of linkode) but my ignorance > about iterate or perfo

Re: QuerySet doubt

2014-04-10 Thread Rafael E. Ferrero
Found a bug in that view (see revision 3 of linkode) but my ignorance about iterate or perform the object for template still remains. Saludos Cordiales, -- Rafael E. Ferrero 2014-04-11 1:00 GMT-03:00 Rafael E. Ferrero : > An SQL who can solve my trouble its here > http://linkode.org/DqwJ0ljeE4w

Re: QuerySet doubt

2014-04-10 Thread Rafael E. Ferrero
An SQL who can solve my trouble its here http://linkode.org/DqwJ0ljeE4wdsqw1G9Q8g7 but, with that i obtain something like this: *ArticleTitle GallerieTitle PicTitle* Fusce luctus scelerisque doloruna galeria una foto Fusce luctus scel

Re: Queryset Filters

2014-04-08 Thread Jill Green
Thank you for the response. I feared the answered would be no but I wanted to be sure. Sent from my iPhone On Apr 9, 2014, at 12:27 AM, Anssi Kääriäinen wrote: > No, there is no way to do what you want. All filters are implemented as > filters in the DB, Django doesn't know how to execute th

Re: Queryset Filters

2014-04-08 Thread Anssi Kääriäinen
No, there is no way to do what you want. All filters are implemented as filters in the DB, Django doesn't know how to execute them in Python. There was some effort to implement filters also in Python, but there hasn't been any activity on this recently. The only way to do this currently is to i

Re: QuerySet to cover a date range

2013-09-10 Thread Borislav Borisov
Hey, You can use https://docs.djangoproject.com/en/dev/ref/models/querysets/#range. Cheers. On Tue, Sep 3, 2013 at 7:02 PM, Neil Menne wrote: > Hello, all! > > I'm trying to get a query set that 'covers' a date range. Each object only > contains a single date. For example, given a start date

Re: Queryset math

2013-05-30 Thread Avraham Serour
try using annotate, you can do something like Entry.objects.extra(select={'diff': "A - B"}) take a look at https://docs.djangoproject.com/en/dev/ref/models/querysets/#extra On Thu, May 30, 2013 at 11:46 PM, Javier Guerra Giraldez wrote: > On Thu, May 30, 2013 at 3:18 PM, SeanJ wrote: > > as s

Re: Queryset math

2013-05-30 Thread Javier Guerra Giraldez
On Thu, May 30, 2013 at 3:18 PM, SeanJ wrote: > as soon as those values come from the queryset I can't do math on them. what have you tried? -- Javier -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop re

Re: queryset minimization

2013-03-07 Thread Nikolas Stevenson-Molnar
Also, I strongly recommend reading through this document for an idea of when queries do and don't hit the database: https://docs.djangoproject.com/en/1.5/topics/db/optimization/ Additionally, take a look at django-debug-toolbar, which will show you all the queries that go into returning a view, ho

Re: queryset minimization

2013-03-07 Thread Nikolas Stevenson-Molnar
1. No, the two will execute identically. 2. No, `group` is loaded by select_related, and `name` is a field on group, so it's loaded when group is, unless you explicitly exclude it. 3. That's one query. However, if you're only grabbing the first result, select_related isn't even necessary... just do

Re: queryset minimization

2013-03-07 Thread Fatih Tiryakioglu
Thank you Nicolas, This works: reg = p.groupregistration_set.all().select_related('group') name = reg[0].group.name This also works: name = p.groupregistration_set.all().select_related('group')[0].group.name 1) Is there any difference? Which one is beter. 2) reg = p.groupregistration_set.all().

Re: queryset minimization

2013-03-07 Thread Nikolas Stevenson-Molnar
The biggest hit is probably going to be the reg.group call. You can optimize that by using select_related (), which will take what is currently 1 + (number of group registrations for the user) queries and turn it into 2 queries: reg = p.groupregistration_set.all().select_related('group') More on

Re: QuerySet API - istartswith - use UPPER instead of ILIKE with PostgreSQL backend

2012-08-03 Thread Karen Tracey
On Wed, Aug 1, 2012 at 1:03 PM, Naoko wrote: > QuerySet API - istartswith - use UPPER instead of ILIKE with PostgreSQL > backend > which conflict with Documentation ( > https://docs.djangoproject.com/en/dev/ref/models/querysets/) > as documentation's example shows SQL equivalent as " ILIKE " > >

Re: 'QuerySet' object has no attribute '_meta' ... but I'm not using a QuerySet!

2012-07-26 Thread Tomas Neme
The ArtworkForm AND the full view code would be helpful, yes also, maybe you'll want to install django-extensions, werkzeug, and run your devserver with runserver_plus, that'll give you full debugging capabilities on your browser, and will be able to see what's each object (that instace object, sp

Re: 'QuerySet' object has no attribute '_meta' ... but I'm not using a QuerySet!

2012-07-25 Thread Babatunde Akinyanmi
Like the code for ArtworkForm On 7/26/12, Babatunde Akinyanmi wrote: > Looks good to me. Are you sure have shown us all the relevant parts of > your code? > > On 7/25/12, Deathweasel wrote: >> Hello, guys. >> This is Django 1.4. >> >> I have this code from my view: >> >> my_art = ArtworkMode

Re: 'QuerySet' object has no attribute '_meta' ... but I'm not using a QuerySet!

2012-07-25 Thread Babatunde Akinyanmi
Looks good to me. Are you sure have shown us all the relevant parts of your code? On 7/25/12, Deathweasel wrote: > Hello, guys. > This is Django 1.4. > > I have this code from my view: > > my_art = ArtworkModel.objects.get(id=pk) > comments = CommentModel.objects.filter(artwork=pk) > artForm = Ar

Re: [] Re: queryset caching - without caching middleware

2012-07-05 Thread Tom Evans
On Thu, Jul 5, 2012 at 4:08 PM, Henrik Genssen wrote: >>Could you show where and how you are executing the query? If the >>queryset is a global, and does not go out of scope at the end of the >>request, then reusing the queryset will not cause the queryset to be >>re-evaluated. >> >>Eg, in this ex

RE: [] Re: queryset caching - without caching middleware

2012-07-05 Thread Henrik Genssen
>Could you show where and how you are executing the query? If the >queryset is a global, and does not go out of scope at the end of the >request, then reusing the queryset will not cause the queryset to be >re-evaluated. > >Eg, in this example, categories is a global outside of the view, and >once

Re: queryset caching - without caching middleware

2012-07-05 Thread Tom Evans
On Thu, Jul 5, 2012 at 3:49 PM, Melvyn Sopacua wrote: > On 5-7-2012 14:28, hinnack wrote: >> - can I disable or force a "refresh" of the cache? > > > Transactions/READ REPEATED behaviour is unl

Re: queryset caching - without caching middleware

2012-07-05 Thread Melvyn Sopacua
On 5-7-2012 14:28, hinnack wrote: > - can I disable or force a "refresh" of the cache? -- Melvyn Sopacua -- You received this message because you are subscribed to the Google Groups "Djang

Re: queryset caching - without caching middleware

2012-07-05 Thread Tom Evans
On Thu, Jul 5, 2012 at 1:28 PM, hinnack wrote: > hmm, Ok, Queryset Caching happens alle the time... > > So here are some more questions on this: > - where is the data stored? > - can I ask a model, if its result is cached or a fresh one? > - can I disable or force a "refresh" of the cache? > - how

Re: queryset caching - without caching middleware

2012-07-05 Thread hinnack
hmm, Ok, Queryset Caching happens alle the time... So here are some more questions on this: - where is the data stored? - can I ask a model, if its result is cached or a fresh one? - can I disable or force a "refresh" of the cache? - how would i use a query in a property of a class, without runnin

Re: QuerySet exclusion

2012-02-17 Thread akaariai
On Feb 17, 6:33 pm, Lie Ryan wrote: > If I have two querysets, say 'a' and 'b', the goal is to create another > queryset, say 'c', which has all elements in 'a' that is not in 'b'. > > I can write: > >      c = a.exclude(id__in=b.values('id')) > > but this seems a little tedious, why can't I just

Re: QuerySet and subselect

2012-02-10 Thread Oleg Korsak
Yeah, you are right. Actually I'm trying to get most actual (latest by timestamp) records per group. 2012/2/10 Dennis Lee Bieber : > On Fri, 10 Feb 2012 02:39:33 +0200, ?? > wrote: > >>Is it possible to write ORM-way request to be same as this SQL: >>SELECT mo.* FROM (SELECT mi.* FROM my

Re: QuerySet and subselect

2012-02-09 Thread akaariai
On Feb 10, 2:39 am, Олег Корсак wrote: > Hello. > I have a model named MyModel and it has its own table named my_model (as > an example). > > Is it possible to write ORM-way request to be same as this SQL: > SELECT mo.* FROM (SELECT mi.* FROM my_model mi) AS mo WHERE mi.a=mo.a > AND mi.b=mo.b; > >

Re: QuerySet: "if obj in queryset" can be very slow

2011-11-03 Thread Tom Evans
On Wed, Nov 2, 2011 at 6:26 PM, Ian Clelland wrote: > Just looking at the source to QuerySet (finally), and it looks like the > __contains__ method actually does something different than this: It > evaluates the whole QuerySet in bulk at the database level, and starts > creating model instances ba

Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Thomas Guettler
Hi, I created a ticket: https://code.djangoproject.com/ticket/17156 {{{ The documentation should explain what happens in this code: if obj in queryset: If queryset is huge, the above code can be very slow. If you want to run the code in the database, you should use this: if queryset

Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Ian Clelland
On Wed, Nov 2, 2011 at 10:46 AM, Tom Evans wrote: > OK, take this example. I have a django model table with 70 million > rows in it. Doing any kind of query on this table is slow, and > typically the query is date restrained - which mysql will use as the > optimum key, meaning any further filteri

Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Ian Clelland
On Wed, Nov 2, 2011 at 10:46 AM, Tom Evans wrote: > On Wed, Nov 2, 2011 at 5:30 PM, Ian Clelland wrote: > > On Wed, Nov 2, 2011 at 8:25 AM, Thomas Guettler wrote: > >> > >> # This is my current solution > >> if get_special_objects().filter(pk=obj.pk).count(): > >># yes, it is special > >> >

Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Furbee
Thanks Tom, that's a great explanation! Furbeenator On Wed, Nov 2, 2011 at 10:46 AM, Tom Evans wrote: > On Wed, Nov 2, 2011 at 5:30 PM, Ian Clelland wrote: > > On Wed, Nov 2, 2011 at 8:25 AM, Thomas Guettler wrote: > >> > >> # This is my current solution > >> if get_special_objects().filter(p

Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Tom Evans
On Wed, Nov 2, 2011 at 5:30 PM, Ian Clelland wrote: > On Wed, Nov 2, 2011 at 8:25 AM, Thomas Guettler wrote: >> >> # This is my current solution >> if get_special_objects().filter(pk=obj.pk).count(): >>    # yes, it is special >> > > I can't speak to the "why" of this situation; it seems to me th

Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Ian Clelland
On Wed, Nov 2, 2011 at 8:25 AM, Thomas Guettler wrote: > # This is my current solution > if get_special_objects().filter(pk=obj.pk).count(): ># yes, it is special > > I can't speak to the "why" of this situation; it seems to me that this could always be converted into a more efficient databas

Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Tom Evans
On Wed, Nov 2, 2011 at 3:25 PM, Thomas Guettler wrote: > Here is a better example: > > def get_special_objects(): >    # Some are special. But the result can still be huge! >    return MyModel.objects.filter() > > obj=MyModel.objects.get() > > # is this object "special?" > if obj in get_sp

Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Thomas Guettler
Here is a better example: def get_special_objects(): # Some are special. But the result can still be huge! return MyModel.objects.filter() obj=MyModel.objects.get() # is this object "special?" if obj in get_special_objects(): # This is very slow if there are many rows in the res

Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Jirka Vejrazka
> queryset=MyModel.objects.all() > obj=MyModel.objects.get(id=319526) Thomas, if the second line works for you (i.e. does not raise MyModel.DoesNotExist exception), then obj is in queryset by definition. What are you trying to achieve? Jirka -- You received this message because you are

Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Flavia Missi
That's because your queryset is being evaluated when you compare, maybe if you explain your problem, we can give you a better solution than the use of `in`. Take a look at the docs about when querysets are evaluated: https://docs.djangoproject.com/en/dev/ref/models/querysets/#when-querysets-are-e

Re: queryset which returns the same result several times

2011-09-01 Thread Tom Evans
On Thu, Sep 1, 2011 at 1:39 PM, Julien Castets wrote: > hello www, > > This is the model: > > from django.contrib.auth.models import User > > class Task(models.Model): >  creator = models.ForeignKey(User) >  assigned_to = models.ManyToManyField(User) > > And there are four users: bob, roger, dan a

Re: QuerySet .annotate().extra() issues

2011-06-21 Thread Michał Sawicz
Dnia 2011-06-21, wto o godzinie 14:31 -0300, Andre Terra pisze: > I'm not sure this has anything to do with your issue, but it's easy to > miss when reading the docs. It's kind of related, but not directly. The similarity to the issue mentioned above is that the default ordering field is added to

Re: QuerySet .annotate().extra() issues

2011-06-21 Thread Andre Terra
BIG FAT DISCLAIMER I'm not sure this has anything to do with your issue, but it's easy to miss when reading the docs. https://docs.djangoproject.com/en/dev/topics/db/aggregation/#interaction-with-default-ordering-or-order-by If your model has an 'ordering' attribute defined in Meta, make sure yo

Re: QuerySet "disappearing"

2011-04-05 Thread Matthew Riedel
Nevermind- I *finally* figured it out.. It was this bit: "for contact in contacts[startIndex:startIndex+100]:" The contacts.count() in this case would steadily decrease as I changed the status of the objects to no longer fit the queryset criteria. So the startIndex value would get to the point whe

Re: Queryset cloning is very expensive

2011-03-22 Thread Malte Engelhardt
Sorry for the late response. Maybe it's sufficient to override the QuerySet clone method to just return self, not really clone it. 2011/2/14 myx > Thank you for the reply. But I meant a slightly different case: > > Item.objects.filter(...).order_by(...).values_list('id', flat=True)[: > 10] > >

Re: Queryset cloning is very expensive

2011-03-12 Thread Alexander Schepanovski
On 14 фев, 15:21, myx wrote: > Thank you for the reply. But I meant a slightly different case: > > Item.objects.filter(...).order_by(...).values_list('id', flat=True)[: > 10] > > As you can see, there are four cloning operations. Wouldn't be > chaining possible without cloning the queryset? The me

Re: Queryset cloning is very expensive

2011-02-24 Thread Karen Tracey
On Thu, Feb 24, 2011 at 11:20 AM, myx wrote: > I found a solution which is suitable for me. > As it turns out, all those methods just clone queryset, and then call > appropriate methods of Query object. > So, for example, to set ordering and to get a slice without cloning > queryset, I can do the

Re: Queryset cloning is very expensive

2011-02-24 Thread myx
I found a solution which is suitable for me. As it turns out, all those methods just clone queryset, and then call appropriate methods of Query object. So, for example, to set ordering and to get a slice without cloning queryset, I can do the following: qs.query.add_ordering('-created') qs.query.s

Re: Queryset cloning is very expensive

2011-02-14 Thread myx
Thank you for the reply. But I meant a slightly different case: Item.objects.filter(...).order_by(...).values_list('id', flat=True)[: 10] As you can see, there are four cloning operations. Wouldn't be chaining possible without cloning the queryset? The method could just return the original querys

Re: Queryset cloning is very expensive

2011-02-11 Thread kurvenschubser
Hi myx, cloning is useful for chaining of filters, e.g. User.objects.filter(name="Harry").exclude(lastname="Potter").filter(somethingelse="bla") But most of the time, I found I can construct querysets using a dictionary for collecting the query conditions: d = {name:"Harry", lastname:"Potter", s

Re: Queryset from 2 models with second model filtered.

2010-12-09 Thread pbzRPA
Typically I simply want to do a left join but have it as an object in django rather than a sql raw query. The queryset would look like. Select a.code as 'product_code', a.description as 'product_description', b.code as 'customer_code', b.code as 'customer_description', ifnull(

Re: 'QuerySet' object has no attribute 'get_payload'

2010-08-24 Thread bruno desthuilliers
On 23 août, 21:25, Cole743 wrote: > "AttributeError at _ > > 'QuerySet' object has no attribute 'get_payload' > > Request Method:         POST > Request URL:     > Exception Type:         AttributeError > Exception Value: > > 'QuerySet' object has no attribute 'get_payloa

Re: queryset field order

2010-08-06 Thread owidjaya
okay that's great but is there a way to get the list of fields from a model instance instead of from the Model class itself? My thought is that if I pass in the list of model instance into the template, the order should be still there. so why pass in another variable which contains the model fields

Re: queryset field order

2010-08-06 Thread Steve Holden
On 8/6/2010 1:34 PM, owidjaya wrote: > is there a way that i can get the a list of dictionaries as a result > with the dictionary having the same field order as the table? > What do you regard as the "field order" of the dictionary? If you are talking about the order Python iterates over the field

Re: queryset field order

2010-08-06 Thread Alec Shaner
You can't use a dictionary if you expect a certain order of key/value pairs. Given model A you could get a list of field objects in the same order (I think) as defined in the model class A._meta.fields At least with that information you could programatically produce a list of data in matching or

Re: queryset field order

2010-08-06 Thread owidjaya
is there a way that i can get the a list of dictionaries as a result with the dictionary having the same field order as the table? On Aug 6, 10:18 am, Daniel Roseman wrote: > On Aug 6, 6:08 pm, owidjaya wrote: > > > I checked it and the field order still not the same. > > Just to clarify. I want

Re: queryset field order

2010-08-06 Thread Daniel Roseman
On Aug 6, 6:08 pm, owidjaya wrote: > I checked it and the field order still not the same. > Just to clarify. I want the to do this A.objects.all().values() > and still get the each list in the result to have the same "field > order" as the database table defined. `values()` returns a set of dicti

Re: queryset field order

2010-08-06 Thread owidjaya
I checked it and the field order still not the same. Just to clarify. I want the to do this A.objects.all().values() and still get the each list in the result to have the same "field order" as the database table defined. On Aug 6, 9:57 am, kostia wrote: > use table = ModelName.objects.all().order

Re: queryset field order

2010-08-06 Thread kostia
use table = ModelName.objects.all().order_by("filter_name") It is ordered by id field apriori. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, s

Re: Queryset composition query

2010-07-07 Thread Tom Evans
On Wed, Jul 7, 2010 at 5:06 PM, Jeff Green wrote: > When I combine two query sets I use the chain command. You might want to try > it. > > Here is my code snippet > > from itertools import chain chain is useful when you want to concatenate two lists together. In this case though, I want distinct

Re: Queryset composition query

2010-07-07 Thread Jeff Green
When I combine two query sets I use the chain command. You might want to try it. Here is my code snippet from itertools import chain # Get current station configuration records stationlist = StationConfig.objects.filter(StationId=result.StationId, StartDate__lte= result.Ex

Re: QuerySet Behaviour Question (Django 1.1)

2010-06-29 Thread Matthias Kestenholz
Hi On Mon, Jun 28, 2010 at 4:37 PM, Jeff wrote: > Hi, > > I have a question concerning some queryset behaviour in Django 1.1. > > In this example, I have an article model that can contain 1 or more > authors who are users registered through Django's auth system. > > I get the following output whe

Re: QuerySet Behaviour Question (Django 1.1)

2010-06-28 Thread Jeff
Yes I am using PostgreSQL and I didn't add an order by clause. Adding the order by clause fixed the problem. Thank you very much Karen! Jeff On Jun 28, 10:46 am, Karen Tracey wrote: > On Mon, Jun 28, 2010 at 10:37 AM, Jeff wrote: > > Hi, > > > I have a question concerning some queryset behaviou

Re: QuerySet Behaviour Question (Django 1.1)

2010-06-28 Thread Karen Tracey
On Mon, Jun 28, 2010 at 10:37 AM, Jeff wrote: > Hi, > > I have a question concerning some queryset behaviour in Django 1.1. > > In this example, I have an article model that can contain 1 or more > authors who are users registered through Django's auth system. > > I get the following output when

Re: Queryset filtering based on user supplied callable??

2010-06-05 Thread Joakim Hove
Thank you very much :-) Joakim On Jun 5, 4:42 pm, johan de taeye wrote: > Typo... > The correct syntax is : >     obj_list = [ i for i in MyObject.objects.all() if my_filter(i) ] > > On Jun 5, 4:29 pm, johan de taeye wrote: > > > Possible through basic Python: > > >   obj_list = [ i for i in My

Re: Queryset filtering based on user supplied callable??

2010-06-05 Thread johan de taeye
Typo... The correct syntax is : obj_list = [ i for i in MyObject.objects.all() if my_filter(i) ] On Jun 5, 4:29 pm, johan de taeye wrote: > Possible through basic Python: > >   obj_list = [ i for i in MyObject.objects.all() where my_filter(i) ] > > Note that this filtering is happening on the

Re: Queryset filtering based on user supplied callable??

2010-06-05 Thread johan de taeye
Possible through basic Python: obj_list = [ i for i in MyObject.objects.all() where my_filter(i) ] Note that this filtering is happening on the Python side of things, whereas a queryset filter is executed in SQL on the database. The filtering on the database is normally much, much faster, so b

Re: Queryset causes error on form validation

2010-04-12 Thread Alastair Campbell
To answer my own question, it looks like you can't do this: class LinkForm(ModelForm): event = forms.ModelChoiceField(queryset=Event.objects.filter(start_date__lte=today).order_by('-start_date')[:15]) The limit (of 15) will be counted as another 'slice' when the form is validated. I got aroun

Re: queryset in clean method

2010-04-06 Thread Vinicius Mendes
You can pass the competition instance to the for in the initialization. In the form you change the form a little bit adding the init method to receive the competition parameter. Then you can save it in a form attribute and then use it in clean method. I made a simple gist to show you haw it could

Re: QuerySet returned based on a Python List?

2010-03-28 Thread rmschne
> > c1=Contact.objects.filter(hostid__tablename__in=list_of_names) > > The ORM is cool. Ah. "in". how could I have missed that in the doc. Too much staring and not enough reading, I guess. Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" g

  1   2   3   >