Odagi | 1 Jul 02:18 2012
Picon

Query with GeoDjango

Hello all. I'm wondering how to resolve this problem with a GeoDjango.This are my models:


from django.db import models
from django.contrib.gis.db import models as geomodels
from django.contrib.gis.geos import Point
from django.contrib.gis.measure import D

class Place(geomodels.Model):
    name = models.CharField(max_length=50)
    point = geomodels.PointField(null=True)
    objects = geomodels.GeoManager()

    def __unicode__(self):
        return u"%s the place" % self.name


class Restaurant(models.Model):
    place = models.OneToOneField(Place, primary_key=True)
    serves_hot_dogs = models.BooleanField()
    serves_pizza = models.BooleanField()

    def __unicode__(self):
        return u"%s the restaurant" % self.place.name

    

How can I get all Restaurants that serve pizza in a radio of 45km of a given (geolocation) point?
I'm trying something like:

pnt = Point(-34.5875015259, -58.6725006104)
Restaurant.objects.all().filter(place__point__distance_lte=(pnt, D(km=45)))

But it's not working:
Join on field 'point' not permitted. Did you misspell 'distance_lte' for the lookup type?

Any ideas?
Thanks in advance.




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/eGmII8v1GMMJ.
To post to this group, send email to django-users <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Nikolas Stevenson-Molnar | 1 Jul 02:19 2012

Re: Query with GeoDjango

Try a double underscore between distance and lte.

_Nik

On 6/30/2012 5:18 PM, Odagi wrote:
> Hello all. I'm wondering how to resolve this problem with a
> GeoDjango.This are my models:
>
>
> from django.db import models
> from django.contrib.gis.db import models as geomodels
> from django.contrib.gis.geos import Point
> from django.contrib.gis.measure import D
>
> class Place(geomodels.Model):
>     name = models.CharField(max_length=50)
>     point = geomodels.PointField(null=True)
>     objects = geomodels.GeoManager()
>
>     def __unicode__(self):
>         return u"%s the place" % self.name
>
>
> class Restaurant(models.Model):
>     place = models.OneToOneField(Place, primary_key=True)
>     serves_hot_dogs = models.BooleanField()
>     serves_pizza = models.BooleanField()
>
>     def __unicode__(self):
>         return u"%s the restaurant" % self.place.name
>
>     
>
> How can I get all Restaurants that serve pizza in a radio of 45km of a
> given (geolocation) point?
> I'm trying something like:
>
> pnt = Point(-34.5875015259, -58.6725006104)
> Restaurant.objects.all().filter(place__point__distance_lte=(pnt,
> D(km=45)))
>
> But it's not working:
> Join on field 'point' not permitted. Did you misspell 'distance_lte' for the lookup type?
>
> Any ideas?
> Thanks in advance.
>
>
>
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/eGmII8v1GMMJ.
> To post to this group, send email to django-users <at> googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscribe <at> googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

--

-- 
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Ethan Jucovy | 1 Jul 02:24 2012
Picon

Re: Query with GeoDjango

On Sat, Jun 30, 2012 at 8:19 PM, Nikolas Stevenson-Molnar <nik.molnar <at> consbio.org> wrote:
Try a double underscore between distance and lte.


But, you need to use a `objects = GeoManager()` on the Restaurants model (as well as the Place model) per the docs: https://docs.djangoproject.com/en/dev/ref/contrib/gis/model-api/#django.contrib.gis.db.models.GeoManager

 -Ethan


_Nik

On 6/30/2012 5:18 PM, Odagi wrote:
> Hello all. I'm wondering how to resolve this problem with a
> GeoDjango.This are my models:
>
>
> from django.db import models
> from django.contrib.gis.db import models as geomodels
> from django.contrib.gis.geos import Point
> from django.contrib.gis.measure import D
>
> class Place(geomodels.Model):
>     name = models.CharField(max_length=50)
>     point = geomodels.PointField(null=True)
>     objects = geomodels.GeoManager()
>
>     def __unicode__(self):
>         return u"%s the place" % self.name
>
>
> class Restaurant(models.Model):
>     place = models.OneToOneField(Place, primary_key=True)
>     serves_hot_dogs = models.BooleanField()
>     serves_pizza = models.BooleanField()
>
>     def __unicode__(self):
>         return u"%s the restaurant" % self.place.name
>
>
>
> How can I get all Restaurants that serve pizza in a radio of 45km of a
> given (geolocation) point?
> I'm trying something like:
>
> pnt = Point(-34.5875015259, -58.6725006104)
> Restaurant.objects.all().filter(place__point__distance_lte=(pnt,
> D(km=45)))
>
> But it's not working:
> Join on field 'point' not permitted. Did you misspell 'distance_lte' for the lookup type?
>
> Any ideas?
> Thanks in advance.
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/eGmII8v1GMMJ.
> To post to this group, send email to django-users <at> googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscribe <at> googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.


