Re: How do I use Django to execute PostGIS query to get polygons within four points?

2018-01-07 Thread Jani Tiainen
Hi.

__within is probably correct lookup.

You can find all lookups at:
https://docs.djangoproject.com/en/2.0/ref/contrib/gis/geoquerysets/

8.1.2018 2.36 "Tom Tanner"  kirjoitti:

> I get this error when trying Jani's example: "FieldError: Unsupported
> lookup 'inside' for MultiPolygonField or join on the field not permitted."
>
> On Sunday, January 7, 2018 at 7:33:51 PM UTC-5, Tom Tanner wrote:
>>
>> Thanks for replying, Jani. I should mention My `geom` field is a
>> MultiPolygon, so I can't use `from_bbox` it seems...
>>
>> On Sunday, January 7, 2018 at 3:45:55 AM UTC-5, Jani Tiainen wrote:
>>>
>>> Something like following should work. Didn't checked if that actually
>>> works.
>>>
>>> Mymodel.objects.filter(geom__inside=Polygon.from_bbox((x1,y1,x2,y2),
>>> srid=1234))
>>>
>>> On Sun, Jan 7, 2018 at 10:41 AM, Jani Tiainen  wrote:
>>>
 Hi,

 I didn't realize what you were asking for. :D

 Django has bunch of spatial queries, so you're looking some of those
 __inside, __within lookups. Coordinate transformations do happen
 automatically so you just need to provide srid for you "envelope".

 On Sun, Jan 7, 2018 at 1:48 AM, Tom Tanner 
 wrote:

> Here's a sample PostGIS query I use to get geometries within four
> points:
>
> SELECT *
> FROM myTable
> WHERE ST_MakeEnvelope(-97.82381347656252, 30.250444940663296, -
> 97.65901855468752, 30.29595835209862, 4326) && ST_Transform(myTable.
> geom,4326);
>
>
> With this query, I can get all rows within those four points. How do I
> execute this query or similar queries in Django or GeoDjango?
>
> --
> 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-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/aac95827-0c79
> -4aef-84cf-646ca82cfffa%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



 --
 Jani Tiainen

 - Well planned is half done, and a half done has been sufficient
 before...

>>>
>>>
>>>
>>> --
>>> Jani Tiainen
>>>
>>> - Well planned is half done, and a half done has been sufficient
>>> before...
>>>
>> --
> 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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/67a80f04-1ea1-45b7-bfce-76863ae0f13e%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91ocXLf4iUMNMOLtm2HWV53aJmqxbcQyWRYcYdNbhbAJPQA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-07 Thread Matemática A3K
On Sun, Jan 7, 2018 at 7:44 PM, Ronnie Raney  wrote:

>
> def random_post(request):
> posts_ids = Post.objects.all().values_list("id", flat=True)
> random_obj = Post.objects.get(id=random.choice(posts_ids))
> context = {'random_obj': random_obj,}
> return render(request, 'blog/random_post.html', context)
>
> Is “”id”” actually post_id in my case?
>

*Model*: I created a model called Post with all the typical fields,
> including a unique autofield. My intention was to randomly select a pk
> using this autofield. I thought about using a property to do some of the
> querying/logic for my random functionality, but I'm not sure if this is the
> best way to do it.
>

It should be your pk, if you did it the "standard way" should be "id", the
idea is to sample one from all your existing pks - whatever it is.

This is a view right? not part of the model?
>

Yup


>
> --
> 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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/b1080eca-fd1c-407f-bd26-46f3740a603f%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BFDnh%2Bt-ScM5TMTSmv0%2By1G6ho5t1MLhfZsdFAjckQZfg-ogg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I use Django to execute PostGIS query to get polygons within four points?

2018-01-07 Thread Tom Tanner
I get this error when trying Jani's example: "FieldError: Unsupported 
lookup 'inside' for MultiPolygonField or join on the field not permitted."

