Re: Annotations as models fields

2019-06-07 Thread Devender Kumar
rs, >>>> >>>> Olivier >>>> >>>> On Thu, 6 Jun 2019 at 12:36, Chetan Ganji >>>> wrote: >>>> >>>>> I had a similar need in one of my clients project, I ended up using >>>>> @property and a python me

Re: Annotations as models fields

2019-06-06 Thread Chetan Ganji
y and a python method. >>>> >>>> AFAIK, AnnotationField is absent from django models. If you would like >>>> to write one, below is the material you need to refer. >>>> https://docs.djangoproject.com/en/2.2/howto/custom-model-fields/ >>>> &

Re: Annotations as models fields

2019-06-06 Thread Olivier Dalang
gt; Chetan Ganji >>> +91-900-483-4183 >>> ganji.che...@gmail.com >>> http://ryucoder.in >>> >>> >>> On Thu, Jun 6, 2019 at 3:36 PM Olivier Dalang >>> wrote: >>> >>>> Dear list, >>>> >>>> I w

Re: Annotations as models fields

2019-06-06 Thread Chetan Ganji
cs.djangoproject.com/en/2.2/howto/custom-model-fields/ >> >> >> Regards, >> Chetan Ganji >> +91-900-483-4183 >> ganji.che...@gmail.com >> http://ryucoder.in >> >> >> On Thu, Jun 6, 2019 at 3:36 PM Olivier Dalang >> wrote: >> >>&

Re: Annotations as models fields

2019-06-06 Thread Olivier Dalang
wto/custom-model-fields/ > > > Regards, > Chetan Ganji > +91-900-483-4183 > ganji.che...@gmail.com > http://ryucoder.in > > > On Thu, Jun 6, 2019 at 3:36 PM Olivier Dalang > wrote: > >> Dear list, >> >> I was wondering whether there's a package

Re: Annotations as models fields

2019-06-06 Thread Chetan Ganji
/ Regards, Chetan Ganji +91-900-483-4183 ganji.che...@gmail.com http://ryucoder.in On Thu, Jun 6, 2019 at 3:36 PM Olivier Dalang wrote: > Dear list, > > I was wondering whether there's a package or pattern to define annotations > as model fields, so that they could really be used

Annotations as models fields