--
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Odagi | 1 Jul 02:31 2012
Picon

Re: Query with GeoDjango

It's working! Thanks a lot. 

Is There a problem with mixing regular models fields with geomodels ones?



But, you need to use a `objects = GeoManager()` on the Restaurants model (as well as the Place model) per the docs: https://docs.djangoproject.com/en/dev/ref/contrib/gis/model-api/#django.contrib.gis.db.models.GeoManager

 -Ethan

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/4FdC-Q1mfuUJ.
To post to this group, send email to django-users <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Rafael Durán Castañeda | 1 Jul 02:36 2012
Picon

Re: Handling millions of rows + large bulk processing (now 700+ mil rows)

El 30/06/12 17:10, Cal Leeming [Simplicity Media Ltd] escribió:
> Hi all,
>
> As some of you know, I did a live webcast last year (July 2011) on our 
> LLG project, which explained how we overcome some of the problems 
> associated with large data processing.
>
> After reviewing the video, I found that the sound quality was very 
> poor, the slides weren't very well structured, and some of the 
> information is now out of date (at the time it was 40mil rows, now 
> we're dealing with 700+mil rows).
>
> Therefore, I'm considering doing another live webcast (except this 
> time it'll be recorded+posted the next day, the stream will be 
> available in 1080p, it'll be far better structured, and will only last 
> 50 minutes).
>
> The topics I'd like to cover are:
>
> * Bulk data processing where bulk_insert() is still not viable (we 
> went from 30 rows/sec to 8000 rows/sec on bulk data processing, whilst 
> still using the ORM - no raw sql here!!)
> * Applying faux child/parent relationship when standard ORM is too 
> expensive (allows for ORM approach without the cost)
> * Applying faux ORM read-only structure to legacy applications (allows 
> ORM usage on schemas that weren't properly designed, and cannot be 
> changed - for example, vendor software with no source code).
> * New Relic is beautiful, but expensive. Hear more about our plans to 
> make an open source version.
> * Appropriate use cases for IAAS vs colo with SSDs.
> * Percona is amazing, some of the tips/tricks we've learned over.
>
> If you'd like to see this happen, please leave a reply in the thread - 
> if enough people want this, then we'll do public vote for the 
> scheduled date.
>
> Cheers
>
> Cal
> -- 
> 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 <at> googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscribe <at> googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
That would be great!

--

-- 
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Setiaman Lee | 1 Jul 02:40 2012
Picon

Re:Handling millions of rows + large bulk processing (now 700+ mil rows)

Hi Cal,
Interesting topic. Count me in.

On Jun 30, 2012 11:10 PM, "Cal Leeming [Simplicity Media Ltd]" <cal.leeming <at> simplicitymedialtd.co.uk> wrote:
Hi all,

As some of you know, I did a live webcast last year (July 2011) on our LLG project, which explained how we overcome some of the problems associated with large data processing.

After reviewing the video, I found that the sound quality was very poor, the slides weren't very well structured, and some of the information is now out of date (at the time it was 40mil rows, now we're dealing with 700+mil rows).

Therefore, I'm considering doing another live webcast (except this time it'll be recorded+posted the next day, the stream will be available in 1080p, it'll be far better structured, and will only last 50 minutes).

The topics I'd like to cover are:

