Suggestion for prefetch_related() documentation

2022-06-23 Thread Laurent Lyaudet
Hello,

I made a simple test to check the number of queries done :

# First part
order = Order.objects.get(id=2)  # one query
items = list(order.items.all())  # one query
items = list(order.items.all())  # one query
items = list(order.items.all())  # one query

# Second part
order = Order.objects.prefetch_related("items").get(id=2)  # two queries
items = list(order.items.all())  # no query
items = list(order.items.all())  # no query
items = list(order.items.all())  # no query

# Third part
order = Order.objects.get(id=2)  # one query
prefetch_related_objects([order], "items")  # one query
items = list(order.items.all())  # no query
items = list(order.items.all())  # no query
items = list(order.items.all())  # no query
prefetch_related_objects([order], "items")  # no more query
prefetch_related_objects([order], "items")  # no more query

I was surprised that there was 4 queries for the First part of the test 
instead of 2 for the other parts, because I was expecting that .all() would 
also fill the cache and not only use it.
Maybe it is intended.
I think that this test or something else explaining this point could 
enhance the documentation on prefetch_related() and 
prefetch_related_objects().
I advised my colleagues to use prefetch_related_objects() when in doubt 
whether the objects given have been already extended with prefetching.

Best regards,
 Laurent Lyaudet




-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/806fd09c-b997-4a1d-91c0-9c4cf5860f2an%40googlegroups.com.


Timeout error in send_mail function

2022-06-23 Thread Sona Sivasundari
Hi.
I'm working on a project with django and django rest framework.
In one of my views, I tried implementing a simple send_mail, but it gives 
me a TimeOut error. I configured the settings (Email backend as smtp, email 
host, password, ...), and also alowed my email to accept 'less secured 
apps',  but it doesn't seem to work.
I also tried the port 25, 587 and 465. None of that seem to work.

Here is the error:
[WinError 10060] A connection attempt failed because the connected party 
did not properly respond after a period of time, or established connection 
failed because connected host has failed to respond

Can someone please help?
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6b07847d-5731-4637-b054-64f607cbeb8an%40googlegroups.com.


Code produced by "django-admin startproject" isn't formatted by black

2022-06-23 Thread Paweł Adamczak
Hi!

I just run "django-admin startproject" command on the latest Django version 
(4.0.5) and noticed that the code it generated isn't formatted by black, 
even though #33476  explicitly 
mentions that it should.

I wasn't sure if I should open another bug or comment on the one above, so 
I decided to write here first.

I'm happy to contribute via a PR.

All best,
Paweł

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/34735176-9060-4685-b259-ff621473231dn%40googlegroups.com.


Re: Django could not parse the remainder

2022-06-23 Thread Shaheed Haque
>From memory, At least in Jinja templates, you can explicitly use the
dictionary form {{ key["hypen-ated"] }}... Have you tried that?

On Thu, 23 Jun 2022, 14:44 Ryan Nowakowski,  wrote:

>
> https://stackoverflow.com/questions/8252387/how-do-i-access-dictionary-keys-that-contain-hyphens-from-within-a-django-templa
>
> On Mon, Jun 20, 2022 at 07:52:46AM -0700, Koushik Romel wrote:
> > When trying to get a value from restapi in for loop to display it takes
> > hyphen(-) as minus(-). And there is no way to change the api structure
> > because it is fixed.
> > Im struck in this anyone help me..
> > The exact error and the expected json is given below is down below
> >
> > when i try to print {{key}} the whole for loop data it displays like this
> > {'_id': ObjectId('xxx'), 'date': 'jun/20/2022', 'dst-active':
> > 'false', 'gmt-offset': '+05:30', 'time': '20:19:04',
> > 'time-zone-autodetect': 'true', 'time-zone-name': 'Asia/Kolkata'}
> >
> > when i specify {{key.dst-active}} it throws this error
> > TemplateSyntaxError at /store/Could not parse the remainder: '-active'
> from
> > 'key.dst-active'
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20220623134418.GE18918%40fattuba.com
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHAc2jdi0tCsM1ypeUir9NRmw4LjOgUuR6VEJyrpXt4np9gt5A%40mail.gmail.com.


Re: Django could not parse the remainder

2022-06-23 Thread Lakshyaraj Dash XI-D 25
You can have a template filter that can parse your dictionary.

On Thu, Jun 23, 2022, 19:14 Ryan Nowakowski  wrote:

>
> https://stackoverflow.com/questions/8252387/how-do-i-access-dictionary-keys-that-contain-hyphens-from-within-a-django-templa
>
> On Mon, Jun 20, 2022 at 07:52:46AM -0700, Koushik Romel wrote:
> > When trying to get a value from restapi in for loop to display it takes
> > hyphen(-) as minus(-). And there is no way to change the api structure
> > because it is fixed.
> > Im struck in this anyone help me..
> > The exact error and the expected json is given below is down below
> >
> > when i try to print {{key}} the whole for loop data it displays like this
> > {'_id': ObjectId('xxx'), 'date': 'jun/20/2022', 'dst-active':
> > 'false', 'gmt-offset': '+05:30', 'time': '20:19:04',
> > 'time-zone-autodetect': 'true', 'time-zone-name': 'Asia/Kolkata'}
> >
> > when i specify {{key.dst-active}} it throws this error
> > TemplateSyntaxError at /store/Could not parse the remainder: '-active'
> from
> > 'key.dst-active'
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20220623134418.GE18918%40fattuba.com
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF7qQgA5YCypVi-2TahbyqmvOR9dr%2BH%2BueQVREi2xotxreBZjQ%40mail.gmail.com.