On Sunday, January 7, 2018 at 7:33:51 PM UTC-5, Tom Tanner wrote:
>
> Thanks for replying, Jani. I should mention My `geom` field is a 
> MultiPolygon, so I can't use `from_bbox` it seems...
>
> On Sunday, January 7, 2018 at 3:45:55 AM UTC-5, Jani Tiainen wrote:
>>
>> Something like following should work. Didn't checked if that actually 
>> works.
>>
>> Mymodel.objects.filter(geom__inside=Polygon.from_bbox((x1,y1,x2,y2), 
>> srid=1234))   
>>
>> On Sun, Jan 7, 2018 at 10:41 AM, Jani Tiainen  wrote:
>>
>>> Hi,
>>>
>>> I didn't realize what you were asking for. :D
>>>
>>> Django has bunch of spatial queries, so you're looking some of those 
>>> __inside, __within lookups. Coordinate transformations do happen 
>>> automatically so you just need to provide srid for you "envelope".
>>>
>>> On Sun, Jan 7, 2018 at 1:48 AM, Tom Tanner  
>>> wrote:
>>>
 Here's a sample PostGIS query I use to get geometries within four 
 points:

 SELECT *
 FROM myTable
 WHERE ST_MakeEnvelope(-97.82381347656252, 30.250444940663296, -
 97.65901855468752, 30.29595835209862, 4326) && ST_Transform(myTable.
 geom,4326);


 With this query, I can get all rows within those four points. How do I 
 execute this query or similar queries in Django or GeoDjango?

 -- 
 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-users...@googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.
 Visit this group at https://groups.google.com/group/django-users.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com
  
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>
>>>
>>> -- 
>>> Jani Tiainen
>>>
>>> - Well planned is half done, and a half done has been sufficient 
>>> before...
>>>
>>
>>
>>
>> -- 
>> Jani Tiainen
>>
>> - Well planned is half done, and a half done has been sufficient before...
>>
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/67a80f04-1ea1-45b7-bfce-76863ae0f13e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I use Django to execute PostGIS query to get polygons within four points?

2018-01-07 Thread Tom Tanner
Thanks for replying, Jani. I should mention My `geom` field is a 
MultiPolygon, so I can't use `from_bbox` it seems...

On Sunday, January 7, 2018 at 3:45:55 AM UTC-5, Jani Tiainen wrote:
>
> Something like following should work. Didn't checked if that actually 
> works.
>
> Mymodel.objects.filter(geom__inside=Polygon.from_bbox((x1,y1,x2,y2), 
> srid=1234))   
>
> On Sun, Jan 7, 2018 at 10:41 AM, Jani Tiainen  > wrote:
>
>> Hi,
>>
>> I didn't realize what you were asking for. :D
>>
>> Django has bunch of spatial queries, so you're looking some of those 
>> __inside, __within lookups. Coordinate transformations do happen 
>> automatically so you just need to provide srid for you "envelope".
>>
>> On Sun, Jan 7, 2018 at 1:48 AM, Tom Tanner > > wrote:
>>
>>> Here's a sample PostGIS query I use to get geometries within four points:
>>>
>>> SELECT *
>>> FROM myTable
>>> WHERE ST_MakeEnvelope(-97.82381347656252, 30.250444940663296, -
>>> 97.65901855468752, 30.29595835209862, 4326) && ST_Transform(myTable.geom
>>> ,4326);
>>>
>>>
>>> With this query, I can get all rows within those four points. How do I 
>>> execute this query or similar queries in Django or GeoDjango?
>>>
>>> -- 
>>> 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-users...@googlegroups.com .
>>> To post to this group, send email to django...@googlegroups.com 
>>> .
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com
>>>  
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> Jani Tiainen
>>
>> - Well planned is half done, and a half done has been sufficient before...
>>
>
>
>
> -- 
> Jani Tiainen
>
> - Well planned is half done, and a half done has been sufficient before...
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ab0234b5-109b-4833-b223-c12870cb654d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-07 Thread Ronnie Raney

def random_post(request):
posts_ids = Post.objects.all().values_list("id", flat=True)
random_obj = Post.objects.get(id=random.choice(posts_ids))
context = {'random_obj': random_obj,}
return render(request, 'blog/random_post.html', context)

Is “”id”” actually post_id in my case?
This is a view right? not part of the model?

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b1080eca-fd1c-407f-bd26-46f3740a603f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: does the tutorial django 2.0 works?

2018-01-07 Thread Egor Smolyakov
Hello, Danilo.

Can you post your code and getting issues (stacktrace) to pastebin or so on?


On 7 January 2018 at 23:05, danilo talamonti 
wrote:

> hellò people,
> i'm learning django 2.0 from the tutorial
> and until part 3 everything went ok
>
> In part 4 i have a problem in detail.html with the form.
> As a conseguence, in the function vote at views.py,
> i always get the KeyError.
>
> has anybody tried it, to confirm the tutorial works?
>
> And if it works, how may i debug ?
>
> Thanks, Danilo
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/f5766479-6cb2-4b47-a08b-9b0f8cdc1a9c%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Kind Regards, Egor Smolyakov.

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACL14xqwmEEE7mn7w3NdmD%3D-P0-aSuFmfG9tt_PNGOGCkCYEoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


does the tutorial django 2.0 works?

2018-01-07 Thread danilo talamonti
hellò people,
i'm learning django 2.0 from the tutorial
and until part 3 everything went ok