* Bulk data processing where bulk_insert() is still not viable (we went from 30 rows/sec to 8000 rows/sec on bulk data processing, whilst still using the ORM - no raw sql here!!)
* Applying faux child/parent relationship when standard ORM is too expensive (allows for ORM approach without the cost)
* Applying faux ORM read-only structure to legacy applications (allows ORM usage on schemas that weren't properly designed, and cannot be changed - for example, vendor software with no source code).
* New Relic is beautiful, but expensive. Hear more about our plans to make an open source version.
* Appropriate use cases for IAAS vs colo with SSDs.
* Percona is amazing, some of the tips/tricks we've learned over.

If you'd like to see this happen, please leave a reply in the thread - if enough people want this, then we'll do public vote for the scheduled date.

Cheers

Cal

--
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Ethan Jucovy | 1 Jul 02:42 2012
Picon

Re: Query with GeoDjango

On Sat, Jun 30, 2012 at 8:31 PM, Odagi <fcmiranda <at> gmail.com> wrote:

It's working! Thanks a lot. 
Is There a problem with mixing regular models fields with geomodels ones?

No, there's no problem, as long as you remember to use a GeoManager on every model that ever does geospatial queries (whether or not it has any geospatial fields itself)

-Ethan

--
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Steven Cummings | 1 Jul 04:34 2012
Picon

Re: Optimistic Locking in Django?

I started looking into it a while back: https://code.djangoproject.com/ticket/16549


The work broke down into ensuring that the updated/deleted/matched counts were returned from the internal ORM objects. Then there was a fair amount of discussion of what the public API of the ORM could provide on top of that. It's kind of died out a bit, I'd like to get back to it and rekindle the discussion when I can find some time.
--
Steven


On Sat, Jun 30, 2012 at 5:24 PM, ydjango <neerashish <at> gmail.com> wrote:

I did google search on "optimistic locking". Most discussion are very old.

Has Django added any features to support it or what are folks generally doing?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/oaykVwXK58wJ.
To post to this group, send email to django-users <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Steven Cummings | 1 Jul 05:18 2012
Picon

Re: Optimistic Locking in Django?

If you read over the linked discussion it's quite possible, just an issue of how disruptive it would be to the ORM APIs.

On Saturday, June 30, 2012, Dennis Lee Bieber wrote:

On Sat, 30 Jun 2012 15:24:59 -0700 (PDT), ydjango <neerashish <at> gmail.com>
declaimed the following in gmane.comp.python.django.user:

>
> I did google search on "optimistic locking". Most discussion are very old.
>
> Has Django added any features to support it or what are folks generally
> doing?

       Since the locking relies upon the database engine itself, Django
probably can't do anything for it -- it would require the front-end to
know about features of the engine, and that could be a significant
impact if one changes the engine later (not to mention the overhead of
looking up some feature list for each engine so it can execute different
code based on what type of locking is available).
--
       Wulfraed                 Dennis Lee Bieber         AF6VN
       wlfraed <at> ix.netcom.com    HTTP://wlfraed.home.netcom.com/

--
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
--
Steven

--
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Javier Guerra Giraldez | 1 Jul 05:25 2012

Re: advantages and disadvantages of Raw sql queries in django

On Sat, Jun 30, 2012 at 5:26 PM, Nick Apostolakis <nickapos <at> oncrete.gr> wrote:
> Interesting idea, I haven't used that yet, could you give an example of
> that?
> Would you use a method calling the ORM that would include something like
> self.objects.select_related().bla bla?

for example: when modelling the requested/accepted/rejected of a
'friendship' relation between 'person' records, you have to design the
exact DB representation, but later on you might want to modify that
representation.  Ideally, such changes shouldn't impact _all_ your
code.

specifically: my Person model has a ManyToManyField to 'self' called
'friends', where the intermediate table ('Friendship' model) has a
'state' field.  These are implementation details, so i added some
methods to get the list of friends, list of unanswered requests sent,
received, and rejections sent and received:

  def get_friends(self):
    return self.friends.filter(as_B__state=Friendship.ACCEPTED)

  def get_sent_requests_unanswered(self):
    return self.friends.filter(as_B__state=Friendship.REQUESTED)

  def get_rcvd_requests_unanswered(self):
    return self.receivedRequests.filter(as_A__state=Friendship.REQUESTED)

  def get_sent_requests_rejected(self):
    return self.friends.filter(as_B__state=Friendship.REJECTED)

  def get_rcvd_requests_rejected(self):
    return self.receivedRequests.filter(as_A__state=Friendship.REJECTED)

as you can see, these queries are readable enough to be used anywhere;
but if later on i want to replace the single 'friends' link field with
several independent relationships, i don't have to search through all
my code, just the models.py

similarly, there are methods to send a request and to accept or reject
it.  Again, the code is simple enough that it could be used directly;
but encapsulating it with the Person model makes it easy to maintain
consistency:

for example, the friendship request method:

  def send_friend_request(self, target):
    try:
      f = Friendship.objects.get(personA=self, personB=target)
      return f in (Friendship.REQUESTED, Friendship.ACCEPTED)
    except Friendship.DoesNotExist:
      Friendship.objects.create(
            personA=self, personB=target,
            state=Friendship.REQUESTED)
      return True

doesn't allow a second request if one is already pending or rejected.
if later on this policy is changed (maybe a rejector could change
mind, or an old request could expire, etc), i know where to do the
changes.

also, this lets the views be _really_ thin. since the interface
presented by the models is really close to the conceptual data objects
presented to the users.  After that, adding for example a REST layer
isn't hard; since it only has to use the same high-level methods as
the HTML views.  again, consistency is guaranteed by the common
underlying implementation.

in short: an application model is _not_ an OOP view of the database;
it's the implementation of the conceptual data objects as handled by
the application.

-- 
Javier

--

-- 
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


Gmane