2019-06-06 Thread Olivier Dalang
Dear list, I was wondering whether there's a package or pattern to define annotations as model fields, so that they could really be used as database-side computed fields. Currently, I do something like this (not tested, it's a simplified case): class SalesManager(models.Man

Re: Caltech Pedestrian Detection Annotations

2019-04-09 Thread Balaji Shetty
Please refer kaggle web site. It contains all data set with Classification algorithm and results also. You may get ideas. https://www.kaggle.com/c/state-farm-distracted-driver-detection/discussion/22018 Shetty Balaji On Mon, Apr 8, 2019 at 4:37 PM Aakash Baranwal wrote: > Hi Everybody, > > Th

Caltech Pedestrian Detection Annotations

2019-04-08 Thread Aakash Baranwal
Hi Everybody, This is not exactly a Django related question, but I need help. I am working on a project, and I have to use Caltech Pedestrian Detection data set. However, I am not able to get the output as desired as the files are

Re: Creating Objects from Annotations and Other Models

2019-03-21 Thread Dylan Young
Thanks Simon. That's exactly what I'm looking for. Wish they had piggy backed in the established F pattern though. It's quite verbose just to access the field on either model. r_id would just be a pk, usually from a fk on another model that I do need to fetch. Best, Casey Le jeu. 21 mars 2

Re: Creating Objects from Annotations and Other Models

2019-03-21 Thread Dylan Young
It's perfectly clear and precisely what an ORM is for. If you don't have an answer, just say so, though I suspect the answer is use SubQuery. It is not "useless" in general (obviously if you want to display/ deliver to an end user, you need to pluck from the database). It is useless in the case

Re: Creating Objects from Annotations and Other Models

2019-03-21 Thread Simon Charette
I'm not sure where r_id comes from but Model.save usually deals with any expression correctly so you could try using a subquery assignment and see if it works. e.g. entry = Entry.objects.create( start=Subquery( Recurrence.objects.filter(pk=r_id).values('start_time')[:1] ) ) Note

Re: Creating Objects from Annotations and Other Models

2019-03-21 Thread Chasan KIOUTSOUK MOUSTAFA
You can override the save method or simply use Django signals to modify fields of Model automatically. On Thu, Mar 21, 2019 at 8:21 PM Derek wrote: > Your use case is not very clear. > > If you are simply "running a few trivial calculations

Re: Creating Objects from Annotations and Other Models

2019-03-21 Thread Derek
Your use case is not very clear. If you are simply "running a few trivial calculations and storing the info" then you could use a function in the database to do this for you - pulling data directly from Table A and storing the result in Table B. Data in Table B could then be later edited using the

Re: Creating Objects from Annotations and Other Models

2019-03-21 Thread Dylan Young
For example using made-up syntax: Entry.objects.create(start=F(Recurrence.objects.filter(pk=r_id), 'start_time')) Note that we can't use `get` since the whole point is to avoid all the useless round-trips to the DB. Best, Casey On Thu, 21 Mar 2019 at 13:18, Dylan Young wrote: > It's not a re

Re: Creating Objects from Annotations and Other Models

2019-03-21 Thread Dylan Young
It's not a recalculation. It's instantiation. Instance data diverges from the factory data and needs to be independently editable. Best, Casey Le jeu. 21 mars 2019 2:52 a.m., Derek a écrit : > Permanently storing data that can be recalculated from existing data is a > practice specific to the

Re: Creating Objects from Annotations and Other Models

2019-03-20 Thread Derek
Permanently storing data that can be recalculated from existing data is a practice specific to the needs of particular applications. Have you perhaps considered making use of the "view" table functionality available in most databases? For example, in PostgreSQL you can create a materialized v

Creating Objects from Annotations and Other Models

2019-03-19 Thread Dylan Young
Hey all: I often find myself fetching data from models in the database only to run a few trivial calculations and store the info in a different model. Is there an established ORM pattern for directly creating objects in the DB based on the fields of other models? Sorry if this is obvious, but

Re: Multiple annotations in one query

2018-09-24 Thread David
Thanks Matthew will take a look. On Monday, 24 September 2018 15:40:44 UTC+1, Matthew Pava wrote: > > Hi David, > > Performing multiple annotations on a queryset is not the same as combining > multiple aggregations. > > Saying that, if you truly are getting wrong results

RE: Multiple annotations in one query

2018-09-24 Thread Matthew Pava
Hi David, Performing multiple annotations on a queryset is not the same as combining multiple aggregations. Saying that, if you truly are getting wrong results, you could try using the Window functions or the Subquery object. https://docs.djangoproject.com/en/2.1/ref/models/database-functions

Multiple annotations in one query

2018-09-24 Thread David
Hi I understand that performing multiple annotations on a queryset will produce incorrect results, I was wondering how anyone else gets around this? "Combining multiple aggregations with annotate() will yield the wrong results <https://code.djangoproject.com/ticket/10060> becaus

Re: Why does combining multiple annotations work in my case?

2017-08-13 Thread Simon Charette
Hello there, The issue tracked by #10060 only manifests itself when two different multi-valued relationships are used to perform aggregated annotations. In both of your provided examples you only perform SUM()s on a single multi-valued relationship (ward and then munipality__ward) while the

Why does combining multiple annotations work in my case?

2017-08-11 Thread Marcin Gałązka
The documentation advises against combining multiple annotations in one query: https://docs.djangoproject.com/en/1.11/topics/db/aggregation/#combining-multiple-aggregations due to the infamous bug #10060: https://code.djangoproject.com/ticket/10060 And indeed, having tried the counter-example

Re: How made worked models.Sum() together with models.Count in Django annotations?

2016-05-15 Thread Seti Volkylany
My new method for resolve problem not working to: (setattr(i, 'scope', i.get_scope()) for i in qs) Django not found field 'scope'. (error from traceback) -- Cannot resolve keyword 'scope' into field. Choices are: answers, author, author_id, count_answers, count_opi

Re: How made worked models.Sum() together with models.Count in Django annotations?

2016-05-15 Thread Simon Charette
Hi Seti, As documented this will yield the wrong results in most cases until subqueries are used instead of JOINs[1]. Cheers, Simon [1] https://docs.djangoproject.com/en/1.9/topics/db/aggregation/#combining-multiple-aggregations Le dimanche 15 mai 2016 12:42:44 UTC-4, Seti Volkylany a écrit :

How made worked models.Sum() together with models.Count in Django annotations?

2016-05-15 Thread Seti Volkylany
For working models.Count() I am using distinct=True. It is right worked if not models.Sum(). next code right worked. def get_queryset(self, request): qs = super(AnswerAdmin, self).get_queryset(request) qs = qs.annotate( count_likes=models.Count('likes', distinct=Tr

Annotations with nested Sums

2015-07-10 Thread Marc Aymerich
Hi, I need to do some annotations that require a nested sumation, I have Bills that have Lines that in turn have Sublines: Bill -> Line -> SubLine In order to calculate the total bill price I need to add all sublines of every line, and then all lines of a bill. queryset.annotate( total

Re: Adding annotations to raw sql

2014-12-10 Thread john
ticle? Thanks. [1]: https://docs.djangoproject.com/en/dev/topics/db/sql/#adding-annotations -- 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 dj

Adding annotations to raw sql

2014-12-10 Thread Ruslan Batukaev
queryset will contain the values of `ct` and `one` for each article. However, while it prints the value of `one` correctly, it does not for `ct` and just returns `null`. Is there any way to get `ct` for each article? Thanks. [1]: https://docs.djangoproject.com/en/dev/topics/db/sql/

Re: Aggregating annotations

2013-07-23 Thread Debanshu Kundu
aggregate(Max(books_per_rating)) > > I get a *DatabaseError*. > > According to this > https://docs.djangoproject.com/en/1.5/topics/db/aggregation/#aggregating-annotations, > > Django supports aggregating annotations. But in the example given in the > link itself, they annotate ove

Re: Aggregating annotations

2013-07-23 Thread Debanshu Kundu
'id')).aggregate(Max(books_per_rating)) >> >> I get a *DatabaseError*. >> >> According to this >> https://docs.djangoproject.com/en/1.5/topics/db/aggregation/#aggregating-annotations, >> >> Django supports aggregating annotations. But in the examp

Re: Aggregating annotations

2013-07-19 Thread Debanshu Kundu
bjects.values('rating').annotate(books_per_rating=Count('id')).aggregate(Max(books_per_rating)) > > I get a *DatabaseError*. > > According to this > https://docs.djangoproject.com/en/1.5/topics/db/aggregation/#aggregating-annotations, > > Django supports agg

Re: Aggregating annotations

2013-07-19 Thread Debanshu Kundu
> > and I run the query: > > Book.objects.values('rating').annotate(books_per_rating=Count('id')).aggregate(Max(books_per_rating)) > > I get a *DatabaseError*. > > According to this > https://docs.djangoproject.com/en/1.5/topics/db/aggregation/#aggrega

Aggregating annotations

2013-07-19 Thread Debanshu Kundu
: Book.objects.values('rating').annotate(books_per_rating=Count('id')).aggregate(Max(books_per_rating)) I get a *DatabaseError*. According to this https://docs.djangoproject.com/en/1.5/topics/db/aggregation/#aggregating-annotations, Django supports aggregating annotations. But in

Re: Support for multiple django annotations?

2012-01-11 Thread girish shabadimath
7;country_abbr')).order_by('- > country_cnt') > > and this takes care of inner loop. > > If I try to do multiple annotations, django raise error.: > > > z=Firewall.objects.annotate(country_cnt=Count('country_abbr')).annotate(cnt=Count('country_c

Support for multiple django annotations?

2012-01-11 Thread pradyumna
jects.values('log_datetime','country_abbr').annotate(date_cnt=Count('log_datetime'),country_cnt=Count('country_abbr')).order_by('- country_cnt') and this takes care of inner loop. If I try to do multiple annotations, django raise error.: z=Fir

Re: Query Builder forgets annotations

2011-02-27 Thread Pascal Germroth
Hi, >> It seems the query builder forgets annotations when dealing with joins: > Not in my experience. Yeah I experimented further and it wasn't actually a problem with /that/ part of the query (well, it changed when I added/removed the order_by, but the actual cause was some int

Re: Query Builder forgets annotations

2011-02-27 Thread Karen Tracey
On Sat, Feb 26, 2011 at 12:39 PM, Pascal Germroth wrote: > It seems the query builder forgets annotations when dealing with joins: > > Not in my experience. > > I have this model with Postgresql, Django 1.3 alpha 1 (SVN rev. 15659): > I don't quite understand that Dja

Query Builder forgets annotations

2011-02-26 Thread Pascal Germroth
Hi, It seems the query builder forgets annotations when dealing with joins: I have this model with Postgresql, Django 1.3 alpha 1 (SVN rev. 15659): class Corporation(Model): uuid = UuidField(primary_key=True) class Branch(Model): uuid = UuidField(primary_key=True) corporation

Re: Comparing two annotations

2011-02-23 Thread Patrick
now that makes sense.. thank you daniel! i better should have rtfm :) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users

Re: Comparing two annotations

2011-02-23 Thread Daniel Roseman
On Wednesday, February 23, 2011 7:28:06 PM UTC+1, Patrick wrote: > > Hi, > > i am trying to compare two count-annotations with a simple "greater- > than" filter like this: > ResultSequence.objects.annotate(num_result=Count('resultset'),num_part

Comparing two annotations

2011-02-23 Thread Patrick
Hi, i am trying to compare two count-annotations with a simple "greater- than" filter like this: ResultSequence.objects.annotate(num_result=Count('resultset'),num_part=Count('seminar__participant')).filter(num_result__gt=num_part) i also tried doing it like this: R

Re: Filtering only on Annotations

2010-01-20 Thread pjrhar...@gmail.com
On Jan 20, 1:36 am, Russell Keith-Magee wrote: > On Wed, Jan 20, 2010 at 3:42 AM, Collin Anderson > > wrote: > > Is there anyway to have the filter only apply to the annotation, so it > > would return all publishers, with some having a num_books=0? > > If I understand your request correctly, I

Re: Filtering only on Annotations

2010-01-19 Thread Russell Keith-Magee
On Wed, Jan 20, 2010 at 3:42 AM, Collin Anderson wrote: > Taking the example from: > http://docs.djangoproject.com/en/dev/topics/db/aggregation/#filter-and-exclude > > Publisher.objects.filter(book__rating__gt=3.0).annotate(num_books=Count > ('book')) > > Is there anyway to have the filter only ap

Filtering only on Annotations

2010-01-19 Thread Collin Anderson
Taking the example from: http://docs.djangoproject.com/en/dev/topics/db/aggregation/#filter-and-exclude Publisher.objects.filter(book__rating__gt=3.0).annotate(num_books=Count ('book')) Is there anyway to have the filter only apply to the annotation, so it would return all publishers, with some h

mixing annotations and extra()

2009-11-16 Thread HARRY POTTRER
If you had a model called Flight which has two fields, one called "total_time", and the other called "distance", you could create a "speed" field like so: Flight.objects.extra(select={'speed': 'distance / time'}) Each object will now have a 'speed' field. What if one of those fields is a result o

Re: Question about Aggregates and Annotations

2009-09-26 Thread Derek Willis
How about using filter() before annotate() Topic.objects.filter(subtopics__trashed_at__isnull=true, subtopics__complete_at__isnull=True).annotate(Count('subtopics')) That filters out the records you don't want and then performs the annotation on the remaining set. On Sep 26, 6:04 am, "oliver.an

Question about Aggregates and Annotations

2009-09-26 Thread oliver.andrich
Hi, is it possible to constrain a Count aggregate by adding some extra filters? I have a model which has a self referentiell foreign key. class Topic(models.Model): ... topic = models.ForeignKey('self', related_name='subtopics', null=True, blank=True) ... Now I wo

Re: annotations only in 1.1 ?

2009-07-31 Thread gentlestone
code > > like this: > > > ... KeyWord.objects.annotate(cnt = Count(categories)).filter(cnt = > > 0) ... > > > What is the similar code in old version 1.0 for resolve the same > > result. Should I use extra() method and go to the table level > > (SELECT ...) ? > > You don&

Re: annotations only in 1.1 ?

2009-07-31 Thread Daniel Roseman
> What is the similar code in old version 1.0 for resolve the same > result. Should I use extra() method and go to the table level > (SELECT ...) ? You don't need annotations for this at all. KeyWord.objects.filter(category__isnull=True) -- DR --~--~-~--~~---

annotations only in 1.1 ?

2009-07-31 Thread gentlestone
I want find all instances of model KeyWord, where ManyToMany field categories is empty. I think in versieon 1.1 is the appropriate code like this: ... KeyWord.objects.annotate(cnt = Count(categories)).filter(cnt = 0) ... What is the similar code in old version 1.0 for resolve the same result. Sh

Re: Annotations

2009-05-11 Thread Andy Lei
works great, thanks george! does anybody know if this is possible to do directly with the ORM? On May 7, 10:41 pm, George Song wrote: > On 5/7/2009 4:28 PM, Andy Lei wrote: > > > > > I have 3 models.  Something like this: > > > Writer: > >      content = ManyToMany(Content) > > Content > >    

Re: Annotations

2009-05-07 Thread George Song
On 5/7/2009 4:28 PM, Andy Lei wrote: > I have 3 models. Something like this: > > Writer: > content = ManyToMany(Content) > Content > tags = ManyToMany(Tag) > Tag > > Now suppose I have a Tag, call it "tag1". The idea of the query is > that I want the Writers that have the most pieces

Annotations

2009-05-07 Thread Andy Lei
I have 3 models. Something like this: Writer: content = ManyToMany(Content) Content tags = ManyToMany(Tag) Tag Now suppose I have a Tag, call it "tag1". The idea of the query is that I want the Writers that have the most pieces of Content tagged with tag1. Theoretically, it'd be som

Re: Struggling with annotations / aggregations

2009-02-19 Thread Stefan Tunsch
Thanks for the answer. I understand the implications of it. I'll keep an eye on the stated ticket. Keep up with the good work. Stefan Russell Keith-Magee escribió: On Thu, Feb 19, 2009 at 2:32 AM, Stefan Tunsch wrote: Hi there! I'm trying to see what's the best approach in

Re: Struggling with annotations / aggregations

2009-02-18 Thread Russell Keith-Magee
On Thu, Feb 19, 2009 at 2:32 AM, Stefan Tunsch wrote: > > Hi there! > > I'm trying to see what's the best approach in my scenario. > The problem is how to make a list display different sums and > calculations based on it's child objects. > > My scenario could be the following: > Two models: Proje

Struggling with annotations / aggregations

2009-02-18 Thread Stefan Tunsch
Hi there! I'm trying to see what's the best approach in my scenario. The problem is how to make a list display different sums and calculations based on it's child objects. My scenario could be the following: Two models: Project and Task One Project has many Task. Task has a boolean "open" fiel

Re: Custom annotations on error emails

2006-03-28 Thread Ned Batchelder
. --Ned [EMAIL PROTECTED] Adrian Holovaty wrote: On 3/27/06, Ned Batchelder <[EMAIL PROTECTED]> wrote: I'd like to add some custom annotations on the traceback emails that get sent when an exception occurs and DEBUG = False. For example, we are using our own user represe

Re: Custom annotations on error emails

2006-03-27 Thread Adrian Holovaty
On 3/27/06, Ned Batchelder <[EMAIL PROTECTED]> wrote: > I'd like to add some custom annotations on the traceback emails that get > sent when an exception occurs and DEBUG = False. For example, we are > using our own user representation, and would like to include the us

Custom annotations on error emails

2006-03-27 Thread Ned Batchelder
I'd like to add some custom annotations on the traceback emails that get sent when an exception occurs and DEBUG = False. For example, we are using our own user representation, and would like to include the user identity in the traceback. I can hack into the code that generates these e