In part 4 i have a problem in detail.html with the form.
As a conseguence, in the function vote at views.py,
i always get the KeyError.

has anybody tried it, to confirm the tutorial works?

And if it works, how may i debug ?

Thanks, Danilo

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f5766479-6cb2-4b47-a08b-9b0f8cdc1a9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Disallowed User Agents | Force To upgrade

2018-01-07 Thread Jason
Agreed.  Blocking users from accessing the site seems counterproductive.  
Just do a feature detection and raise an alert warning if css-grid.  
Modernizr will let you do this easily

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5725db97-774a-473d-9714-bcc89b6a5051%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using Django create() on a time.field

2018-01-07 Thread Daniel Roseman
On Sunday, 7 January 2018 21:03:05 UTC, Malik Rumi wrote:
>
> --
>
> As a string that evaluates to the past ***
>
> (lifeandtimes) malikarumi@Tetuoan2:~/Projects/lifeandtimes/chronicle$ 
> python django_textract_9.py
>
> Traceback (most recent call last):
>
>  File "django_textract_9.py", line 17, in 
>
>clock='04:04:04'))
>
> io.UnsupportedOperation: write
>
> ***Back to the same old error. How can it not support writing to a single 
> field when it writes to all the others? ***
> Django 1.11.5 Postgres 9.4, Psycopg2, Python 3.6.3
>


The error is nothing to do with the time field. The model create command is 
*succeeding*, as you could tell by looking at the database.

However you have wrapped this creation in a TextIOBase.write function, 
which is failing. This is because a TextIOBase is an abstract class which 
does not actually have any concept of anything to write to. What, exactly, 
are you trying to do here?
-- 
DR.

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1a12423a-d7bb-425c-9252-9af535f9de46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Using Django create() on a time.field

2018-01-07 Thread Malik Rumi


I am trying to process some text files and feed the result directly into a 
django model using create(). As so often seems to happen with me, this 
turns out to not be as simple as I thought it would be. Specifically, I 
can’t seem to get any data into ‘clock’, the time field in my model. When I 
tried making the input data a string, it rejected it. When I tried making 
it a function, it told me it was expecting a string, and no version of int, 
float, or decimal got past Pylint. What is the right way to get this done, 
or do I need to do direct db inserts instead? Here is my code. Thanks.

As a string ***

from io import TextIOBase

from os import environ

import textract

import django

environ['DJANGO_SETTINGS_MODULE'] = 'chronicle.settings'

django.setup()

from ktab.models import Entry


text = textract.process('/home/malikarumi/010417_odt_tests/2018-01-01 
psycopg2-error-at-or-near.odt', encoding='utf_8')

b = TextIOBase(text)

b.write(Entry.objects.create(

   title='2018-01-01 psycopg2-error-at-or-near', content=b, 
chron_date='2018-01-05',

   clock='23:59:59'))

b.save()

(lifeandtimes) malikarumi@Tetuoan2:~/Projects/lifeandtimes/chronicle$ 
python django_textract_7.py

Traceback (most recent call last):

 File "django_textract_7.py", line 17, in 

   clock='23:59:59'))

io.UnsupportedOperation: write

--

As a function ***

from time import time, localtime

from io import TextIOBase

from os import environ

import textract

import django

environ['DJANGO_SETTINGS_MODULE'] = 'chronicle.settings'

django.setup()

from ktab.models import Entry