ERROR : no such table

2022-06-23 Thread Hugh Frost
Good evening all,
  
I'm working on django 3.2 project, i have one issue with migrations.

my project already in live. same time I'm adding two new tables in same 
file but that was in local, now i'm trying to add live database in my 
modified local file but tables created when i migrate but database not 
synced instead of that error page display "no such table"

i don't know how to fix this, anyone know how to configure that database 
with new tables in django 3.2

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/587799fc-87a5-4c5c-b735-086d5d737eb7n%40googlegroups.com.


new record is created while updating

2022-06-23 Thread Ayush Bajpai
model:
class Batch(models.Model):
batch_id = models.AutoField(primary_key=True, default=None)
batch_name = models.CharField(max_length=256, default=None, null=True)
... some more fields

views:
def organisationEditBatch(request, batch_id):
batch = Batch.objects.get(batch_id=batch_id)
if request.method == 'POST':
batch.batch_name = request.POST.get("batch_name")
batch.save() 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/924ac596-824d-410e-bd64-0d7698c2f3fdn%40googlegroups.com.


no such table

2022-06-23 Thread Hugh Frost
Good evening all,
 
  My project was based on django 3.2, I have an issue with migrations, my 
project was already in live same time I try to create two new tables after 
that i'm adding the live database file in local file but that shows Error : 
no such table

i don't know how to fix this, anyone please help us

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b5a2db9e-127e-4bf4-ad0f-2dea06d3f769n%40googlegroups.com.


Re: Django could not parse the remainder

2022-06-23 Thread Ryan Nowakowski
https://stackoverflow.com/questions/8252387/how-do-i-access-dictionary-keys-that-contain-hyphens-from-within-a-django-templa

On Mon, Jun 20, 2022 at 07:52:46AM -0700, Koushik Romel wrote:
> When trying to get a value from restapi in for loop to display it takes 
> hyphen(-) as minus(-). And there is no way to change the api structure 
> because it is fixed.
> Im struck in this anyone help me..
> The exact error and the expected json is given below is down below
> 
> when i try to print {{key}} the whole for loop data it displays like this
> {'_id': ObjectId('xxx'), 'date': 'jun/20/2022', 'dst-active': 
> 'false', 'gmt-offset': '+05:30', 'time': '20:19:04', 
> 'time-zone-autodetect': 'true', 'time-zone-name': 'Asia/Kolkata'}
> 
> when i specify {{key.dst-active}} it throws this error
> TemplateSyntaxError at /store/Could not parse the remainder: '-active' from 
> 'key.dst-active'

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20220623134418.GE18918%40fattuba.com.


Re: server can't connect in browser

2022-06-23 Thread Paul Kudla (SCOM.CA Internet Services Inc.)



ok this is networking 101 stuff

if the server is running on 127.0.0.1 8000 (or whatever port)

and you are trying to access from another system you need to use the ip 
address of the server (not 127.0.0.1) and it needs to be accesable on 
your network to be able to find it.


best to try telneting to the server as a test to verify ip & ports are 
correct.


example :

telnet 192.168.0.2  8000  for example if you get 
a response then you are good to go.


ie

"telnet 192.168.0.2 8000"





Happy Thursday !!!
Thanks - paul

Paul Kudla


Scom.ca Internet Services 
004-1009 Byron Street South
Whitby, Ontario - Canada
L1N 4S3

Toronto 416.642.7266
Main 1.866.411.7266
Fax 1.888.892.7266
Email p...@scom.ca

On 6/22/2022 1:46 PM, Django-Admin wrote:
Try opening the link in a browser in the same EC2 instance, if you are 
not doing so.


On Wednesday, June 22, 2022 at 6:37:18 PM UTC+5:30 kamald...@gmail.com 
wrote:


Hi all,
I am quite new in django. Just started my first project in it.
I started an ec2 instance, setup virtual environment and run server
through
python manage.py runserver command.
Server is up with no errors. But when I copy the link and open in
browser it says site can't be reached. Screenshots of it are
attached for reference.

--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dfe8f847-65bc-4602-b3b9-9e7a81998459n%40googlegroups.com 
.


--
This message has been scanned for viruses and
dangerous content by *MailScanner* , and is
believed to be clean.


--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eef876cb-0c0c-5123-63f2-3fc6b727eac5%40scom.ca.


Re: ?? question ,its urgent

2022-06-23 Thread Soumen Khatua
Better use JSON Field to store all the informations

On Mon, Jun 20, 2022 at 12:16 PM Abhinandan K 
wrote:

> how to store the data in django databse table if user append fields
> according to their need
> for example i have 1 one field 1) name 2) age 3) salary and the sign('+)
> if user click on + sign row append one plus in form..my question is that i
> want to store the data in all appended textboxes in single field in
> database,,
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAA6_Mp6UPLakoi-JhcgB4U89-iKfDwAaxDWwW547tFKyk_imrg%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPUw6WZmMSjWKoTxGvmvuk_paEkvpvD5NjX0ri7cRrDe%2BtMtfg%40mail.gmail.com.