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

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

Re: advantages and disadvantages of Raw sql queries in django

On 30/06/2012 10:58 μμ, Javier Guerra Giraldez wrote:
>
> Even when using the ORM, any complex query is a good candidate to be
> encapsulated as part of the model. Ideally, the model should expose a
> high level view of your data objects, not simply an easy to use view
> of the database.
>
>

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?

Thanks

--
--------------------------------------------------------------
Nick Apostolakis
e-mail: nickapos@oncrete.gr
Web Site: http://nick.oncrete.gr
--------------------------------------------------------------


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

Optimistic Locking in Django?


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

Re: advantages and disadvantages of Raw sql queries in django

On Sat, Jun 30, 2012 at 1:33 AM, Mike Dewhirst <miked@dewhirst.com.au> wrote:
> I firmly believe in using the ORM for everything until i am forced to use
> handwritten SQL.

absolutely agree


> I could also argue against custom SQL because it contains business logic and
> i prefer to keep that all in one place, ie., in models in python code.

of course, when you have to use SQL, the best place to put it is in
the models file, either on the model itself or on a custom manager.
That way, if/when you modify the database representation, you don't
have to change other parts of the code.

Even when using the ORM, any complex query is a good candidate to be
encapsulated as part of the model. Ideally, the model should expose a
high level view of your data objects, not simply an easy to use view
of the database.

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

Re: i want to display a student profile from the database and am unable to do that.plz help

On Sat, 30 Jun 2012 11:54:35 -0700 (PDT), rick
<manishgirdhar88@gmail.com> declaimed the following in
gmane.comp.python.django.user:

>
> this is my views.py.
>
> def studentid(request):
> if request.method == 'POST':
> form = Student_loginForm(request.POST)
> if form.is_valid():
> cd = form.cleaned_data
> rollno = cd['rollno']
> p = form.save()
> rollno = request.POST.get('rollno')
> rollno=int(rollno)
> results = Add_record.objects.filter(Student_ID=rollno)
> return HttpResponseRedirect(reverse('record_system.views.search',
> args=(results)))

Note: if args is supposed to be a tuple, you need to include a
trailing ,

args = (results, )

Otherwise, each item (if there are more than one) in results is
being treated as a separate positional argument.

Other than that minor syntactic nit, one may need to see
"Add_record"...

Also, what is the expected behavior if .is_valid() comes back false?

As coded, regardless of the .is_valid() return, you appear to fetch
"rollno" from the request object (replacing any value saved from the
clean data branch).
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@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@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

i want to display a student profile from the database and am unable to do that.plz help


this is my views.py.

def studentid(request):
    if request.method == 'POST':
        form = Student_loginForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            rollno = cd['rollno']
            p = form.save()
        rollno = request.POST.get('rollno')
        rollno=int(rollno)
        results = Add_record.objects.filter(Student_ID=rollno)
        return HttpResponseRedirect(reverse('record_system.views.search', args=(results)))


def search(request,Student_ID ):
    p = get_object_or_404(Add_record, pk=Student_ID)
    p.save()
    return render_to_response('add_record/search.html', locals(), context_instance=RequestContext(request))


and am getting error on browser that

NoReverseMatch at /record_system/studentid/

Reverse for 'record_system.views.search' with arguments '(<Add_record: Add_record object>,)' and keyword arguments '{}' not found.


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