text = textract.process('/home/malikarumi/010417_odt_tests/2018-01-01 
psycopg2-error-at-or-near.odt', encoding='utf_8')

b = TextIOBase(text)

b.write(Entry.objects.create(

   title='2018-01-01 psycopg2-error-at-or-near', content=str(b), 
chron_date='2018-01-05',

   clock=localtime(time(

b.save()

(lifeandtimes) malikarumi@Tetuoan2:~/Projects/lifeandtimes/chronicle$ 
python django_textract_10.py

Traceback (most recent call last):

 File "django_textract_10.py", line 18, in 

   clock=localtime(time(

<...snip…>

File 
"/home/malikarumi/Projects/lifeandtimes/lib/python3.6/site-packages/django/utils/dateparse.py",
 
line 76, in parse_time

   match = time_re.match(value)

TypeError: expected string or bytes-like object

(lifeandtimes) malikarumi@Tetuoan2:~/Projects/lifeandtimes/chronicle$ 

--

As a string that evaluates to the past ***

(lifeandtimes) malikarumi@Tetuoan2:~/Projects/lifeandtimes/chronicle$ 
python django_textract_9.py

Traceback (most recent call last):

 File "django_textract_9.py", line 17, in 

   clock='04:04:04'))

io.UnsupportedOperation: write

***Back to the same old error. How can it not support writing to a single 
field when it writes to all the others? ***
Django 1.11.5 Postgres 9.4, Psycopg2, Python 3.6.3

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/94714f16-9f9d-42e6-add4-5798a9389f09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django local development server hangs after calling pandas df.plot a second time

2018-01-07 Thread Matemática A3K
Hi! This may be better suited for the django-pandas community, as it
involves its internals. It is also very hard to debug without errors or
stack traces.

HTH

On Sun, Jan 7, 2018 at 3:51 PM, asilver  wrote:

> I'm trying to build a small website, using django, that stores network
> performance data. The user will be able to use filters to retrieve the
> exact data he/she wants and then have the option to graph that data. I'm
> using django-pandas to convert filtered queryset to a dataframe and from
> there to create a plot. Everything works fine the first time the plot
> function is called. When the plot function is called a second time, the
> python web server just hangs (started from python2.7.exe manage.py
> runserver).
>
> Here is the django view function:
>
>
> def FilteredPerformanceChartsView(request):
> f = PerfvRtrOnlyFilter(request.GET, queryset=PerfvRtrOnly.objects.all())
> df = read_frame(f.qs, fieldnames=['runDate', 'deviceName', 'aggrPPS', 
> 'jdmVersion'])
>
> #
> # Let's pass the Pandas DataFrame off to a seperate function for
> # further processing and to generate a chart.
> # This should return an image (png or jpeg)
> #
> chart = pandas_generate_chart(f.qs)
>
> return render(request,
>   'performance_charts.html',
>   context={'filter': f,
> 'chart': chart,
> 'dataFrame': df,
> },
>
>   )
>
>
>
> The function *pandas_generate_chart* is where the problem is. After
> performing a lot of troubleshooting, what appears to trigger the hang is
> calling df.plot a second time. In other words, when the user hits the
> button to generate a different chart. Until that second request to generate
> a chart is submitted, the website still works perfect. You will also notice
> that plt.close() is commented out below. If I uncomment that out, the
> webserver will hang the first time this function is called. (Note, it will
> display the chart). I've been looking into the pyplot interactive vs
> non-interactive modes to see if that was the cause of the problem. From the
> troubleshooting I've done, it is running in non-interactive mode.
>
>
> def pandas_generate_chart(filtered_queryset):
>
> df = read_frame(filtered_queryset, fieldnames=['jdmVersion', 'hardware', 
> 'deviceName', 'aggrPPS'])
> df = df.set_index('jdmVersion')
>
> # Plot
> myplot = df.plot(kind='barh', figsize=(12,7), grid=True)
> myplot.set_ylabel('JDM Version')
>
> format="png"
> sio_file = StringIO()
> plt.savefig(sio_file, format=format)
> image = base64.b64encode(sio_file.getvalue())#   plt.close()
> sio_file.close()
> return image
>
>
>
> Thank you for your 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
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/ed7e5391-3172-4914-bbd4-568e0f76d4f3%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BFDnh%2B%2Bj760gOXHpKf-MB2r58kchtEj-89ODv2SAjNtLz0rqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-07 Thread Matemática A3K
def random_post(request):
posts_ids = Post.objects.all().values_list("id", flat=True)
random_obj = Post.objects.get(id=random.choice(posts_ids))
context = {'random_obj': random_obj,}
return render(request, 'blog/random_post.html', context)

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BFDnhLYyEhFuvnLvvzE0aTZSGsPSdF_eoJkVvn%2BzTE_LKfe%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django local development server hangs after calling pandas df.plot a second time

2018-01-07 Thread asilver


I'm trying to build a small website, using django, that stores network 
performance data. The user will be able to use filters to retrieve the 
exact data he/she wants and then have the option to graph that data. I'm 
using django-pandas to convert filtered queryset to a dataframe and from 
there to create a plot. Everything works fine the first time the plot 
function is called. When the plot function is called a second time, the 
python web server just hangs (started from python2.7.exe manage.py 
runserver).

Here is the django view function:


def FilteredPerformanceChartsView(request):
f = PerfvRtrOnlyFilter(request.GET, queryset=PerfvRtrOnly.objects.all())
df = read_frame(f.qs, fieldnames=['runDate', 'deviceName', 'aggrPPS', 
'jdmVersion'])

#
# Let's pass the Pandas DataFrame off to a seperate function for 
# further processing and to generate a chart.
# This should return an image (png or jpeg)
#
chart = pandas_generate_chart(f.qs)

return render(request,
  'performance_charts.html',
  context={'filter': f,
'chart': chart,
'dataFrame': df,
},

  )



The function *pandas_generate_chart* is where the problem is. After 
performing a lot of troubleshooting, what appears to trigger the hang is 
calling df.plot a second time. In other words, when the user hits the 
button to generate a different chart. Until that second request to generate 
a chart is submitted, the website still works perfect. You will also notice 
that plt.close() is commented out below. If I uncomment that out, the 
webserver will hang the first time this function is called. (Note, it will 
display the chart). I've been looking into the pyplot interactive vs 
non-interactive modes to see if that was the cause of the problem. From the 
troubleshooting I've done, it is running in non-interactive mode.


def pandas_generate_chart(filtered_queryset):

df = read_frame(filtered_queryset, fieldnames=['jdmVersion', 'hardware', 
'deviceName', 'aggrPPS'])
df = df.set_index('jdmVersion')

# Plot
myplot = df.plot(kind='barh', figsize=(12,7), grid=True)
myplot.set_ylabel('JDM Version')

format="png"
sio_file = StringIO()
plt.savefig(sio_file, format=format)
image = base64.b64encode(sio_file.getvalue())#   plt.close()
sio_file.close()
return image



Thank you for your 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 email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ed7e5391-3172-4914-bbd4-568e0f76d4f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-07 Thread Ronnie Raney
I am familiar with this from searching all over for a solution. The 
accepted solution is to create a manager.

from django.db.models.aggregates import Count
>
> from random import randint
>
>  

> class PaintingManager(models.Manager):
> def random(self):
> count = self.aggregate(count=Count('id'))['count']
> random_index = randint(0, count - 1)
> return self.all()[random_index]
>
>
If I use this as a template, it might look like this

class PostManager(models.Manager):
def random(self):
count = self.aggregate(count=Count('post_id'))['count']
random_index = randint(0, count - 1)
return self.all()[random_index]


I tried this earlier in the week and I got nothing but errors, so I was not 
executing it properly. I think it told me there was no "aggregates".

Anyway, moving forward... If this worked to draw a random post_id, then how 
do I get from this model to my DetailView? Remember, currently I am using a 
simple class-based view - DetailView - to show blog posts. Would I create 
another DetailView using PostManager as the model, then create another 
urlpattern?

I really appreciate all of the help with this. It would be nice to get a 
consensus on how to approach this.

To m712: Your solution might be simple, but I'm not seeing it because there 
is no code. Your suggestion was to create a random_post URL pointing a view 
that:
1. does shuffle logic
2. returns a redirect to the proper page, ex. /post/$id (is the $ outdated 
in Django 2.0?)

Then you say to make a valid URL using a DetailView. Are you saying to make 
a different urlpattern than the random_post URL, or are you talking about 
making the random_post URL valid?

Since I'm pretty new to Django, I was confused by your suggestion.


-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b6bc9e7a-1edb-4abc-ab8c-bbe280fd2f8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django URL pattern for an unusual address

2018-01-07 Thread Dylan Reinhold
Hit send while typing ;(

page = request.GET.get('page', 1)

Would give you the page number, and default to 1 if nothing was passed.

Dylan

On Sun, Jan 7, 2018 at 8:06 AM, Dylan Reinhold  wrote:

> You will just match that to /
> The ?page=1 you will deal with in the view you point / to.
>
> In you view you retrive the page value from the request object
> Somthing like
>
>
> page = request.GET.get('order', 'name')
>
> Dylan
>
> On Sun, Jan 7, 2018 at 2:18 AM, christopher okoro 
> wrote:
>
>> Which regular expression do I write in my URLs to give me this
>> 'host:8000/?page=1' in my browser address
>>
>> --
>> 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-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/b8527e36-d43c-4af8-848c-794cc27757dc%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHtg44CVG46SwAYUGXG0LBebjaHa9Fp5kaU8vv7kTDHE58c0Sw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django URL pattern for an unusual address

2018-01-07 Thread Dylan Reinhold
You will just match that to /
The ?page=1 you will deal with in the view you point / to.

In you view you retrive the page value from the request object
Somthing like


page = request.GET.get('order', 'name')

Dylan

On Sun, Jan 7, 2018 at 2:18 AM, christopher okoro 
wrote:

> Which regular expression do I write in my URLs to give me this
> 'host:8000/?page=1' in my browser address
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/b8527e36-d43c-4af8-848c-794cc27757dc%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHtg44Au5uFrmaFfxmhiMUZJEt%2B29tcggZ8QDrCSC0x7S4BF9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-07 Thread Jason
Actually, using order_by('?') is the worst thing possible, especially in a 
largish db in production.

Why?

That query generated is SELECT  FROM  WHERE  ORDER BY RAND() 
LIMIT N

where the random function is executed for every row in the result set which 
is ordered by the generated value.  As I'm sure you can imagine, running 
this on a medium sized db table will be _slow_

Check out 
https://stackoverflow.com/questions/962619/how-to-pull-a-random-record-using-djangos-orm
 for 
better options

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e6505c0f-1186-493b-b0c2-af8881663183%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Disallowed User Agents | Force To upgrade

2018-01-07 Thread Andréas Kühne
Include something like this:
https://browser-update.org/

It'll add a warning on your site that says that they should upgrade their
browser to get the best experience.

Regards,

Andréas

2018-01-06 6:11 GMT+01:00 Ruchit Bhatt :

> In my new Django project, i am planning to use CSS Grid for template
> layout. To make site responsive without using bootstrap.
>
> So here i want to know how can i block or force to upgrade those browser
> which doesn't support CSS grid ??
>
>
> For testing purpose i tried this in *settings.py* but nothing works
>
>
> DISALLOWED_USER_AGENTS = (re.compile(r'IE\s[0-9]+', re.IGNORECASE), )
>
>
> is there any better way to do this ? where i can force user to upgrade
> their browser
>
>
> Thank you
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/ff9aad10-52ad-43c3-b0ed-eb313fc20b28%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK4qSCcoVcQgeR-qxq4XtR6Ufp7OMhmWoWiU2pC%2BAjrU_piM3A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


django URL pattern for an unusual address

2018-01-07 Thread christopher okoro
Which regular expression do I write in my URLs to give me this 
'host:8000/?page=1' in my browser address

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b8527e36-d43c-4af8-848c-794cc27757dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can you people explain why the def _str_() method is used below?

2018-01-07 Thread project . wsms
That is returning a string expression for your model. I will explain with 
an example.
Consider you were to pull the list of authors in one of your template in a 
*choice 
field*. If you do not have a string method your choice field options by 
default will look like:

   - author.objects(1)
   - author.objects(2)
   
and so on. Basically, you will get a list of objects in return. However, 
that is not how you would want your users to see. Your users would want to 
know the text/value/name of the author.  That's when you put a string 
method to your model. Now if you pull the list of objects you will get it 
as:

   - James
   - jack

So this method returns a string representation of your model. Hope this 
helps.







On Sunday, January 7, 2018 at 10:02:22 AM UTC+5:30, utpalbr...@gmail.com 
wrote:
>
> from django.db import models
> class Blog(models.Model):
> name = models.CharField(max_length=100)
> tagline = models.TextField()
>
> def __str__(self):  # __unicode__ on Python 2
> return self.name
> class Author(models.Model):
> name = models.CharField(max_length=200)
> email = models.EmailField()
>
> def __str__(self):  # __unicode__ on Python 2
> return self.name
> class Entry(models.Model):
> blog = models.ForeignKey(Blog, on_delete=models.CASCADE)
> headline = models.CharField(max_length=255)
> body_text = models.TextField()
> pub_date = models.DateField()
> mod_date = models.DateField()
> authors = models.ManyToManyField(Author)
> n_comments = models.IntegerField()
> n_pingbacks = models.IntegerField()
> rating = models.IntegerField()
>
> def __str__(self):  # __unicode__ on Python 2
> return self.headline
>
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c3ed6a05-eb7a-4e8e-93f0-2d2c1faeb092%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-07 Thread Jani Tiainen
Hi,

Something like this:

post_id = Post.objects.values_list ('id', flat=True).order_by('?').first()
return redirect('postview', id=post_id)


7.1.2018 15.33 "Ronnie Raney"  kirjoitti:

> If I understand you, you suggest using my existing DetailView url which
> shows the detailed Post, but create a view which selects a random pk.
>
> I thought of this but I don’t know how to go about creeating a view that
> selects a random pk, then applies to the existing urlpattern.
>
> My guess is to count() the Post objects, then randomly pick one of the
> objects. Then somehow grab the primary key, post_id, and somehow insert
> into a urlpattern. Also point to the correct template. Any help appreciated!
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/493e4623-df7a-4605-8dcc-e88e2db17064%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91oeyEgtyzoXcU%3DXhAWFb2ddbHL2i7aiRvqwfUMvQH%2BkBUg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-07 Thread m712
What you need is actually very simple. Create a 'random_post' URL, which points 
to a view doing the shuffle logic and returns a redirect to the proper page, 
say '/post/$id', then make that a valid URL and use a DetailView.

On January 7, 2018 4:32:11 PM GMT+03:00, Ronnie Raney  
wrote:
>If I understand you, you suggest using my existing DetailView url which
>shows the detailed Post, but create a view which selects a random pk.
>
>I thought of this but I don’t know how to go about creeating a view
>that selects a random pk, then applies to the existing urlpattern.
>
>My guess is to count() the Post objects, then randomly pick one of the
>objects. Then somehow grab the primary key, post_id, and somehow insert
>into a urlpattern. Also point to the correct template. Any help
>appreciated!

   m712
--
https://nextchan.org -- https://gitgud.io/blazechan/blazechan
I am awake between 3AM-8PM UTC, HMU if the site's broken

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7F10E576-DF89-4403-B958-3B4D62B9%40getbackinthe.kitchen.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-07 Thread Ronnie Raney
If I understand you, you suggest using my existing DetailView url which shows 
the detailed Post, but create a view which selects a random pk.

I thought of this but I don’t know how to go about creeating a view that 
selects a random pk, then applies to the existing urlpattern.

My guess is to count() the Post objects, then randomly pick one of the objects. 
Then somehow grab the primary key, post_id, and somehow insert into a 
urlpattern. Also point to the correct template. Any help appreciated!

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/493e4623-df7a-4605-8dcc-e88e2db17064%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: MongoDB and Django

2018-01-07 Thread Etienne Robillard

Hi,

My recommendation is to check out libschevo. [1]

It is compatible with Durus and ZODB databases and support schema 
migrations in Pure python.


cheers,

Etienne

1. https://www.isotopesoftware.ca/documentation/libschevo/

Le 2018-01-07 à 03:34, Jani Tiainen a écrit :

Hi,

You can use MongoDB with Django just fine. Though, you won't get any 
ORM integration.


If you're not bound to MongoDB yet personally I would suggest to take 
a look at ArangoDB. It doesn't have ORM integration either but in my 
opinion it's much better than MongoDB. It has many SQL-like features 
(including it's query language and proper transactions)


On Sun, Jan 7, 2018 at 5:00 AM, Mark Phillips 
mailto:m...@phillipsmarketing.biz>> wrote:


Is anyone on the list using MongoDB with Django?

I see the MongoDB-django engine is no longer in active
development, so I am not sure if I want to start using it as no
one is supporting it.

There are other python mongodb options, and some django rest mongo
options. I am curious what, if anything, the group is using.

Thanks!

Mark
-- 
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-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at https://groups.google.com/group/django-users
.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/CAEqej2PCHthPB3gzAewsvT7o141gdLEq_0P6VVH5JFngcain%3Dw%40mail.gmail.com

.
For more options, visit https://groups.google.com/d/optout
.




--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...
--
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-users+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91oe36_P3gzuPRqegX%3Dcqc%3DdF82vygqndJLW8vMqcwFQ1cg%40mail.gmail.com 
.

For more options, visit https://groups.google.com/d/optout.


--
Etienne Robillard
tkad...@yandex.com
https://www.isotopesoftware.ca/

--
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8cb57cdf-5660-0718-6eab-da14524e67dc%40yandex.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I use Django to execute PostGIS query to get polygons within four points?

2018-01-07 Thread Jani Tiainen
Something like following should work. Didn't checked if that actually works.

Mymodel.objects.filter(geom__inside=Polygon.from_bbox((x1,y1,x2,y2),
srid=1234))

On Sun, Jan 7, 2018 at 10:41 AM, Jani Tiainen  wrote:

> Hi,
>
> I didn't realize what you were asking for. :D
>
> Django has bunch of spatial queries, so you're looking some of those
> __inside, __within lookups. Coordinate transformations do happen
> automatically so you just need to provide srid for you "envelope".
>
> On Sun, Jan 7, 2018 at 1:48 AM, Tom Tanner 
> wrote:
>
>> Here's a sample PostGIS query I use to get geometries within four points:
>>
>> SELECT *
>> FROM myTable
>> WHERE ST_MakeEnvelope(-97.82381347656252, 30.250444940663296, -
>> 97.65901855468752, 30.29595835209862, 4326) && ST_Transform(myTable.geom,
>> 4326);
>>
>>
>> With this query, I can get all rows within those four points. How do I
>> execute this query or similar queries in Django or GeoDjango?
>>
>> --
>> 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-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Jani Tiainen
>
> - Well planned is half done, and a half done has been sufficient before...
>



-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91ofxrrmVTSenvzbF%2BeSV5StvLEofVfa7J4h%3DBfWN4cmCcA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I use Django to execute PostGIS query to get polygons within four points?

2018-01-07 Thread Jani Tiainen
Hi,

I didn't realize what you were asking for. :D

Django has bunch of spatial queries, so you're looking some of those
__inside, __within lookups. Coordinate transformations do happen
automatically so you just need to provide srid for you "envelope".

On Sun, Jan 7, 2018 at 1:48 AM, Tom Tanner 
wrote:

> Here's a sample PostGIS query I use to get geometries within four points:
>
> SELECT *
> FROM myTable
> WHERE ST_MakeEnvelope(-97.82381347656252, 30.250444940663296, -
> 97.65901855468752, 30.29595835209862, 4326) && ST_Transform(myTable.geom,
> 4326);
>
>
> With this query, I can get all rows within those four points. How do I
> execute this query or similar queries in Django or GeoDjango?
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91oeeAHfgAke5mB4PYx8n8%3DKvHgYPY27ua5ULWB1Qz6n5og%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I use Django to execute PostGIS query to get polygons within four points?

2018-01-07 Thread Jani Tiainen
Hi,

I'm not sure is there already such expression/aggregation available, but
you can always create your own expression/aggregate that does whatever you
want to.

Check Django sources to check how GIS lookups/aggregates are made.

On Sun, Jan 7, 2018 at 1:48 AM, Tom Tanner 
wrote:

> Here's a sample PostGIS query I use to get geometries within four points:
>
> SELECT *
> FROM myTable
> WHERE ST_MakeEnvelope(-97.82381347656252, 30.250444940663296, -
> 97.65901855468752, 30.29595835209862, 4326) && ST_Transform(myTable.geom,
> 4326);
>
>
> With this query, I can get all rows within those four points. How do I
> execute this query or similar queries in Django or GeoDjango?
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91ocTQEv_antqNqm8m3ahNjkBnfyHA0yRcp0h6jiU-3AOwQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: MongoDB and Django

2018-01-07 Thread Jani Tiainen
Hi,

You can use MongoDB with Django just fine. Though, you won't get any ORM
integration.

If you're not bound to MongoDB yet personally I would suggest to take a
look at ArangoDB. It doesn't have ORM integration either but in my opinion
it's much better than MongoDB. It has many SQL-like features (including
it's query language and proper transactions)

On Sun, Jan 7, 2018 at 5:00 AM, Mark Phillips 
wrote:

> Is anyone on the list using MongoDB with Django?
>
> I see the MongoDB-django engine is no longer in active development, so I
> am not sure if I want to start using it as no one is supporting it.
>
> There are other python mongodb options, and some django rest mongo
> options. I am curious what, if anything, the group is using.
>
> Thanks!
>
> Mark
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAEqej2PCHthPB3gzAewsvT7o141gdLEq_0P6VVH5JFngcain%3Dw%
> 40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91oe36_P3gzuPRqegX%3Dcqc%3DdF82vygqndJLW8vMqcwFQ1cg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-07 Thread Jani Tiainen
Hi.

Since you do have show post url, I would create random view just to
redirect to show post view with random post id.

7.1.2018 5.49 ap. "Ronnie Raney"  kirjoitti:

> Greetings! My first time using this forum. Using Django 2.0 for a project.
> I'm a beginner so I appreciate your patience.
>
> I have a type of blog app,  but I don't want the routing/url to be
> traditional. I want the user to be able to hit a button that says "Random
> Post" which takes them to a random blog post.
>
> I'm not at all sure of the best way to approach this, but I'll share what
> I have for context. This blog works because I have class-based views using
> ListView and DetailView. I have a template that shows ALL of the blog posts
> in chronological order as a ListView, and I have a template that shows each
> blog post as a DetailView. It works great but I want this "random"
> functionality for my routing.
>
> *Model*: I created a model called Post with all the typical fields,
> including a unique autofield. My intention was to randomly select a pk
> using this autofield. I thought about using a property to do some of the
> querying/logic for my random functionality, but I'm not sure if this is the
> best way to do it.
>
> *View: *I have created a custom method-type view, but it doesn't work.
>
> def random_post(request):
>>
>> posts = Post.objects.all()
>>
>> shuffle (posts)
>>
>> random_obj = posts.first()
>>
>> context = {'random_obj': random_obj,}
>>
>> return render(request, 'blog/random_post.html', context)
>>
>>
> *URL: *I have a 'path' type urlpattern...
>
> path('posts/random_post/', views.random_post, name='random_post'),
>>
>
> *TEMPLATE: *Here is the link to my randomly selected blog post...
>
> > role="button">Random Blog Post
>
>
> The "Detail" template for my blog post has nothing special. The routing
> seems to work just fine, but the fields are empty. No data is being sent
> from the model to the view.
>
> FYI, this is actually not a blog. I'm using blog logic for the sake of
> conversation, but I have a very specialized reason for wanting to choose
> random objects and render them in a view.
>
> Thanks in advance!
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/c68e062a-c2a3-434e-aa70-cfcf3e10e600%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91oeMjKMpQvwhJVqry_US-XW1OP5q2jgyxYZrAwvQoX6UWA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.