Re: How to roll back related objects if any error happened.

2022-07-05 Thread Antonis Christofides
I'm not really an expert, but it strikes me that this doesn't work. If you are 
using MySQL or SQLite, make sure you read the Database-specific notes on 
Database transactions 
<https://docs.djangoproject.com/en/4.0/topics/db/transactions/#database-specific-notes> 
in the Django documentation. If you want further help on this, please post your 
DATABASES setting.


Regards,

Antonis


On 05/07/2022 17.17, Sencer Hamarat wrote:


Hi Antonis,

The code that I tried is something like below:

with transaction.atomic():
    parent_data = {
        "foo": "bar",
        "baz": "bar"
    }

    parent_serializer = ParentSerializer(data=parent_data)
    if parent_serializer.is_valid():
        parent_obj = parent_serializer.save()

        child_data = {
            "parent_id": parent_obj.id <http://parent_obj.id>,
            "baz": "foo":
            "bar": "baz"
        }

        child_serializer = ChildSerializer(data=child_data)
        if child_serializer.is_valid():
            child_obj = child_serializer.save()


As I mentioned in the previous email;
If child_serializer.save() raises an exception, the db row created by 
parent_serializer.save() is not rolled back.


Actually, I changed the way I send the data to the db. I put the child data as 
a nested json,
wrote a create method in the serializer and pushed the data through a single 
serializer to the db.
Thus, any bad request at the serializer validation level is avoided and there 
is no need to go back.


Anyway, If you think that my claim above is false, I would like to hear your 
opinion.



Kind regards,
Sencer HAMARAT



On Tue, Jul 5, 2022 at 3:49 PM Antonis Christofides 
 wrote:


Could you show the code with your attempt to use atomic?

On 05/07/2022 14.45, Sencer Hamarat wrote:

Hi,

I tried that but, when child_serializer.save() throws an exception, the
row created by parent_serializer.save() at the database is not rolled back.

Kind regards,
Sencer HAMARAT



On Mon, Jul 4, 2022 at 7:59 PM Ryan Nowakowski  wrote:

You can use transaction.atomic:

https://docs.djangoproject.com/en/4.0/topics/db/transactions/#controlling-transactions-explicitly

On July 4, 2022 7:16:41 AM EDT, Sencer Hamarat
 wrote:

Hi,

Say I have a parent and a child model.

And also there is a view which is using DRF serializers to save
data into models.

The saving operation steps are:

First create parent parent object
Then, create child object with parent object relation.

The view code regarding the description above:

parent_data = {
    "foo": "bar",
    "baz": "bar"
}

parent_serializer = ParentSerializer(data=parent_data)
if parent_serializer.is_valid():
    parent_serializer.save()

    child_data = {
        "parent_id": parent_serializer.data['id'],
        "baz": "foo":
        "bar": "baz"
    }

    child_serializer = ChildSerializer(data=child_data)
    if child_serializer.is_valid():
        child_serializer.save()


if any exception is thrown while child_serializer saving, how to
roll back the parent object, too?

Is there any chance to make this happen in a transaction to roll
back any related record?


Kind regards,
Sencer HAMARAT

-- 
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/BEE4B516-7426-4A07-B91B-9733537D4F92%40fattuba.com

<https://groups.google.com/d/msgid/django-users/BEE4B516-7426-4A07-B91B-9733537D4F92%40fattuba.com?utm_medium=email_source=footer>.

-- 
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/CACp8TZiN2bWGc6FKERxRm83_bbyaRZkhr%3DoG_scATQoxREzPJg%40mail.gmail.com

<https://groups.google.com/d/msgid/django-users/CACp8TZiN2bWGc6FKERxRm83_bbyaRZkhr%3DoG_scATQoxREzPJg%40mail.gmail.com?utm_medium=email_source=footer>.
-- 
You received this message because you are subscribed to the Google

Re: How to roll back related objects if any error happened.

2022-07-05 Thread Antonis Christofides

Could you show the code with your attempt to use atomic?


On 05/07/2022 14.45, Sencer Hamarat wrote:

Hi,

I tried that but, when child_serializer.save() throws an exception, the row 
created by parent_serializer.save() at the database is not rolled back.


Kind regards,
Sencer HAMARAT



On Mon, Jul 4, 2022 at 7:59 PM Ryan Nowakowski  wrote:

You can use transaction.atomic:

https://docs.djangoproject.com/en/4.0/topics/db/transactions/#controlling-transactions-explicitly

On July 4, 2022 7:16:41 AM EDT, Sencer Hamarat 
wrote:

Hi,

Say I have a parent and a child model.

And also there is a view which is using DRF serializers to save data
into models.

The saving operation steps are:

First create parent parent object
Then, create child object with parent object relation.

The view code regarding the description above:

parent_data = {
    "foo": "bar",
    "baz": "bar"
}

parent_serializer = ParentSerializer(data=parent_data)
if parent_serializer.is_valid():
    parent_serializer.save()

    child_data = {
        "parent_id": parent_serializer.data['id'],
        "baz": "foo":
        "bar": "baz"
    }

    child_serializer = ChildSerializer(data=child_data)
    if child_serializer.is_valid():
        child_serializer.save()


if any exception is thrown while child_serializer saving, how to roll
back the parent object, too?

Is there any chance to make this happen in a transaction to roll back
any related record?


Kind regards,
Sencer HAMARAT

-- 
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/BEE4B516-7426-4A07-B91B-9733537D4F92%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/CACp8TZiN2bWGc6FKERxRm83_bbyaRZkhr%3DoG_scATQoxREzPJg%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/aa91c012-95d7-ff3d-bfdc-0bcfcb32a3ee%40antonischristofides.com.


Re: server can't connect in browser

2022-06-22 Thread Antonis Christofides

Hello,

If you insist on working this way, there are two things you need to do:

1. You need to run it with "python manage.py runserver 0.0.0.0:8002".
2. 127.0.0.1 is the wrong address. Find the IP address of the server and use
   that one.

Typically, when developing (and especially when we're new), we run the Django 
development server on the local machine, not an a EC2 instance or anywhere else. 
You will be less confused if you do that, and you will have fewer problems.


Regards,

Antonis


On 22/06/2022 06.44, Deep Kamal 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/7643c462-97bf-479d-90a0-302a10255470n%40googlegroups.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/0be1b239-5e14-5d89-bb93-686b86b69c0c%40antonischristofides.com.


Re: variable inside a template

2022-06-16 Thread Antonis Christofides
What you are trying to do is very unusual, and any solution to exactly what you 
are asking is going to be an ugly hack. So, why do you want to do this? What are 
these static files that you have in mylist?



On 16/06/2022 14.09, luca72.b...@gmail.com wrote:

Hello i have a list like:
mylist =  ['1,png','2.png',3.jpj']
in the template i do as follow:
{% for o in mylist %}
        
        {% if "png" in o %}
        {{ o }}
        %}" class="">

        {% else %}
            {{o}}
        
        {% endif %}
        {% endfor %}
in the template i see the file name but it never render, if i loock the source 
code i see that in the http://127.0.0.1:8000/static_files/polls/%7Bo%7D>" class="">

So i never get the correct file name.
How is the correct way to get the name of the variable o inside the img tag
Thanks
--
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/b7e47034-7029-476a-bb08-a5e780c4b95bn%40googlegroups.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/c04b166c-e738-f489-47d2-b89ed5b01f57%40antonischristofides.com.


Re: static file serve nothing is load in deployment

2022-06-15 Thread Antonis Christofides
If you are running the server with "manage.py runserver", STATIC_ROOT is 
irrelevant. You should put the "polls" directory in "polls/static", i.e. e.g. 
"polls/static/polls/style.css"; this is relative to the folder where "manage.py" is.



On 15/06/2022 13.54, luca72.b...@gmail.com wrote:

no i'm not in production
i'm running with runserver

Il giorno mercoledì 15 giugno 2022 alle 12:45:54 UTC+2 Antonis Christofides ha 
scritto:


Is this in production? Are you using apache or something? if yes, please
take a look at

https://djangodeployment.readthedocs.io/en/latest/_images/how-static-files-work-apache.png.
Otherwise, please explain in more detail what your deployment environment
looks like.


On 15/06/2022 13.08, luca72.b...@gmail.com wrote:

Hello i have this configuration in settings.py

STATIC_URL = '/static_files/'
STATIC_ROOT =  'D:/prova_nuovo_sito/static_files'

INSTALLED_APPS = [
    'polls.apps.PollsConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

The folder where I store the file is 'D:/prova_nuovo_sito/static_files'
in this folder I have a subfolder polls with all the needed file

The template I write as follow:
{% load static %}
    

What is wrong
Thanks

-- 
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 view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/8398ea8b-63da-40c1-90e6-fedd08594085n%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/8398ea8b-63da-40c1-90e6-fedd08594085n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/34b6ab11-2892-4d16-a848-ee8b09a09344n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/34b6ab11-2892-4d16-a848-ee8b09a09344n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/16abae4f-b0d9-73e2-2e97-fe5abf4f57a3%40antonischristofides.com.


Re: static file serve nothing is load in deployment

2022-06-15 Thread Antonis Christofides
Is this in production? Are you using apache or something? if yes, please take a 
look at 
https://djangodeployment.readthedocs.io/en/latest/_images/how-static-files-work-apache.png. 
Otherwise, please explain in more detail what your deployment environment looks 
like.



On 15/06/2022 13.08, luca72.b...@gmail.com wrote:

Hello i have this configuration in settings.py

STATIC_URL = '/static_files/'
STATIC_ROOT =  'D:/prova_nuovo_sito/static_files'

INSTALLED_APPS = [
    'polls.apps.PollsConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

The folder where I store the file is 'D:/prova_nuovo_sito/static_files'
in this folder I have a subfolder polls with all the needed file

The template I write as follow:
{% load static %}
    

What is wrong
Thanks

--
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/8398ea8b-63da-40c1-90e6-fedd08594085n%40googlegroups.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/b094eb89-953c-56fa-4c37-e827b7b76331%40antonischristofides.com.


Re: I can't use accented letters in my model

2022-06-14 Thread Antonis Christofides
Exactly. The important thing to remember here is that, in Python 2, a "string" 
is actually a list of bytes, whereas a "unicode string" is actually a list of 
characters (not a list of unicode characters—just a list of characters). The 
confusion arises because, when Python was created, i.e. in 1990, multi-byte 
characters were in their infancy, and we mostly assumed that a character and a 
byte was more or less the same thing.


In Python 3, the Python 2 "strings" were renamed to "bytes", and the Python 2 
"unicode strings" were renamed to "strings"—and the syntax for the literals of 
these types also changed. This made it way better.


More information about all this is in 
https://djangodeployment.com/2017/06/19/encodings-part-1/.




On 12/06/2022 12.07, Virgilio Ravagli wrote:

I found a way: book.title = titolo.decode('unicode_escape')
it works fine

Il giorno venerdì 10 giugno 2022 alle 21:45:46 UTC+2 Virgilio Ravagli ha 
scritto:

Thank you, Antonis, it works !
book.title = u'Verità' doesn't give any errors.

Just another step: suppose that the title with accented letters stays in a
variable, say titolo, and I want to write
book.title = titolo. It gives error. How can I do, when the assignment on
the right is not a constant ?
Thanks in advance

Il giorno venerdì 10 giugno 2022 alle 15:25:51 UTC+2 Antonis Christofides
ha scritto:

Hello,

try this:

book.title = u'Verità'

Regards,

Antonis

P.S. Sorry I was a bit harsh yesterday—I had drunk too much beer :-)


On 10/06/2022 10.50, Virgilio Ravagli wrote:

I have surround book.save with a try...catch...; the exception is:
You must not use 8-bit bytestrings unless you use a text_factory that
can interpret 8-bit bytestrings (like text_factory = str). It is
highly recommended that you instead just switch your application to
Unicode strings.
Without the try...catch, here is the traceback:
Environment:


Request Method: POST
Request URL: http://localhost:8000/uti/dataLoading/

Django Version: 1.8.5
Python Version: 2.7.10
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'uti')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in
get_response
  132.                     response = wrapped_callback(request,
*callback_args, **callback_kwargs)
File
"C:\Users\RavagliV\eclipse-workspace-saved\librarian\uti\views.py" in
datLoading
  34.                 msg = do_dat_loading()
File
"C:\Users\RavagliV\eclipse-workspace-saved\librarian\uti\views.py" in
do_dat_loading
  79.             book.save()
File "C:\Python27\lib\site-packages\django\db\models\base.py" in save
  734.  force_update=force_update, update_fields=update_fields)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in
save_base
  762.             updated = self._save_table(raw, cls, force_insert,
force_update, using, update_fields)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in
_save_table
  827. forced_update)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in
_do_update
  877.         return filtered._update(values) > 0
File "C:\Python27\lib\site-packages\django\db\models\query.py" in 
_update
  580.         return query.get_compiler(self.db).execute_sql(CURSOR)
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py"
in execute_sql
  1062.         cursor = super(SQLUpdateCompiler,
self).execute_sql(result_type)
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py"
in execute_sql
  840.             cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py" in
execute
  79.            

Re: I can't use accented letters in my model

2022-06-10 Thread Antonis Christofides

Hello,

try this:

book.title = u'Verità'

Regards,

Antonis

P.S. Sorry I was a bit harsh yesterday—I had drunk too much beer :-)


On 10/06/2022 10.50, Virgilio Ravagli wrote:
I have surround book.save with a try...catch...; the exception is: You must 
not use 8-bit bytestrings unless you use a text_factory that can interpret 
8-bit bytestrings (like text_factory = str). It is highly recommended that you 
instead just switch your application to Unicode strings.

Without the try...catch, here is the traceback:
Environment:


Request Method: POST
Request URL: http://localhost:8000/uti/dataLoading/

Django Version: 1.8.5
Python Version: 2.7.10
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'uti')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in 
get_response
  132.                     response = wrapped_callback(request, 
*callback_args, **callback_kwargs)
File "C:\Users\RavagliV\eclipse-workspace-saved\librarian\uti\views.py" in 
datLoading

  34.                 msg = do_dat_loading()
File "C:\Users\RavagliV\eclipse-workspace-saved\librarian\uti\views.py" in 
do_dat_loading

  79.             book.save()
File "C:\Python27\lib\site-packages\django\db\models\base.py" in save
  734.                        force_update=force_update, 
update_fields=update_fields)

File "C:\Python27\lib\site-packages\django\db\models\base.py" in save_base
  762.             updated = self._save_table(raw, cls, force_insert, 
force_update, using, update_fields)

File "C:\Python27\lib\site-packages\django\db\models\base.py" in _save_table
  827.                                       forced_update)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in _do_update
  877.         return filtered._update(values) > 0
File "C:\Python27\lib\site-packages\django\db\models\query.py" in _update
  580.         return query.get_compiler(self.db).execute_sql(CURSOR)
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py" in 
execute_sql

  1062.         cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py" in 
execute_sql

  840.             cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\utils.py" in __exit__
  97.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py" in 
execute
  318.         return Database.Cursor.execute(self, query, params)

Exception Type: ProgrammingError at /uti/dataLoading/
Exception Value: You must not use 8-bit bytestrings unless you use a 
text_factory that can interpret 8-bit bytestrings (like text_factory = str). 
It is highly recommended that you instead just switch your application to 
Unicode strings.


Il giorno giovedì 9 giugno 2022 alle 23:17:16 UTC+2 Antonis Christofides ha 
scritto:


Please read my email again.

Antonis Christofides
+30-6979924665(mobile)

On 09/06/2022 22.27, Virgilio Ravagli wrote:

All right.
class Book(models.Model):
       code = models.PositiveIntegerField(primary_key=True)
       title = models.CharField(max_length=60,blank=False,null=False)

book = Book()
    book.code = 1
    book.title = 'Verità'
book.save()

the code is really simple
Il giorno mercoledì 8 giugno 2022 alle 21:07:41 UTC+2 Antonis
Christofides ha scritto:

Please provide the minimum code that reproduces the problem, and the
full traceback.

Regards,

Antonis


On 08/06/2022 18.24, Virgilio Ravagli wrote:

ou must not use 8-bit bytestrings unless you use a text_factory that
can interpret 8-bit bytestrings


-- 
You received this message because you are subscribe

Re: I can't use accented letters in my model

2022-06-09 Thread Antonis Christofides

Please read my email again.

Antonis Christofides
+30-6979924665 (mobile)

On 09/06/2022 22.27, Virgilio Ravagli wrote:

All right.
class Book(models.Model):
       code = models.PositiveIntegerField(primary_key=True)
       title = models.CharField(max_length=60,blank=False,null=False)

book = Book()
book.code = 1
book.title = 'Verità'
book.save()

the code is really simple
Il giorno mercoledì 8 giugno 2022 alle 21:07:41 UTC+2 Antonis Christofides ha 
scritto:


Please provide the minimum code that reproduces the problem, and the full
traceback.

Regards,

Antonis


On 08/06/2022 18.24, Virgilio Ravagli wrote:

ou must not use 8-bit bytestrings unless you use a text_factory that can
interpret 8-bit bytestrings


--
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/cf785c0e-5cfc-4587-b0cd-ea796a62a20bn%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/cf785c0e-5cfc-4587-b0cd-ea796a62a20bn%40googlegroups.com?utm_medium=email_source=footer>.


--
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/5745c834-7b23-3534-f099-b7a3f33bdf39%40antonischristofides.com.


Re: I can't use accented letters in my model

2022-06-08 Thread Antonis Christofides

Please provide the minimum code that reproduces the problem, and the full 
traceback.

Regards,

Antonis


On 08/06/2022 18.24, Virgilio Ravagli wrote:
ou must not use 8-bit bytestrings unless you use a text_factory that can 
interpret 8-bit bytestrings


--
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/9fefa952-2ea6-9aae-8623-0cd4d3a30a3b%40antonischristofides.com.


Re: Need help

2022-06-01 Thread Antonis Christofides

Hello,

If, as I understand, you don't know anything about deployment, a possible 
starting point is the book at https://djangodeployment.com (disclaimer: I am the 
author). It doesn't cover docker, and it also doesn't cover continuous 
development with gitlab. But you can start with the basics and then move forward.


Regards,

Antonis



On 01/06/2022 19.16, Théodore KOSSI wrote:


Hello everyone,
I want your help to deploy my django app.
I have a ubuntu server.
My django project is pushing to gitlab.
So I want to deploy my app django to my ubuntu server using Gitlab and docker
Any help enjoy me
Thanks.

--
theodoros17@python-developer
--
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/CAKiMjQEYVje02k1dSeYACdocH%2B2vD5BgCQZ%2BEAYhF28%3DSy0%2BjA%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/164d1c9b-4483-34cb-9cb5-0fb822694d9a%40antonischristofides.com.


Re: Please criticise use of global keyword in Admin

2022-05-19 Thread Antonis Christofides

Hi,

First of all, you should type REC_FIELDS and CONS_FIELDS, in capitals, as these 
are constants (this is not a Python language requirement but widely used style, 
also suggested by PEP8 iirc).


Then, it seems to me that most of the times you don't need the "global" keyword 
in your code, because you aren't assigning to "receipt_fields". "receipt_fields" 
is a name that points to an array, and you are only manipulating the array to 
which "receipt_fields" is pointing, you aren't actually changing what the name 
is pointing to. For example:


    def hello(field):
    b = receipt_fields
    b.remove(field)

This will effectively remove field from *receipt_fields*, because "b" and 
"receipt_fields" are names that point to the same thing.


There is one exception in your code: at some point you are assigning to 
"receipt_fields_ro" inside a method. In that case, the "global" statement is 
necessary. However, the code looks quite bad to me, but I'm not looking into it 
further in order to not cover too many issues in this discussion.


Regardless whether you need to use the "global" keyword or not, you are using 
global variables, and this is a bad idea. It will work in some cases but 
eventually it will cause you headaches when you are least expecting them. I 
think it will work as long as each Django processes is serving a single HTTP 
request at a time. But one day you will use gunicorn's gevent worker, or 
something that runs Django in threads instead of processes, or async, and you 
will be in a huge mess, because when two users access the site at the same time 
the Django thread that is serving one user will be altering the global variables 
that are being used by the Django thread serving the other user. It will be a 
real pain.


Besides that, this style is quite unusual.

As for a proper solution, I don't remember exactly how the admin works, but if 
you can verify that ReceiptAdmin is instantiated in each request (rather than 
when Django starts), then you can override its __init__() method and set the 
variables you need in the object:


    def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.receipt_fields = REC_FIELDS[:]
    ...

If ReceiptAdmin is instantiated when Django starts and the same object is thus 
used for many requests, you could hijack the "request" object, which might not 
be the best solution but will work way better:


    def get_queryset(self, request):
    qs = super().get_queryset(request)
    request.receipt_fields = REC_FIELDS[:]
    ...

Regards,

Antonis

On 19/05/2022 05.33, Mike Dewhirst wrote:
The code below appears to work perfectly but it worries me because I have 
never used the global keyword before.


Is there a generous guru who will criticise the code constructively for me 
please?


The use case is Admin review of payment gateway receipt records.

Users in the manager group can have readonly access to the transaction half of 
the information while all payment gateway cost info is hidden.


Users in the consultant group get readonly access to the gateway info as well.

Members of the operator group can do manual invoices so they need write access 
to a couple of fields.


Many thanks

Mike

#admin.py for the billing app

rec_fields = [
    "company",
    "chemical",
    "invoice",
    "currency",
    "currency_amount",
    "gst_amount",
    "gst_rate",
    "gst_name",
    "amount_due",
    "amount_paid",
    "paid_by",
    "date_paid",
]


cons_fields = [
    "gateway_flagfall",
    "gateway_rate",
    "gateway_amount",
    "gateway_gst_amount",
    "net_amount",
]

receipt_fields = rec_fields[:]
receipt_fields_ro = rec_fields[:]
consultant_fields = cons_fields[:]

def trim_fields():
    global receipt_fields, receipt_fields_ro, consultant_fields #<<
    if "gateway_flagfall" in receipt_fields:
    for field in consultant_fields:
    receipt_fields.remove(field)
    receipt_fields_ro = receipt_fields[:]


def add_fields(operator=False):
    global receipt_fields, receipt_fields_ro, consultant_fields #<<
    if "gateway_flagfall" not in receipt_fields:
    receipt_fields.extend(consultant_fields)
    receipt_fields_ro.extend(consultant_fields)
    if operator:
    receipt_fields_ro.remove("amount_due")
    receipt_fields_ro.remove("amount_paid")
    receipt_fields_ro.remove("date_paid")


class ReceiptAdmin(admin.ModelAdmin):

    global receipt_fields, receipt_fields_ro #

    def has_add_permission(self, request, obj=None):
    return is_operator(request.user)

    def has_change_permission(self, request, obj=None):
    return is_operator(request.user)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    #
    def get_queryset(self, request):
    qs = super().get_queryset(request)
    if qs:
    if is_operator(request.user):
    

Re: Virtualenv steup

2022-05-12 Thread Antonis Christofides

Is Python working? If you type "python", does Python start?

If yes, you can try reading about virtualenv here: 
https://djangodeployment.com/2016/11/01/virtualenv-demystified/


Regards,

Antonis


On 12/05/2022 13.42, Priyanshu Ganwani wrote:
Hy is any one there as a beginner i  have install python and update version 
and install virtualwrapperlenv , virtualenv and django too,  whenever i close  
and use workon command

to reach on my project  it show's:---
'workon' is not recognized as an internal or external command,
operable program or batch file.
then i try to install workon command by using pip install workon  .
it show :
'subprocess' is not recognized as an internal or external command,
operable program or batch file.
please help to resolve the issue.
--
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/d80bf28c-21ab-40c9-95fb-54a36ade169en%40googlegroups.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/98354134-fb8e-4010-3db4-7862ead52139%40antonischristofides.com.


Re: Django 3.0 -> 3.1 performance degradation

2022-05-05 Thread Antonis Christofides
Hi! This is a very interesting problem, and I'm afraid I'm not qualified to 
answer it. What I'd like to point out is that, if I had done all the work that 
you seem to have done, I would be tempted to start bisecting in between versions 
3 and 3.1 in order to find the exact commit that causes the problem.


(However, in order to avoid that, I might also take a second look at the release 
notes, in case there was some information in there. And I might also ask in the 
developers mailing list—many of those who might know the answer don't read 
django-users.)


It's possible it's a Django issue, but it's also possible it isn't. For example, 
it could be some error in your caches or templates or other configuration that 
happens to only manifest itself in Django>=3.1.


In any case, I'm eager to learn how this plays out.

Regards,

Antonis


On 04/05/2022 12.12, Jonatan Heyman wrote:


Hi!

I've recently upgraded an old Django app from Django 1.11 all the way up to 
Django 4.0. Even though the app is pretty large, the migration went smooth (or 
so I thought). However, when all tests passed and I deployed the app to 
production, I saw that the response time of the app took a significant hit 
(the response time for the 95th percentile went from about 300 ms to 900 ms, 
and the median from about 100 ms to 250 ms). I also saw that the server CPU 
load had increased significantly.


I wrote some load tests and started downgrading Django. Now I've narrowed down 
the problem to appear when I upgrade from Django 3.0.x to Django 3.1.x, with 
no other significant changes to my app code.


Is this something someone else has experienced, or does anyone know what might 
be going on?


Are there any known changes that might increase CPU usage? In that case, I 
could throw more hardware at the problem.


Any ideas, pointers or insights would be greatly appreciated!

Best,
Jonatan
--
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/5f05c06c-bd22-417b-9688-20aca9632bcbn%40googlegroups.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/160b9b6a-fc89-cb54-7dec-39ef1ffafaba%40antonischristofides.com.


Re: SMTP Authentification error

2022-05-02 Thread Antonis Christofides
If some emails are emails are disappearing, you may get ideas on how to fix it 
from 
https://djangodeployment.com/2017/01/18/why-does-django-not-email-me-the-500-internal-server-error/


On 02/05/2022 07.33, 'Delvin Alexander' via Django users wrote:
Improvements! i fixed my settings.py file and now i do not get the error. The 
only problem is that for my email, i do not get the email notification to 
reset my password. Any clues to this?


On Sunday, May 1, 2022 at 4:08:46 AM UTC-7 Mahendra Yadav wrote:

I Know this solution charges are applicable if you want?

Mahendra Yadav

On Wed, 27 Apr 2022, 11:08 am 'Delvin Alexander' via Django users,
 wrote:

Hello everyone,

May you please assist in informing me on what i need to do to resolve
this issue.

- *SMTPAuthenticationError at /password-reset/*
*- (535, b'5.7.8 Username and Password not accepted. Learn more
at\n5.7.8 https://support.google.com/mail/?p=BadCredentials
j64-20020a62c54300b0050d260c0ea8sm13366402pfg.110 - gsmtp')*
*
*
*
*
I included the 16 character code to my environment variable and called
it in my settings.pymfile,  but still the error occurs. Also here is
my settings.py file:

- *EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'*
*EMAIL_HOST = 'smtp.gmail.com '*
*EMAIL_PORT = 587*
*EMAIL_USE_TLS = True*
*EMAIL_HOST_USER = os.environ.get('DB_USER')*
*EMAIL_HOST_PASSWORD = os.environ.get('DB_PASSWORD')*

-- 


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 view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/c18935a8-43bf-4a15-a5ba-95209009498dn%40googlegroups.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/a87e4b6a-6c5d-49ea-b308-2121936054fdn%40googlegroups.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/97031329-66f5-a26b-e002-57a77c789ec9%40antonischristofides.com.


Re: 'ascii' codec can't encode character

2022-04-29 Thread Antonis Christofides
Hi, could you post the full traceback? And if some part of this traceback refers 
to your code, it would be a good idea to also show us that part of your code.



On 29/04/2022 03.01, Thiago Luiz Parolin wrote:

Hi,
i have a model with 2 charfields for givenname, surname:

   nome = models.CharField(
        max_length=150,
        verbose_name=_("Nome"),
        default=''
    )
    sobrenome = models.CharField(
        max_length=150,
        verbose_name=_("Sobrenome"),
        default=''
    )

My modelForm does nothing, just defines a model at Meta with all fields.
My CreateView is just defined with all default values, not overriding anything.
When submitting the form, the server returns 500 if 'nome' or 'sobrenome' 
fields have accent letters like Á, é, í, ç. etc.


The error:
'ascii' codec can't encode character '\xe9' in position 4: ordinal not in 
range(128)

with character depending on user input.

I am using sqlite for db and the pragma encoding returns utf8.

I don't know how to deal with it.
Any help would be 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANbmKyvUWshdM3ENz9LjbG66rLkt4vruM6cC9M-%3DKmL7rcCR%2Bg%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/eafa7d28-9a14-7216-d5a9-46d230cc1530%40antonischristofides.com.


Re: SMTP Authentification error

2022-04-28 Thread Antonis Christofides
In my experience, Gmail does not allow (or does not support) using it as a 
smarthost if all you have is a free account, and even if you get it to work it 
will eventually cause you headaches. I don't know if this has changed the last 
few years, but I feel it hasn't. It's much better to use another service. I use 
runbox.com; mailbox.org is another solution. These are both paid email services. 
In a recent thread, someone also mentioned mailgun and sendgrid, which may be 
better suited for this purpose.


Other than that, you should enter a breakpoint or something in your code to 
verify that the values of EMAIL_HOST_USER and EMAIL_HOST_PASSWORD are what they 
should.


Regards,

Antonis


On 28/04/2022 07.58, 'Delvin Alexander' via Django users wrote:

okay i did both but now i am getting this error. Any clue on why?

*SMTPSenderRefused at /password-reset/*
*
*
*(530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 
https://support.google.com/mail/?p=WantAuthError 
w137-20020a62828f00b0050d2f9c3409sm14545822pfd.199 - gsmtp', 
'webmaster@localhost')

*
On Wednesday, April 27, 2022 at 12:27:02 AM UTC-7 dashlaksh...@gmail.com wrote:

Check whether you have turned on less secure apps or not.

On Wed, Apr 27, 2022, 11:07 'Delvin Alexander' via Django users
 wrote:

Hello everyone,

May you please assist in informing me on what i need to do to resolve
this issue.

- *SMTPAuthenticationError at /password-reset/*
*- (535, b'5.7.8 Username and Password not accepted. Learn more
at\n5.7.8 https://support.google.com/mail/?p=BadCredentials
j64-20020a62c54300b0050d260c0ea8sm13366402pfg.110 - gsmtp')*
*
*
*
*
I included the 16 character code to my environment variable and called
it in my settings.pymfile,  but still the error occurs. Also here is
my settings.py file:

- *EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'*
*EMAIL_HOST = 'smtp.gmail.com '*
*EMAIL_PORT = 587*
*EMAIL_USE_TLS = True*
*EMAIL_HOST_USER = os.environ.get('DB_USER')*
*EMAIL_HOST_PASSWORD = os.environ.get('DB_PASSWORD')*

-- 


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 view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/c18935a8-43bf-4a15-a5ba-95209009498dn%40googlegroups.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/a6f92133-32db-4f4a-ae46-bb1f7644b431n%40googlegroups.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/c200b368-7cdb-19fe-cc69-9682d6548e81%40antonischristofides.com.


Re: simple command line ./manage.py shell puzzle

2022-04-25 Thread Antonis Christofides
The problem also occurs here when I use Django 2.2. It seems it's Django bug 
32183, which in the meantime has been fixed.


https://code.djangoproject.com/ticket/32183


On 22/04/2022 21.47, cseb...@gmail.com wrote:

Antonis

Thanks.  Here are the answers to your questions...

OS: Ubuntu 20.04.3 LTS

Django version: 2:2.2.12-1ubuntu0.11

Django shell version: Python 3.8.10

Chris
On Friday, April 22, 2022 at 2:00:17 AM UTC-5 Antonis Christofides wrote:

It works fine here. I entered your commands exactly and the second one
does not provide any output.

What shell do you have? And what version of Python and Django? And what OS?


On 21/04/2022 22.28, cseb...@gmail.com wrote:


Yes I agree.  But why does it complain that datetime doesn't exist when I
do "  ./manage.py shell < test " ?

Shouldn't it also not do anything like when I paste into a Python3 or
Django shell as you did?

cs

On Thursday, April 21, 2022 at 2:10:39 PM UTC-5 larry@gmail.com wrote:

On Thu, Apr 21, 2022 at 2:53 PM cseb...@gmail.com 
wrote:
>
> The script should quietly exist without error.
>
> I actually have a longer script that is the real workhorse.
> I just made this tiny one to showcase the issue.
>
> I can past
>
> import datetime ; [datetime for e in [1, 2]]
>
> into a regular Python3 shell as well as the Django shell and all is
fine.

$ python3
Python 3.8.10 (v3.8.10:3d8993a744, May 3 2021, 08:55:58)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime ; [datetime for e in [1, 2]]
[,

]


It does not do anything.

>
> The problem I think has something to do with how I inject
> it into the Django shell via "< test".
>
> cs
> On Thursday, April 21, 2022 at 12:18:04 PM UTC-5
larry@gmail.com wrote:
>>
>> On Thu, Apr 21, 2022 at 1:06 PM cseb...@gmail.com
 wrote:
>> >
>> > Why does this fail?...
>> >
>> > % echo "import datetime ; [datetime for e in [1, 2]]" > test
>> >
>> > % ./manage.py shell < test
>> >
>> > Traceback (most recent call last):
>> > File "./manage.py", line 8, in 
>> > django.core.management.execute_from_command_line(sys.argv)
>> > File
"/usr/lib/python3/dist-packages/django/core/management/__init__.py",
line 381, in execute_from_command_line
>> > utility.execute()
>> > File
"/usr/lib/python3/dist-packages/django/core/management/__init__.py",
line 375, in execute
>> > self.fetch_command(subcommand).run_from_argv(self.argv)
>> > File
"/usr/lib/python3/dist-packages/django/core/management/base.py", line
323, in run_from_argv
>> > self.execute(*args, **cmd_options)
>> > File
"/usr/lib/python3/dist-packages/django/core/management/base.py", line
364, in execute
>> > output = self.handle(*args, **options)
>> > File

"/usr/lib/python3/dist-packages/django/core/management/commands/shell.py",
line 92, in handle
>> > exec(sys.stdin.read())
>> > File "", line 1, in 
>> > File "", line 1, in 
>> > NameError: name 'datetime' is not defined
>>
>> What do you expect to happen?
>
> --
> 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 view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/c4a36ffb-8c7a-477f-9d26-f6b898178d91n%40googlegroups.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...@googlegroups.com.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/dcb3ee25-cb8b-4aa9-84d7-ac0772e677f6n%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/dcb3ee25-cb8b-4aa9-84d7-ac0772e677f6n%40google

Re: Connection timeout error with Postgres

2022-04-24 Thread Antonis Christofides
Since PostgreSQL is listening on a different machine, then it is more or less 
clear from the error message that the traffic is being filtered. It's strange it 
works sometimes and other times it isn't working. Does it have a static IP 
address? Is the PostgreSQL server machine running something like fail2ban?


What I'd do if I had such a problem would be to investigate the PostgreSQL 
server machine at the time when the problem is occurring (e.g. check 
/var/log/syslog and `iptables -L`).




On 24/04/2022 20.34, Disha Patel wrote:


Hi Antonis,

Yes, the PostgreSQL server is on a difference machine than Django. I have 
noticed that initial connections are successful but it fails in the later 
connections mainly in long running jobs.


Thanks,
Disha

On Friday, April 22, 2022 at 12:19:27 PM UTC+5:30 Antonis Christofides wrote:

Hi!

I shall assume that PostgreSQL is listening on port 5432. "Connection
timed out" means that the client (Django/psycopg2 in this case) is not
getting any response—as if the PostgreSQL server machine did not exist.
("Connection refused", on the other hand, means that the PostgreSQL server
machine replied that connection on port 5432 is not possible, because
there is no process listening on that port.)

If Django/psycopg2 have the correct domain name or IP address for the
PostgreSQL server, and the correct port, the most common explanation for
"Connection timed out" is that a firewall (typically on the PostgreSQL
server) is filtering that traffic. Is your PostgreSQL server on a
different machine than Django?

Regards,

Antonis


On 17/04/2022 17.34, Disha Patel wrote:


Hi,
I am facing below connection timeout error while using Postgres as
database for my Django application.

"psycopg2.operationalerror: could not connect to server: connection timed
out:

Solutions tried:
1. increased timeout at server end.
2. added conn_max_age in the settings and tried multiple values ( eg.
None, 60,120)

It is a random error but occurs very frequently.
Kindly share if anyone aware about the reason for this issue and any
solutions for the same.


-- 
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 view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/b0c59297-5125-46f5-843f-55c0c00eb4acn%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/b0c59297-5125-46f5-843f-55c0c00eb4acn%40googlegroups.com?utm_medium=email_source=footer>.


--
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/8f413f70-7795-45c5-97ee-ee1278f69a21n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/8f413f70-7795-45c5-97ee-ee1278f69a21n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/090fbd72-73f0-2862-1a88-4693e6e515bd%40antonischristofides.com.


Re: SMTPConnectError

2022-04-24 Thread Antonis Christofides
Indeed, I don't know how it is nowadays, but a few years ago Gmail did not allow 
(or did not support) using it as a smarthost if all you had was a free account. 
This means that even if you get it to work it will stop working the next day or 
month.



On 24/04/2022 16.15, Jason wrote:

how many emails are you sending out like this?

this really isn't a django or python issue, its a gmail/google concern and is 
tied to using this pretty heavily over other services (mailgun, sendgrid, etc)


On Saturday, April 23, 2022 at 7:26:09 PM UTC-4 otuwi...@gmail.com wrote:

Hello guys,
I get the following error when trying to send mails to users after a
successful registration on my app
"raise SMTPConnectError(code, msg)

Exception Type: SMTPConnectError at /register/
Exception Value: (421, b'Server busy, too many connections')

"
Any idea on how to go about this
my email settings configuration looks like this
EMAIL_BACKEND =  'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com '
EMAIL_PORT= 587
EMAIL_HOST_USER = os.environ.get('EMAIL_USER')
EMAIL_HOST_PASSWORD= os.environ.get('EMAIL_PASS')
EMAIL_USE_TLS= True

--
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/f499a79a-16e7-43f7-86a9-bbefaa2c5b11n%40googlegroups.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/f7920702-434d-ffc8-c3b4-2238aa037f55%40antonischristofides.com.


Re: simple command line ./manage.py shell puzzle

2022-04-22 Thread Antonis Christofides
It works fine here. I entered your commands exactly and the second one does not 
provide any output.


What shell do you have? And what version of Python and Django? And what OS?


On 21/04/2022 22.28, cseb...@gmail.com wrote:

Yes I agree.  But why does it complain that datetime doesn't exist when I do " 
 ./manage.py shell < test " ?


Shouldn't it also not do anything like when I paste into a Python3 or Django 
shell as you did?


cs

On Thursday, April 21, 2022 at 2:10:39 PM UTC-5 larry.mart...@gmail.com wrote:

On Thu, Apr 21, 2022 at 2:53 PM cseb...@gmail.com  wrote:
>
> The script should quietly exist without error.
>
> I actually have a longer script that is the real workhorse.
> I just made this tiny one to showcase the issue.
>
> I can past
>
> import datetime ; [datetime for e in [1, 2]]
>
> into a regular Python3 shell as well as the Django shell and all is fine.

$ python3
Python 3.8.10 (v3.8.10:3d8993a744, May 3 2021, 08:55:58)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime ; [datetime for e in [1, 2]]
[,

]


It does not do anything.

>
> The problem I think has something to do with how I inject
> it into the Django shell via "< test".
>
> cs
> On Thursday, April 21, 2022 at 12:18:04 PM UTC-5 larry@gmail.com 
wrote:
>>
>> On Thu, Apr 21, 2022 at 1:06 PM cseb...@gmail.com 
wrote:
>> >
>> > Why does this fail?...
>> >
>> > % echo "import datetime ; [datetime for e in [1, 2]]" > test
>> >
>> > % ./manage.py shell < test
>> >
>> > Traceback (most recent call last):
>> > File "./manage.py", line 8, in 
>> > django.core.management.execute_from_command_line(sys.argv)
>> > File
"/usr/lib/python3/dist-packages/django/core/management/__init__.py", line
381, in execute_from_command_line
>> > utility.execute()
>> > File
"/usr/lib/python3/dist-packages/django/core/management/__init__.py", line
375, in execute
>> > self.fetch_command(subcommand).run_from_argv(self.argv)
>> > File "/usr/lib/python3/dist-packages/django/core/management/base.py",
line 323, in run_from_argv
>> > self.execute(*args, **cmd_options)
>> > File "/usr/lib/python3/dist-packages/django/core/management/base.py",
line 364, in execute
>> > output = self.handle(*args, **options)
>> > File
"/usr/lib/python3/dist-packages/django/core/management/commands/shell.py",
line 92, in handle
>> > exec(sys.stdin.read())
>> > File "", line 1, in 
>> > File "", line 1, in 
>> > NameError: name 'datetime' is not defined
>>
>> What do you expect to happen?
>
> --
> 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 view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/c4a36ffb-8c7a-477f-9d26-f6b898178d91n%40googlegroups.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/dcb3ee25-cb8b-4aa9-84d7-ac0772e677f6n%40googlegroups.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/34d916a3-479c-03c4-25bf-636c257374cf%40antonischristofides.com.


Re: Connection timeout error with Postgres

2022-04-22 Thread Antonis Christofides

Hi!

I shall assume that PostgreSQL is listening on port 5432. "Connection timed out" 
means that the client (Django/psycopg2 in this case) is not getting any 
response—as if the PostgreSQL server machine did not exist. ("Connection 
refused", on the other hand, means that the PostgreSQL server machine replied 
that connection on port 5432 is not possible, because there is no process 
listening on that port.)


If Django/psycopg2 have the correct domain name or IP address for the PostgreSQL 
server, and the correct port, the most common explanation for "Connection timed 
out" is that a firewall (typically on the PostgreSQL server) is filtering that 
traffic. Is your PostgreSQL server on a different machine than Django?


Regards,

Antonis


On 17/04/2022 17.34, Disha Patel wrote:


Hi,
I am facing below connection timeout error while using Postgres as database 
for my Django application.


"psycopg2.operationalerror: could not connect to server: connection timed out:

Solutions tried:
1. increased timeout at server end.
2. added conn_max_age in the settings and tried multiple values ( eg. None, 
60,120)


It is a random error but occurs very frequently.
Kindly share if anyone aware about the reason for this issue and any solutions 
for the same.



--
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/b0c59297-5125-46f5-843f-55c0c00eb4acn%40googlegroups.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/93d90c47-298b-c2bc-6cc8-d4703583e298%40antonischristofides.com.


Re: Possible Django Admin or auth bug or Mozilla bug

2022-04-14 Thread Antonis Christofides

  
  
I haven't tried it, but I have a few observations on your
  template code. First, it would be better to use "{% static %}"
  instead of hardcoding the url to the static files. Second, "{%
  blcok extrastyle %}" is obviously wrong for this, it should be
  extrajs. However, neither of these should affect what you are
  trying to accomplish (except if extrastyle comes earlier than
  extrajs).



On 14/04/2022 06.37, Mike Dewhirst
  wrote:


  
  On 14/04/2022 11:36 am, Mike Dewhirst
wrote:
  
  

Thanks Antonis
  
  OK - the problem has two workarounds. One is to use Chrome.
  
  Two is https://code.djangoproject.com/ticket/33386
  which suggests including some _javascript_ to disable Firefox
  autocomplete ...
  
  $('form').attr('autocomplete', 'off').each(function () {
this.reset();
});

  
  
  Can anyone verify that the above _javascript_ will work?
  
  And I cannot because I don't know how to _javascript_. This is what
  I tried ...
  
  /static/admin/js/autocomplete_off.js
  
  $('form').attr('autocomplete', 'off').each(function () {
      this.reset();
  });
  
  /templates/admin/auth/group/change_form.html
  
  {% extends "admin/change_form.html" %}
  {% load i18n admin_urls static admin_modify %}
  {% block extrastyle %}{{ block.super }}
  
  {% endblock %}
  
  Thanks
  
  Mike
  
  
  
 
  ... but this looks a bit like a sledgehammer. What might that
  do to other browsers?
  
  I guess I'll give that a try and see what happens.
  
  Cheers
  
  Mike
  
  
  On 13/04/2022 11:19 pm, Antonis Christofides wrote:


  
  It happens here as well as far as I can see (tested on a
Debian 11 server running Django 3.2.12).
  The "Chosen groups" box seems to be created by _javascript_;
if I run it with _javascript_ disabled then it doesn't exist.
Apparently _javascript_ creates the box and then populates it
and accordingly removes stuff from "Available groups".
Therefore it could be an error in Django; maybe for some
reason that _javascript_ doesn't always run correctly on
Firefox.
  If I were you I'd file a Django bug anyway.
  
  Regards,
  Antonis
  
  
  
  
  
  On 13/04/2022 10.00, Mike
Dewhirst wrote:
  
  I
don't know how long this has been happening for me. 

Happens on Windows 10 in Mozilla Firefox but not Chrome. 

 In the Admin User screen where there are two boxes of
Groups labelled 'Available groups' and 'Chosen groups' with
controls to move groups between boxes, everything seems to
work perfectly - until I refresh the screen! 

On refresh, the Chosen groups box seems to slide across to
the left and drop all its groups into the Available box! It
quickly resumes its usual place on the right except that it
is completely empty. 

Shift refresh retrieves the data from the database and
everything is OK. 

The problem is that if an admin user accidentally saves
after a refresh, they save that profile with no permissions
and that user loses all access to their data. 

I have tested identically on four different Django projects
I look after with the same results. Django versions 3.2.12
and 3.2.13 running on Apache 2.4 on Ubuntu 20.04 and
localhost on Windows 10 with the dev server. Also happens on
Ubuntu 18.04 with nginx and running Mezzanine. 

Any ideas? Debug strategy? 

Not sure where to start. 

Seems like a Mozilla issue but I have been known to get
things wrong. Has anyone seen this? 

Thanks 

Mike 


  
  -- 
  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/92661660-a500-f625-ac9a-d1404f99cb3d%40antonischristofides.com.



Re: delete button

2022-04-14 Thread Antonis Christofides
Also thank you for informing me to include less. I put 3 files there because i 
thought someone would have needed it.
I wasn't clear enough. You should include the *entire code* that reproduces the 
problem. Remove stuff from your code until you can't remove any more, while the 
problem is still there.




On 14/04/2022 05.57, 'Delvin Alexander' via Django users wrote:

test func is a function that my 'User' passes tests mixins runs in django.

Also thank you for informing me to include less. I put 3 files there because i 
thought someone would have needed it.


On Tue, Apr 12, 2022 at 11:20 PM Antonis Christofides 
 wrote:


What is `test_func()`?

In addition, if you want people to help you, it would be a good idea to
help them by giving them the smallest possible amount of code that
reproduces the problem. (In fact, whenever I do that, in about 50% of
cases I solve the problem myself during the reduction process.)

Regards,

Antonis


On 13/04/2022 07.32, 'Delvin Alexander' via Django users wrote:


Hello everyone,

i am having trouble. i created a delete button but my page does not
confirm the deletion of the post, nor does it redirect to another page.
may someone help guide me on what it is i have done wrong and explain for
me please?

- I feel as though the problem could be located in my views.py but not sure


Here is my views.py:

*from django.shortcuts import render*
*from django.contrib.auth.mixins import LoginRequiredMixin,
UserPassesTestMixin*
*from django.views.generic import ListView, DetailView, CreateView,
UpdateView, DeleteView*
*from .models import Post*
*

*
*def home(request):*
*    context = {*
*        'posts': Post.objects.all()*
*    }*
*    return render(request, 'blog/home.html', context)*
*

*
*class PostListView(ListView):*
*    model = Post*
*    template_name = 'blog/home.html'*
*    context_object_name = 'posts'*
*    ordering = ['-date_posted']*
*

*
*class PostDetailView(DetailView):*
*    model = Post*
**
**
*class PostCreateView(LoginRequiredMixin, CreateView):*
*    model = Post*
*    fields = ['title', 'content']*
**
*    def form_valid(self, form):*
*        form.instance.author = self.request.user*
*        return super().form_valid(form)*
**
*class PostUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):*
*    model = Post*
*    fields = ['title', 'content']*
**
*    def form_valid(self, form):*
*        form.instance.author = self.request.user*
*        return super().form_valid(form)*
**
*    def test_func(self):*
*        post = self.get_object()*
*        if self.request.user == post.author:*
*            return True*
*        return False*
**
*class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):*
*    model = Post*
*    success_url = 'blog'*
**
*    def test_func(self):*
*        post = self.get_object()*
*        if self.request.user == post.author:*
*            return True*
*        return False*
*
*
*def about(request):*
*    return render(request, 'blog/about.html', {'title': 'About'})*
*
*
*
*
*
*
Here is my urls.py:

*from django.urls import path*
*from .views import PostListView, PostDetailView, PostCreateView,
PostUpdateView, PostDeleteView*
*from . import views*
*
*
*urlpatterns = [*
*    path('', PostListView.as_view(), name='blog-home'),*
*    path('post//', PostDetailView.as_view(), name='post-detail'),*
*    path('post/new/', PostCreateView.as_view(), name='post-create'),*
*    path('post//update/', PostUpdateView.as_view(),
name='post-update'),*
*    path('post//delete/', PostDeleteView.as_view(),
name='post-delete'),*
*    path('about/', views.about, name='blog-about'),*
*]*


And here is my post_confirm_delete.html:

*{% extends "blog/base.html" %}*
*{% block content %}*
*    *
*            {% csrf_token %}*
*            *
*                Delete Post*
*                Are you sure you want to delete this post? "{{
object.title }}"*
*            *
*            *
*                Yes, Delete*
*                http://object.id> %}">Cancel *
*            *
*        *
*     *
*{% endblock content %}*


-- 
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/3a23eabf-f8bd-4fa3-a27b-199a3aabf33bn%40googlegroups.com

<https://gro

Re: Possible Django Admin or auth bug or Mozilla bug

2022-04-13 Thread Antonis Christofides
It happens here as well as far as I can see (tested on a Debian 11 server 
running Django 3.2.12).


The "Chosen groups" box seems to be created by JavaScript; if I run it with 
JavaScript disabled then it doesn't exist. Apparently JavaScript creates the box 
and then populates it and accordingly removes stuff from "Available groups". 
Therefore it could be an error in Django; maybe for some reason that JavaScript 
doesn't always run correctly on Firefox.


If I were you I'd file a Django bug anyway.

Regards,

Antonis



On 13/04/2022 10.00, Mike Dewhirst wrote:

I don't know how long this has been happening for me.

Happens on Windows 10 in Mozilla Firefox but not Chrome.

 In the Admin User screen where there are two boxes of Groups labelled 
'Available groups' and 'Chosen groups' with controls to move groups between 
boxes, everything seems to work perfectly - until I refresh the screen!


On refresh, the Chosen groups box seems to slide across to the left and drop 
all its groups into the Available box! It quickly resumes its usual place on 
the right except that it is completely empty.


Shift refresh retrieves the data from the database and everything is OK.

The problem is that if an admin user accidentally saves after a refresh, they 
save that profile with no permissions and that user loses all access to their 
data.


I have tested identically on four different Django projects I look after with 
the same results. Django versions 3.2.12 and 3.2.13 running on Apache 2.4 on 
Ubuntu 20.04 and localhost on Windows 10 with the dev server. Also happens on 
Ubuntu 18.04 with nginx and running Mezzanine.


Any ideas? Debug strategy?

Not sure where to start.

Seems like a Mozilla issue but I have been known to get things wrong. Has 
anyone seen this?


Thanks

Mike




--
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/92661660-a500-f625-ac9a-d1404f99cb3d%40antonischristofides.com.


Re: delete button

2022-04-13 Thread Antonis Christofides

What is `test_func()`?

In addition, if you want people to help you, it would be a good idea to help 
them by giving them the smallest possible amount of code that reproduces the 
problem. (In fact, whenever I do that, in about 50% of cases I solve the problem 
myself during the reduction process.)


Regards,

Antonis


On 13/04/2022 07.32, 'Delvin Alexander' via Django users wrote:


Hello everyone,

i am having trouble. i created a delete button but my page does not confirm 
the deletion of the post, nor does it redirect to another page. may someone 
help guide me on what it is i have done wrong and explain for me please?


- I feel as though the problem could be located in my views.py but not sure


Here is my views.py:

*from django.shortcuts import render*
*from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin*
*from django.views.generic import ListView, DetailView, CreateView, 
UpdateView, DeleteView*

*from .models import Post*
*

*
*def home(request):*
*    context = {*
*        'posts': Post.objects.all()*
*    }*
*    return render(request, 'blog/home.html', context)*
*

*
*class PostListView(ListView):*
*    model = Post*
*    template_name = 'blog/home.html'*
*    context_object_name = 'posts'*
*    ordering = ['-date_posted']*
*

*
*class PostDetailView(DetailView):*
*    model = Post*
**
**
*class PostCreateView(LoginRequiredMixin, CreateView):*
*    model = Post*
*    fields = ['title', 'content']*
**
*    def form_valid(self, form):*
*        form.instance.author = self.request.user*
*        return super().form_valid(form)*
**
*class PostUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):*
*    model = Post*
*    fields = ['title', 'content']*
**
*    def form_valid(self, form):*
*        form.instance.author = self.request.user*
*        return super().form_valid(form)*
**
*    def test_func(self):*
*        post = self.get_object()*
*        if self.request.user == post.author:*
*            return True*
*        return False*
**
*class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):*
*    model = Post*
*    success_url = 'blog'*
**
*    def test_func(self):*
*        post = self.get_object()*
*        if self.request.user == post.author:*
*            return True*
*        return False*
*
*
*def about(request):*
*    return render(request, 'blog/about.html', {'title': 'About'})*
*
*
*
*
*
*
Here is my urls.py:

*from django.urls import path*
*from .views import PostListView, PostDetailView, PostCreateView, 
PostUpdateView, PostDeleteView*

*from . import views*
*
*
*urlpatterns = [*
*    path('', PostListView.as_view(), name='blog-home'),*
*    path('post//', PostDetailView.as_view(), name='post-detail'),*
*    path('post/new/', PostCreateView.as_view(), name='post-create'),*
*    path('post//update/', PostUpdateView.as_view(), 
name='post-update'),*
*    path('post//delete/', PostDeleteView.as_view(), 
name='post-delete'),*
*    path('about/', views.about, name='blog-about'),*
*]*


And here is my post_confirm_delete.html:

*{% extends "blog/base.html" %}*
*{% block content %}*
*    *
*            {% csrf_token %}*
*            *
*                Delete Post*
*                Are you sure you want to delete this post? "{{ 
object.title }}"*

*            *
*            *
*                Yes, 
Delete*
*                Cancel *

*            *
*        *
*     *
*{% endblock content %}*


--
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/3a23eabf-f8bd-4fa3-a27b-199a3aabf33bn%40googlegroups.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/b1d616eb-7460-8263-f1ad-74efb59c64d8%40antonischristofides.com.


Re: sort by alphabet

2022-04-11 Thread Antonis Christofides

Please read the documentation of order_by(). It tells you how you can do this.


On 11/04/2022 20.15, divya murugulla wrote:


that is not working since my sort function is of different table

On Monday, April 11, 2022 at 10:44:14 PM UTC+5:30 Antonis Christofides wrote:

Same thing, use
CommodityLocatinoXref.objects.select_related(...).filter(...).order_by(...)



On 11/04/2022 20.03, divya murugulla wrote:


latamSupplyPoints = [ (e.globe_code_id, e.globe_code.plant_name) for e in

CommodityLocationXref.objects.select_related('globe_code','cmdty_loc').filter(cmdty_loc_id__in=LatamLocationIds)
]

how to sort these values

On Monday, April 11, 2022 at 10:00:50 PM UTC+5:30 Antonis Christofides 
wrote:

Hi,

You need to replace

queryset=GlobePlant.objects.all()

with

queryset=GlobePlant.objects.all().order_by(...)

I can't tell you what arguments to give "order_by()" without seeing
your GlobePlant model, but if you read Django's documentation for
order_by you should be able to determine that.

Regards,

Antonis


On 11/04/2022 18.47, divya murugulla wrote:


Please help me sort the queryset by name alphabetical order.

 plant = forms.ModelChoiceField(label='Destinations
Name',queryset=GlobePlant.objects.all(),empty_label='Select the
Point',required=True)

Thanks & Regards,
Divya
-- 
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 view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/56143c58-7525-4cab-959b-acf79b50a7dbn%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/56143c58-7525-4cab-959b-acf79b50a7dbn%40googlegroups.com?utm_medium=email_source=footer>.


-- 
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 view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/743aaa4c-f709-424a-adfc-cd60b72f4644n%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/743aaa4c-f709-424a-adfc-cd60b72f4644n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/bf0dfe11-a8a0-4265-a698-3010730de403n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/bf0dfe11-a8a0-4265-a698-3010730de403n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/5fd0dffc-0457-717b-007f-cb06c9fb8f17%40antonischristofides.com.


Re: sort by alphabet

2022-04-11 Thread Antonis Christofides
Same thing, use 
CommodityLocatinoXref.objects.select_related(...).filter(...).order_by(...)




On 11/04/2022 20.03, divya murugulla wrote:

latamSupplyPoints = [ (e.globe_code_id, e.globe_code.plant_name) for e in 
CommodityLocationXref.objects.select_related('globe_code','cmdty_loc').filter(cmdty_loc_id__in=LatamLocationIds) 
]


how to sort these values

On Monday, April 11, 2022 at 10:00:50 PM UTC+5:30 Antonis Christofides wrote:

Hi,

You need to replace

queryset=GlobePlant.objects.all()

with

queryset=GlobePlant.objects.all().order_by(...)

I can't tell you what arguments to give "order_by()" without seeing your
GlobePlant model, but if you read Django's documentation for order_by you
should be able to determine that.

Regards,

Antonis


On 11/04/2022 18.47, divya murugulla wrote:


Please help me sort the queryset by name alphabetical order.

 plant = forms.ModelChoiceField(label='Destinations
Name',queryset=GlobePlant.objects.all(),empty_label='Select the
Point',required=True)

Thanks & Regards,
Divya
-- 
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 view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/56143c58-7525-4cab-959b-acf79b50a7dbn%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/56143c58-7525-4cab-959b-acf79b50a7dbn%40googlegroups.com?utm_medium=email_source=footer>.


--
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/743aaa4c-f709-424a-adfc-cd60b72f4644n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/743aaa4c-f709-424a-adfc-cd60b72f4644n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/4c935aa8-45dc-1d2e-c333-72b6c1540af3%40antonischristofides.com.


Re: sort by alphabet

2022-04-11 Thread Antonis Christofides

Hi,

You need to replace

queryset=GlobePlant.objects.all()

with

queryset=GlobePlant.objects.all().order_by(...)

I can't tell you what arguments to give "order_by()" without seeing your 
GlobePlant model, but if you read Django's documentation for order_by you should 
be able to determine that.


Regards,

Antonis


On 11/04/2022 18.47, divya murugulla wrote:


Please help me sort the queryset by name alphabetical order.

 plant = forms.ModelChoiceField(label='Destinations 
Name',queryset=GlobePlant.objects.all(),empty_label='Select the 
Point',required=True)


Thanks & Regards,
Divya
--
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/56143c58-7525-4cab-959b-acf79b50a7dbn%40googlegroups.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/7f79a9ca-6457-3500-6182-943048078ad5%40antonischristofides.com.


Re: Calculated Fields

2022-04-11 Thread Antonis Christofides
As was found out with the conversation with Mike Dewhirst, the error appears to 
be because of wrong understanding of operator precedence 
. 
That's easy to correct with parentheses.


Except for that, I wouldn't do it that way; I wouldn't store the total price in 
the database, because it's likely to create problems. Models that have not (yet) 
been saved to the database will not have a total price. Models that have been 
loaded from the database, modified, but not (yet) updated in the database will 
have a wrong total price. Saving to the database with bulk operations or with 
plain SQL may result in no total price. These are all symptoms of storing 
redundant information in the database, which is something that should be avoided.


Instead, I would do this:

class Stock(models.Model):
    unit_price = models.DecimalField(max_digits=10, decimal_places=2, 
default='0', blank=True, null=True)

    quantity = models.IntegerField(default='0', blank=True, null=True)
    reorder_level = models.IntegerField(default='0', blank=True, null=True)

    @property
    def total_price(self):
    return (self.quantity + self.reorder_level) * self.unit_price



On 10/04/2022 20.49, tech george wrote:


Hello,

I am trying to calculate fields directly from a model but no luck. I want to 
get total_price from quantity, reoder_level and unit price. My code is abelow, 
Please advise.


class Stock(models.Model):
    unit_price = models.DecimalField(max_digits=10, decimal_places=2, 
default='0', blank=True, null=True)

    quantity = models.IntegerField(default='0', blank=True, null=True)
    total_price = models.DecimalField(max_digits=10, decimal_places=2,default=1)
    reorder_level = models.IntegerField(default='0', blank=True, null=True)


    def save(self, *args, **kwargs):
        self.total_price = self.quantity + self.reorder_level * self.unit_price
        super(Stock, self).save(*args, **kwargs)


What am i my doing wrong

Regards,

--
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/CADYG20HBcMMGq6QodO0v%2BeZVmfS%2Bmr4aCSro5FZeeRLFdQztnQ%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/8efea23c-52d8-6ac1-b94e-3cb9ad46d086%40antonischristofides.com.


Re: Error during template rendering

2022-04-10 Thread Antonis Christofides

Hi!

The error message 'relation "curriculum_standard" does not exist' has been 
produced by PostgreSQL, and Django merely repeats it. In other words, Django is 
telling you that while it was doing what it was doing, an error occurred in the 
RDBMS, and it is showing you the error message that the RDBMS returned.


People who, unlike me, have studied relational calculus often use the word 
"relation" for what I call a "table". I don't know why. I once picked up a 
relational calculus book to take a look, but it was too heavy for my taste :-) 
(If someone can explain in simple terms I'm eager to read.) So the system is 
telling you that table "curriculum_standard" does not exist.


This probably means that you need to run "python manage.py migrate".

Regards,

Antonis



On 09/04/2022 21.41, emmanuel odor wrote:


Hello group,

I hosted this app on Heroku and i am getting this error. find the attached 
below. It is working well on my local host...
ProgrammingError at /relation "curriculum_standard" does not exist LINE 1: 
"slug", "curriculum_standard"."description" FROM "curriculu... ^

Request Method:
GET
Request URL:
https://insightskillz8.herokuapp.com/
Django Version:
3.2
Exception Type:
ProgrammingError
Exception Value:
relation "curriculum_standard" does not exist LINE 1: "slug", 
"curriculum_standard"."description" FROM "curriculu... ^

Exception Location:
/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py, 
line 84, in _execute

Python Executable:
/app/.heroku/python/bin/python
Python Version:
3.9.11
Python Path:
['/app/.heroku/python/bin', '/app', '/app/.heroku/python/lib/python39.zip', 
'/app/.heroku/python/lib/python3.9', 
'/app/.heroku/python/lib/python3.9/lib-dynload', 
'/app/.heroku/python/lib/python3.9/site-packages']

Server time:
Sat, 09 Apr 2022 18:32:20 +
Error during template rendering

In template /app/templates/base.html, error at line *42*

relation "curriculum_standard" does not exist LINE 1: "slug", 
"curriculum_standard"."description" FROM "curriculu... ^

--
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/0143d604-a9e7-4fd8-9586-f9c8e8785c8en%40googlegroups.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/db64f9a9-512c-6bd5-b7e5-9014ab884b4e%40antonischristofides.com.


Re: Django Foreign key field require dependent on another datetime field

2022-04-09 Thread Antonis Christofides

Hi,

you can override the model's save() method 
. 
It's something that should be done in the backend. Relying on the front end is a 
bad idea, because then errors in the front end would lead to inconsistencies in 
the database. In the future you might have more than one front end (e.g. a 
mobile app), or something else using the API might be in error. So things that 
have to do with data integrity should be taken care of in the backend.


Regards,

Antonis



On 09/04/2022 11.19, Mehedi Hasan Tayef wrote:

I want to create a *Foreign key *which is *require if another datetime value 
is greater than any year* (like 2014). How can I create that on Django Models. 
Or I should do that in frontend. (I will use rest framework)

--
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/422fbc6d-1424-424d-8f20-d9e08e19e773n%40googlegroups.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/c2f85573-b2a7-80a6-2d5d-cbd0f4d13ff7%40antonischristofides.com.


Re: NameError:

2022-04-08 Thread Antonis Christofides
Hi! In the line where the error occurs, Pharmacist has not been defined yet. 
Move your Pharmacist model before your Patients model.


Regards,

Antonis


On 08/04/2022 20.49, tech george wrote:


Hello,

I've been struggling with the below error, what might be the problem?

I have used the same ForeignKey in other models.. all works ok, except this.

Please advise.

*Models:*

class CustomUser(AbstractUser):
    user_type_data = ((1, "AdminHOD"), (2, "Pharmacist"), (3, "Doctor"), (4, 
"PharmacyClerk"),(5, "Patients"))

    user_type = models.CharField(default=1, choices=user_type_data, 
max_length=10)



class Patients(models.Model):
    gender_category=(
        ('Male','Male'),
        ('Female','Female'),
    )

nurse = models.ForeignKey(Pharmacist, related_name='Pharmacist', 
on_delete=models.CASCADE, null=True)

    admin = models.OneToOneField(CustomUser,null=True, on_delete = 
models.CASCADE)
reg_no=models.CharField(max_length=30,null=True,blank=True,unique=True)
gender=models.CharField(max_length=7,null=True,blank=True,choices=gender_category)
first_name=models.CharField(max_length=20,null=True,blank=True)
last_name=models.CharField(max_length=20,null=True,blank=True)
    date_admitted=models.DateTimeField(auto_now_add=True, auto_now=False)
    last_updated = models.DateTimeField(auto_now_add=False, auto_now=True)

    def __str__(self):
        return str(self.admin)


*Error:*

nurse = models.ForeignKey(Pharmacist, related_name='Pharmacist', 
on_delete=models.CASCADE, null=True)

NameError: name 'Pharmacist' is not defined


Regards,




--
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/CADYG20GbMnoGjkT7VtD1FFMw3Tr8Axaepnf27vDyvqYvMb%2BUiQ%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/6f64f27c-ec8c-da80-5878-5520c7017b35%40antonischristofides.com.


Re: Django 1.5 app had subclasses without tables without proxy and now 1.6 won't sync with proxy

2022-04-04 Thread Antonis Christofides
This looks strange, although I'm not familiar with exactly this particular use 
case. I'm assuming you are referring to multi-table inheritance. Are you certain 
Django 1.5 wasn't creating these tables? Was it using migrations or South maybe? 
(Obviously I don't remember when Django started supporting migrations.) When you 
say it tries to query these tables, when does it attempt to do so? Could you 
post an example of a subclasss, preferably with its base class?




On 04/04/2022 09.09, John Abraham wrote:

Hello. We're migrating someone else's app that was at Django 1.5.12 and we're 
trying to bring it more up-to-date, step-by-step, starting with Django 1.6.11.


There's an odd thing. There were a bunch of subclasses of a Model class, that 
didn't have any database fields. Django wasn't creating nor using tables for 
them at 1.5.12. But, Django 1.6.11 keeps trying to query these non-existent 
tables for these subclasses, expecting them to have a single field which would 
just be the pointer to their superclass.


It seems the proper way to tell Django not to use tables for a class is to set:

class Meta:
proxy = True

But if we put this in, then when we run syncdb it strangly tries to query the 
base classes before any tables are created at all in the database.


Any old-timers run into anything like this? Did Django 1.5 not need the proxy 
= True in the meta to avoid creating tables for subclasses of Models that 
didn't add any fields?


They are using InheritanceManager from django_model_utils.

Thanks for any help! Banging our heads against the wall on this one for quite 
a while now...

--
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/45eec62d-a27c-4b5e-b8ff-6fc2981efa17n%40googlegroups.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/e18bf6d7-e384-8a10-91dc-55246488e938%40antonischristofides.com.


Re: Is Overriding widget templates buggy?

2022-04-03 Thread Antonis Christofides

Hi,

I'm not really an expert in that part. From what I can read in the 
documentation, TemplatesSetting isn't a template backend, so why do you think 
you can specify it in TEMPLATES[x]['BACKEND']? It appears to be a form renderer, 
which means you can specify it in FORM_RENDERER.


But of course I may have understood something wrong myself.

Regards,

Antonis



On 03/04/2022 20.56, run_the_race wrote:

I was going to report a bug, but the guide recommends asking here first.

While trying to override a built in widget template (still stuck on it here: 
https://forum.djangoproject.com/t/overriding-widgets-templates-not-working-following-help-template-loader-not-searching-app-dirs/12974), 
I came across this weird behavoir:


In `django/forms/renderers.py` line 59 it has:
```
class TemplatesSetting(BaseRenderer):
    """
    Load templates using template.loader.get_template() which is configured
    based on settings.TEMPLATES.
    """
    def get_template(self, template_name):
        return get_template(template_name)
```
However a new project with:
```
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
            ],
        },
    },
    {
        'BACKEND': 'django.forms.renderers.TemplatesSetting',
        'DIRS': ['/my/overide/dir/path',],
        'APP_DIRS': False,
    },
]
```

Generates the error:
```

Traceback (most recent call last):
  File 
"/home/michael/.venv/project/lib/python3.8/site-packages/django/template/utils.py", 
line 66, in __getitem__

    return self._engines[alias]
KeyError: 'renderers'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/michael/project/src/manage.py", line 16, in 
    execute_from_command_line(sys.argv)
  File 
"/home/michael/.venv/project/lib/python3.8/site-packages/django/core/management/__init__.py", 
line 425, in execute_from_command_line

    utility.execute()
  File 
"/home/michael/.venv/project/lib/python3.8/site-packages/django/core/management/__init__.py", 
line 419, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/home/michael/.venv/project/lib/python3.8/site-packages/django/core/management/base.py", 
line 373, in run_from_argv

    self.execute(*args, **cmd_options)
  File 
"/home/michael/.venv/project/lib/python3.8/site-packages/django/core/management/base.py", 
line 417, in execute

    output = self.handle(*args, **options)
  File 
"/home/michael/.venv/project/lib/python3.8/site-packages/django/core/management/commands/check.py", 
line 63, in handle

    self.check(
  File 
"/home/michael/.venv/project/lib/python3.8/site-packages/django/core/management/base.py", 
line 438, in check

    all_issues = checks.run_checks(
  File 
"/home/michael/.venv/project/lib/python3.8/site-packages/django/core/checks/registry.py", 
line 77, in run_checks

    new_errors = check(app_configs=app_configs, databases=databases)
  File 
"/home/michael/.venv/project/lib/python3.8/site-packages/django/contrib/admin/checks.py", 
line 78, in check_dependencies

    for engine in engines.all():
  File 
"/home/michael/.venv/project/lib/python3.8/site-packages/django/template/utils.py", 
line 90, in all

    return [self[alias] for alias in self]
  File 
"/home/michael/.venv/project/lib/python3.8/site-packages/django/template/utils.py", 
line 90, in 

    return [self[alias] for alias in self]
  File 
"/home/michael/.venv/project/lib/python3.8/site-packages/django/template/utils.py", 
line 81, in __getitem__

    engine = engine_cls(params)
TypeError: TemplatesSetting() takes no arguments
```

How does one configure `django.forms.renderers.TemplatesSetting` without it 
throwing an error?

--
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/2b5182cf-cef1-463b-bb6a-2fb96b893b56n%40googlegroups.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/77d0dd37-b0bb-ec64-cc05-a59712a3a54d%40antonischristofides.com.


Re: django.db.utils.OperationalError: index row requires 45344 bytes, maximum size is 8191

2022-04-02 Thread Antonis Christofides
Sorry, which model is causing the problem? Which is the model that started 
giving you errors when you added the Meta?


Antonis Christofides
+30-6979924665 (mobile)



On 02/04/2022 15.00, Sunday Ajayi wrote:

Hi Antonis below is my model definition:


from django.db import models
from authentication.models import User,Business
import cloudinary
from cloudinary.models import CloudinaryField
from django.core.paginator import 
Paginator,EmptyPage,PageNotAnInteger,InvalidPage
from rest_framework.pagination import PageNumberPagination
from django.contrib.postgres.fields import ArrayField
# Create your models here.
DATA_PER_PAGE =10
class Category(models.Model):
TYPE = (
('custom','custom'),
('non-custom','non-custom')
)
STATE = (
('untrained','Untrained'),
('in-progress','Training in Progress'),
('more-training','More Training Needed'),
('trained','Trained')
)
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=255, blank=True,null=True)
slug = models.CharField(max_length=20,null=True,blank=True)
category_type = 
models.CharField(max_length=20,choices=TYPE,default='non-custom',null=True,blank=True)

description = models.TextField(blank=True,null=True)
business = models.ForeignKey(Business, 
on_delete=models.DO_NOTHING,null=True,blank=True)
image = 
models.ImageField(upload_to='category',null=True,blank=True,default='/media/category/unnamed-5.png')

extracted_data = models.JSONField(blank=True,null=True)
state = 
models.CharField(max_length=20,choices=STATE,default='untrained',null=True,blank=True)

training_status = models.BooleanField(default=False,null=True,blank=True)
f1_score = models.FloatField(null=True,blank=True)
accuracy = models.FloatField(null=True,blank=True)
progessive_training_file = models.TextField(null=True, blank=True)
created_date = models.DateField(auto_now_add=True)
created_time = models.TimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
created_by = models.ForeignKey(User, 
on_delete=models.DO_NOTHING,null=True,blank=True,related_name='user_cat')

def __str__(self) -> str:
return self.name
class Batch(models.Model):
id = models.AutoField(primary_key=True)
description = models.TextField(blank=True,null=True)
business = models.ForeignKey(Business, 
on_delete=models.DO_NOTHING,null=True,blank=True)
category = models.ForeignKey(Category,on_delete=models.DO_NOTHING, 
null=True,blank=True)

counts = models.BigIntegerField(null=True, blank=True)
created_date = models.DateField(auto_now_add=True)
created_time = models.TimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
created_by = models.ForeignKey(User, on_delete=models.DO_NOTHING, 
null=True,blank=True,related_name='user_batch')

def __str__(self) -> str:
return str(self.id)
class Custom_model_extract(models.Model):
id = models.AutoField(primary_key=True)
title = models.CharField(max_length=255, null=True,blank=True)
batch = models.BigIntegerField(null=True,blank=True)
category = models.ForeignKey(Category,on_delete=models.DO_NOTHING, 
null=True,blank=True)

image_extract = models.FileField(upload_to='custom_data',blank=True,null=True)
transcribed_data = models.JSONField(null=True,blank=True)
label_data = models.JSONField(null=True,blank=True)
extracted_json = models.JSONField(blank=True,null=True)
business = models.ForeignKey(Business, 
on_delete=models.DO_NOTHING,null=True,blank=True,related_name='bus_extracted')
created_by = models.ForeignKey(User, on_delete=models.DO_NOTHING, 
null=True,blank=True,related_name='user_extracted')

created_date = models.DateField(auto_now_add=True)
created_time = models.TimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self) -> str:
return self.name
class Training_model_data(models.Model):
id = models.AutoField(primary_key=True)
category = models.ForeignKey(Category,on_delete=models.DO_NOTHING, 
null=True,blank=True)

# image_extract = 
models.FileField(upload_to='training_data',blank=True,null=True)
image_extract = models.TextField(blank=True,null=True)
transcribed_data = models.JSONField(null=True,blank=True)
label_data = models.JSONField(null=True,blank=True)
business = models.ForeignKey(Business, 
on_delete=models.DO_NOTHING,null=True,blank=True,related_name='training_bus_extracted')
created_by = models.ForeignKey(User, on_delete=models.DO_NOTHING, 
null=True,blank=True,related_name='trainng_user_extracted')

created_date = models.DateField(auto_now_add=True)
created_time = models.TimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self) -> str:
return self.name
class PostManager(models.Manager):
def get_paginated_posts(self, user=None):
if user:
posts = super(PostManager, self).filter()
else:
posts = super(PostManager, self).filter()
return Paginator(posts, DATA_PER_PAGE)
class Epassport(models.Model):
id = models.AutoField(primary_key=True)
fullname = models.CharField(max_length=255, null=True,blank=True)
batch = models.BigIntegerFie

Re: django.db.utils.OperationalError: index row requires 45344 bytes, maximum size is 8191

2022-04-01 Thread Antonis Christofides

Hi,

could you show the definition of your model?

Antonis Christofides
+30-6979924665 (mobile)



On 02/04/2022 00.43, Sunday Ajayi wrote:

Hi Team,


Please I am having the error below from django - postgresql:

django.db.utils.OperationalError: index row requires 45344 bytes, maximum size 
is 8191



Please how can I fix it?

Regards,
*AJAYI Sunday *
(+234) 806 771 5394
/sunnexaj...@gmail.co <mailto:sunnexaj...@gmail.com>m/
--
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/CAKYSAw2o5TD2katq07Np2zdKs1yDMd%3D_UCnp0Ly2vMpV7h1p-w%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAKYSAw2o5TD2katq07Np2zdKs1yDMd%3D_UCnp0Ly2vMpV7h1p-w%40mail.gmail.com?utm_medium=email_source=footer>.


--
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/d65d443e-6eeb-1daf-590b-1cc29445ba59%40antonischristofides.com.


Re: Difference in datetime with timezone

2022-03-30 Thread Antonis Christofides

Hi,

not what you asked, but

    from settings import TIME_ZONE

is an error. It happens to work in this case, but generally you should write

    from django.conf import settings

and then use "settings.TIME_ZONE". In Django, "settings" isn't a module, it's an 
object. Django has some logic when populating that object with attributes. An 
obvious example is that you can django the DJANGO_SETTINGS_MODULES environment 
variable to specify a different settings file.


Now, regarding what you asked, the pytz documentation has the following warning:

   Unfortunately using the tzinfo argument of the standard datetime
   constructors ‘’does not work’’ with pytz for many timezones.

I don't remember the correct way to do it, since I'm always confused by how pytz 
works, and also its usage is deprecated because of the existence of the new 
"zoneinfo" Python standard library module.


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 29/03/2022 17.51, Andrés Alvarez wrote:
I need to save some fields in my database in the format YYY-MM-MM 00:00:00+00. 
So I decide to do this:


# setting.py
TIME_ZONE = 'America/Mexico_City'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# models.py
class Program(models.Model):
    objects = models.Manager()
    objects_custom = ProgramManager()
    class Meta:
        ordering = ['id']
    name = models.CharField(max_length=100, null=False)
    program_budget = models.CharField(max_length=100, null=False)
    company = models.ForeignKey(Company, on_delete=models.CASCADE, null=True)
    active = models.BooleanField(default=True)
    uuid4 = models.CharField(max_length=50, unique=True, null=True)
    country_list = models.TextField(null=True)
    method_payment = models.CharField(max_length=100, null=True)
    currency = models.CharField(max_length=4, default='USD', null=True)
    create_at = models.DateTimeField(auto_now_add=True, null=True)
    discharge_program = models.DateTimeField(auto_now_add=True, null=True)
    updated_at = models.DateTimeField(auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    is_saved = models.NullBooleanField(default=False, null=True, blank=True)
    is_suspended = models.BooleanField(default=False)
    start_at = models.DateTimeField(null=True)
    finish_at = models.DateTimeField(null=True)

# utils.py
from datetime import datetime, time
import pytz
from settings.py import TIME_ZONE
def get_start_at(date):
    """Obtain the current day initialize in the first second of the day.
    Parameters:
        date (date): date object

    Returns:
        (datetime): -MM-DD 00:00:00
    """
    return datetime.combine(date, time.min, pytz.timezone(TIME_ZONE))


Here are my values to create the register:
{
    'has_individual_budget': False,
    'name': 'plan test create program start_at datetime',
    'program_budget': '0',
    'uuid4', 'd6effacf-3c19-48db-ab06-5af1d97df599',
     'country_list': 
'[{"id":239,"name":"Venezuela","iso_code2":"VE","iso_code3":"VEN","phone_prefix":58,"currency":"VEF","flag":"U+1F1FB 
U+1F1EA","phone_national_regex":"^[68]00d{7}|(?:[24]d|[59]0)d{8}$","active":1}]', 


    'method_payment': '7fb39a7e-a6de-488b-9564-9bd853b598ec',
    'currency': 'USD',
    'is_saved': False,
    'start_at': datetime.datetime(2022, 3, 28, 0, 0, tzinfo='America/Mexico_City' LMT-1 day, 17:23:00 STD>),
    'finish_at': datetime.datetime(2022, 4, 27, 23, 59, 59, 99, 
tzinfo=),

    'company': ,
    'card_provider': ,
    'payment_provider': 
}

as you can see the field 'start_at' is the datetime that I want to store in 
the database, but when I look the insert query:

{
    'sql': """
         INSERT INTO "user_program"
             (
                 "name",
                 "program_budget",
                 "company_id",
                 "active",
                 "uuid4",
                 "country_list",
                 "method_payment",
                 "currency",
                 "create_at",
                 "discharge_program",
                 "updated_at",
                 "deleted_at",
                 "is_saved",
                 "is_suspended",
                 "start_at",
                 "finish_at",
                 "has_individual_budget",
                 "card_provider_id",
                 "payment_provider_id"
             )
        VALUES
            (
                \'plan test create program start_at datetime\',
                \'0\',
                247,
                true,
\'d6effacf-3c19-48db-ab06-5af1d97df599\',
\'[{"id":239,"

Re: Difference in datetime with timezone

2022-03-28 Thread Antonis Christofides

Hello,

1. Please copy your code exactly. Is it really "pytz.timezone(TIME_ZONE)"? Or
   is it "pytz.timezone(*settings.*TIME_ZONE)"? If it is the first one, please
   include the definition or importing of TIME_ZONE.
2. Please pretty-print your dictionary. You can use pprint for that. If it
   doesn't work on OrderedDicts, convert it to a simple dictionary before
   pretty printing.
3. Likewise, do something so that your SQL statement is more readable, such as
   manually inserting newlines and indents.

Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 28/03/2022 22.02, Andrés Alvarez wrote:
I need to save some fields in my database in the format YYY-MM-MM 00:00:00+00. 
So I decide to do this:

field_to_save = datetime.combine(date_to_save, time.min, 
pytz.timezone(TIME_ZONE))
in settings.py I have:
TIME_ZONE = 'America/Mexico_City'
USE_I18N = True
USE_L10N = True
USE_TZ = True

My model:
class Program(models.Model):
    objects = models.Manager()
    objects_custom = ProgramManager()
    class Meta:
        ordering = ['id']
    # ... others fields
    start_at = models.DateTimeField(null=True)
    finish_at = models.DateTimeField(null=True)

Here are my values to create the register:
OrderedDict([('has_individual_budget', False), ('name', 'plan test create 
program start_at datetime'), ('program_budget', '0'), ('uuid4', 
'd6effacf-3c19-48db-ab06-5af1d97df599'), ('country_list', 
'[{"id":239,"name":"Venezuela","iso_code2":"VE","iso_code3":"VEN","phone_prefix":58,"currency":"VEF","flag":"U+1F1FB 
U+1F1EA","phone_national_regex":"^[68]00d{7}|(?:[24]d|[59]0)d{8}$","active":1}]'), 
('method_payment', '7fb39a7e-a6de-488b-9564-9bd853b598ec'), ('currency', 
'USD'), ('is_saved', False), ('start_at', datetime.datetime(2022, 3, 28, 0, 0, 
tzinfo=)), 
('finish_at', datetime.datetime(2022, 4, 27, 23, 59, 59, 99, 
tzinfo=)), 
('company', ), ('card_provider', stripe-usa>), ('payment_provider', )])
as you can see the field 'start_at' is the datetime that I want to store in 
the database, but when I look the insert query:
{'sql': 'INSERT INTO "user_program" ("name", "program_budget", "company_id", 
"active", "uuid4", "country_list", "method_payment", "currency", "create_at", 
"discharge_program", "updated_at", "deleted_at", "is_saved", "is_suspended", 
"start_at", "finish_at", "has_individual_budget", "card_provider_id", 
"payment_provider_id") VALUES (\'plan test create program start_at datetime\', 
\'0\', 247, true, \'d6effacf-3c19-48db-ab06-5af1d97df599\', 
\'[{"id":239,"name":"Venezuela","iso_code2":"VE","iso_code3":"VEN","phone_prefix":58,"currency":"VEF","flag":"U+1F1FB 
U+1F1EA","phone_national_regex":"^[68]00d{7}|(?:[24]d|[59]0)d{8}$","active":1}]\', 
\'7fb39a7e-a6de-488b-9564-9bd853b598ec\', \'USD\', 
\'2022-03-28T18:47:10.865801+00:00\'::timestamptz, 
\'2022-03-28T18:47:10.865870+00:00\'::timestamptz, 
\'2022-03-28T18:47:10.865913+00:00\'::timestamptz, NULL, false, false, 
\'2022-03-28T00:00:00-06:37\'::timestamptz, 
\'2022-04-27T23:59:59.99-06:37\'::timestamptz, false, 1, 1) RETURNING 
"user_program"."id"', 'time': '0.267'}

the timezone part is -06:37 should be only -06.
Plase tell me how to fix that, if I need to change the TIME_ZONE or something.

Regards, Andres.

--
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/1999ec1e-9170-432e-adc0-71cab3dece6an%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/1999ec1e-9170-432e-adc0-71cab3dece6an%40googlegroups.com?utm_medium=email_source=footer>.


--
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/9f518ac9-3b8e-5bc5-fae2-c65ebd00d6c6%40antonischristofides.com.


Re: Question regarding adding language support to webapp based on Django

2022-03-28 Thread Antonis Christofides

Hello,

I'm not really an expert, but I'm replying since no-one else did.

If the user request the translation zh-hk and a string isn't available, then I 
think that it will fallback on another zh-, but I don't know which (but I think 
you only have zh-hant, so presumably that will be it). Even if that isn't 
working as I think it is, you could possibly copy the translation for zh-hant as 
zh-hk and change the strings you want to change in the copy. This would have the 
problem that you wouldn't automatically get updated translations from zh-hant 
into zh-hk, but it would work alright.


I think it would be better just to experiment and see what it does.

Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)



On 23/03/2022 08.32, Guan Zhang wrote:


Hi all:

I'm trying to help the developer of a Django-based webapp with adding 
additional language support and have some quick questions regarding how it works.


The website initially only had Japanese text but now includes English 
translations. We would like to add Chinese as well but not just Traditional 
(zh-hant) and Simplified Chinese (zh-hans) but something more specific like 
Hong Kong Chinese (zh-hk).


You'll have to excuse me since I'm not really a Django developer myself but I 
did try to read as much as possible regarding how Internationalization and 
Localization works but from my understanding, 
https://github.com/django/django/blob/main/django/conf/global_settings.py provides 
languages that Django provides translations for, out of the box, but it's 
possible to add your own language (in this case zh-hk). We don't really want 
to re-translate everything or make the code overly complex and honestly most 
of the text should be the same as zh-hant but we just want to provide some 
exceptions. Is it possible to just include certain text in zh-hk and the rest 
just let it fall back to zh-hant?


Please feel free to point me to some other documentations or even examples 
that deals with this specifically, I will gladly review those.


Oh in case anybody is interested, this is the webapp in question:

https://gundam-data.herokuapp.com/uce/

We are currently managing the text to be translated via a Google Sheet and 
once we've gotten everything we will get it compiled and pushed out to the webapp.


Thanks in advance for any tips/feedback on this!

--
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/b628cc82-c794-414e-bf88-7155ead2b52cn%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/b628cc82-c794-414e-bf88-7155ead2b52cn%40googlegroups.com?utm_medium=email_source=footer>.


--
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/1ab5cbaa-4b44-c5e8-3967-8adfa65ff650%40antonischristofides.com.


Re: Supertypes, subtypes and authentication

2022-03-22 Thread Antonis Christofides

Hello,

Could you explain a few things? A node is the superclass of organization, person 
and thing? Could you give an example of an organization and of a thing that can 
or create an article? What would be a better name for test_func? Could it be 
named is_authorized for example? What does get_object do? What is an "object"? 
What would be a better name for "UserPassesTestMixin"? Maybe "UserIsAuthorized"?


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 22/03/2022 14.49, 'AnneVerm' via Django users wrote:
I'm working on a web aplication in which I have a supertype node which is 
subtyped by organization, person and thing. Nodes can have permission to 
create/update/delete addresses, events, articles, pages etc. which all have a 
foreignkey referencing node.


I'm struggling with the authentication and authorization. If I add a node to 
the user I could use UserPassesTestMixin like this:


def test_func(self):
    obj = self.get_object()
    return obj.node == self.request.node

However, the consequence is that every node is related to a user one-to-one, 
which in case of things is not ideal.


I hope someone could point me in the right direction to solve this problem.

Kind regards,

Anne
--
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/03685bda-5257-42e0-88ef-1973de3411dfn%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/03685bda-5257-42e0-88ef-1973de3411dfn%40googlegroups.com?utm_medium=email_source=footer>.


--
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/4da06770-1478-6cbe-379a-9f268b85582b%40antonischristofides.com.


Re: runserver not working

2022-03-22 Thread Antonis Christofides

What Visual Studio shows you is the content of the file "manage.py".

Apparently when you enter "manage.py [whatever]", Windows understands that you 
want to open the file "manage.py", and it thinks that Visual Studio is the 
program with which such files should be opened.


Try "python manage.py runserver" instead.

Antonis Christofides
+30-6979924665 (mobile)



On 22/03/2022 07.07, 'Delvin Alexander' via Django users wrote:

would anyone know why my "manage.py runserver" is not working?

Every time i try running it on the command prompt, i get relocated to my 
visual studio of manage.py file that states this:


#*!/usr/bin/env python*
*"""Django's command-line utility for administrative tasks."""*
*import os*
*import sys*
**
*def main():*
*    """Run administrative tasks."""*
*    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings')*
*    try:*
*        from django.core.management import execute_from_command_line*
*    except ImportError as exc:*
*        raise ImportError(*
*            "Couldn't import Django. Are you sure it's installed and "*
*            "available on your PYTHONPATH environment variable? Did you "*
*            "forget to activate a virtual environment?"*
*        ) from exc*
*    execute_from_command_line(sys.argv)*
**
*if __name__ == '__main__':*
*    main()*
A step in the right direction will be super helpful for me.
--
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/69291c68-61e7-4557-8175-7b705bcfcbb0n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/69291c68-61e7-4557-8175-7b705bcfcbb0n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/d4cdd3dc-744a-1af3-0450-7badfeb8b48b%40antonischristofides.com.


Re: mysql 8 file creation issue

2022-03-18 Thread Antonis Christofides
I'm not certain, but it doesn't look to me as a MySQL version issue. It's more 
probably a umask issue. Search for "umask" and you'll probably find the answer.


However, it's likely that this is suboptimal and risky. It would probably be 
better to run `mysql` (or whatever mysql client you are using) as the same 
operating system user as the one who will read and write the csv file later.


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 18/03/2022 06.48, Aadil Rashid wrote:


When I run this query on mysql 5.7:

SELECT CURDATE() INTO OUTFILE '/var/lib/mysql-files/test.csv';

It creates test.csv with the following permissions:

-rw-rw-rw- 1 mysql mysql 11 Mar 18 04:27 test.csv

But when I create the same file in mysql 8.0 it creates file with the 
following permissions:


-rw-r- 1 mysql mysql 11 Mar 18 09:54 test.csv

How would I allow mysql 8 to create file with the same permissions it created 
with mysql 5.7 ? The reason being I need to read and write to that generated 
file later in my application.


--
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/5292768f-f3f4-4973-aea2-ecceb1cda299n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/5292768f-f3f4-4973-aea2-ecceb1cda299n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/c5824464-a427-d8fc-ae3b-a4391db69830%40antonischristofides.com.


Re: How do detect if template is being viewed on mobile device?

2022-03-17 Thread Antonis Christofides

Inside of a Django function or template we need to know if to display
a landscape or portrait of a form - based on knowing if the viewer is
using a mobile or not.
Your requirement to know whether you are using "landscape or portrait" is 
unusual. Normally we are only interested in knowing the width of the screen. If 
the screen is wide enough, we show the wide version, without caring about what 
the height of the screen is (it could be a large screen in portrait, for example).


In any case, I think you can solve it with CSS (even if you really want to take 
the height of the screen into account). This problem has nothing to with Python 
and Django, it's merely a HTML+CSS issue. If you don't want to learn much CSS, 
using a CSS framework like Bootstrap can help.


Regards,

Antonis

Antonis Christofides



On 16/03/2022 22.42, Django2021 wrote:
> There are many ways to approach this problem, so it would be best to explain 
what you are trying to achieve.


Inside of a Django function or template we need to know if to display
a landscape or portrait of a form - based on knowing if the viewer is
using a mobile or not.
On Wednesday, March 16, 2022 at 9:34:09 PM UTC+1 Antonis Christofides wrote:

Hello,

there are many ways to approach this problem, so it would be best to
explain what you are trying to achieve.

Regards,

Antonis

Antonis Christofides
+30-6979924665(mobile)


On 16/03/2022 22.28, Django2021 wrote:


With Django how is it possible to detect
* if template is being viewed on mobile device?
and/or
* if template is being viewed in portrait or landscape mode?

Any suggestions 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...@googlegroups.com.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/7be1145e-662e-4d57-afa6-b9d178f7fb0fn%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/7be1145e-662e-4d57-afa6-b9d178f7fb0fn%40googlegroups.com?utm_medium=email_source=footer>.


--
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/83a4a51d-6913-47ce-a5da-f49f4b3d72abn%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/83a4a51d-6913-47ce-a5da-f49f4b3d72abn%40googlegroups.com?utm_medium=email_source=footer>.


--
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/0d0aa98d-7142-aceb-5bd8-31e41e705bac%40antonischristofides.com.


Re: How do detect if template is being viewed on mobile device?

2022-03-16 Thread Antonis Christofides

Hello,

there are many ways to approach this problem, so it would be best to explain 
what you are trying to achieve.


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 16/03/2022 22.28, Django2021 wrote:


With Django how is it possible to detect
* if template is being viewed on mobile device?
and/or
* if template is being viewed in portrait or landscape mode?

Any suggestions 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7be1145e-662e-4d57-afa6-b9d178f7fb0fn%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/7be1145e-662e-4d57-afa6-b9d178f7fb0fn%40googlegroups.com?utm_medium=email_source=footer>.


--
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/66c9d4a1-b0c6-41fe-e09a-2bd6faa3a9ed%40antonischristofides.com.


Re: How Important Is Writing Unit Tests For Django Applications?

2022-03-13 Thread Antonis Christofides

Hello,

This topic is always interesting for me.

*What is an integration test?*

First, I'm always confused about what "integration tests" means. Apparently I'm 
not the only one. Here's what Edd Yerburgh says in his excellent book, "Testing 
Vue.js Applications" (p. 9):


   People define integration tests differently, especially on the frontend.
   Some think tests that run in a browser environment are integration tests.
   Some think any test that tests a unit with module dependencies is an
   integration test. Some think that any fully rendered component is an
   integration test.

His definition of end-to-end tests is also relevant (p. 5):

   In frontend applications, end-to-end tests automate a browser to check that
   an application works correctly from the user's perspective.

An additional complication is that people often use the term "unit testing" as 
all encompassing, that is for any kind of automated testing. This is especially 
true in Python, where the module for automating testing is called "unittest", 
and even more so in Django, where its TestCase subclasses contain functionality 
which some people would consider inappropriate for "unit tests" and appropriate 
only for "end-to-end" tests or "integration" tests, whatever that means.


On the other hand, why is a Django view NOT a unit of functionality? I think it 
is. Therefore why testing a Django view isn't unit testing? I don't really know, 
this is just food for thought. I think I'd talk about low-level testing and 
high-level testing, this labeling of end-to-end vs. unit doesn't always work 
well I think.


*How to do a high level test*

def add(a, b):
    return a + b

def multiply(i, j):
    result = 0
    while i:
    result = add(result, j)
    i -= 1
    return result

These are very stupid and I haven't tried them at all but it doesn't matter, the 
point I'm trying to make is that "multiply" is my high level function here, 
because it is calling "add", which is a lower level function.


How do you test "multiply"? A purist might say that you have tested "add" with 
some unit tests, and that when testing "multiply" you should mock "add". This 
way, if a unit test for "multiply" fails, you know the problem was in "multiply" 
and not in "add".


But, frankly, mocking is such a pain that I avoid doing it unless doing it 
without mocking would be harder. That is, my rule of thumb is to mock or not to 
mock based on how easy it will be to write a test. If you don't mock, an error 
in "add" should cause some "add" unit tests AND some "multiply" unit tests to 
fail. Usually it won't be hard to locate and fix the error.


At other times, I don't do low level testing at all. If the low-level function 
is just an implementation detail of the high level function, then often I don't 
test the lower level.


*Conclusion*

The purpose of writing tests is usually to save time. It's really hard, if not 
impossible, to measure how much time and money you saved (or lost) by working 
one way vs. another. Ultimately we just have a feeling guide us. I feel ok with 
my testing experience, but I always wonder whether I'm testing insufficiently or 
whether I'm testing too much.


I didn't expect this reply to become that long, neither that I would not answer 
the question in the end. I hope it was helpful anyway. Good luck!


Antonis Christofides
+30-6979924665 (mobile)



On 12/03/2022 20.00, Daniel Coker wrote:
I understand the importance of unit testing. However, if we are going to write 
integration tests (testing the views), this test will step through all of the 
modules that we would otherwise unit test.


So, I'm wondering, it it really necessary to write unit test for Django 
Applications when we will still test the views?

--
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/d0cf2d7c-79cb-41a5-801a-4240c3c0c1c1n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/d0cf2d7c-79cb-41a5-801a-4240c3c0c1c1n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/6818c74d-9ce2-1d91-0e6a-99895bcb1020%40antonischristofides.com.


Re: Update to Tutorial 4 - Generic Views

2022-03-11 Thread Antonis Christofides

Hello,

why do you say that importing of TemplateView is missing? I don't see 
TemplateView being used anywhere in that page.


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 11/03/2022 07.42, Dan Cox wrote:
Hi I've been searching on how I might contribute to the tutorials but I can't 
seem to find a way. If you could help me there I could take this question to a 
potentially more useful place.


Anyway; I am pretty new to Django but I've been following the tutorials and in 
the Generic Views section here: 
https://docs.djangoproject.com/en/4.0/intro/tutorial04/


I beleive that there is a missing import statement in the urls.py file:
from django.views.generic import TemplateView

I was scratching my head trying to work out why I was getting errors and upon 
adding that (which I found in the more general documentation on Views) 
everything worked.


Cheers,

Dan.
--
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/9869e767-7255-40e4-839e-fdcb6d834257n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/9869e767-7255-40e4-839e-fdcb6d834257n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/d6191aab-6f2a-a29f-e5f8-df4852189ad4%40antonischristofides.com.


Re: How to add object to users unique list?

2022-02-28 Thread Antonis Christofides

Hello!

Are you using class-based views? Does your view have a post() method?

I searched the web for `django "method not allowed (POST)"` and this is the 
first result that came up:


https://stackoverflow.com/questions/52244156/method-not-allowed-post-in-django

Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)



On 28/02/2022 19.49, raf sandwich wrote:
Hi there. I have a system whereby users are recommended anime, and I want it 
so when they see anime on the website they can press a button on any anime 
shown, which will then add it to their 'UserList' which is a saved list that 
they can go back to and see whenever they want.


I figure the button just needs to associate the anime.id with the POST 
request, and then add it to the user that is logged ins 
user.userlist.anime_in_list but I can't get it to work.


Currently my terminal is displaying the error

Method Not Allowed (POST): /anime/

Method not allowed: /anime/

when the button is pressed


A code break down for my models.py, views.py etc. is available on this reddit 
post:


https://www.reddit.com/r/djangolearning/comments/t3jwo0/how_to_add_an_object_to_a_users_list_without/

Thanks for any help I'm so stuck and I think it's probably simple!

--
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/68c00521-21f5-4e15-a737-41edc42c11dfn%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/68c00521-21f5-4e15-a737-41edc42c11dfn%40googlegroups.com?utm_medium=email_source=footer>.


--
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/e52adcd4-bf95-4da8-ed2a-661a17617cb6%40antonischristofides.com.


Re: How to create dynamic models in django??

2022-02-26 Thread Antonis Christofides
Short answer: I don't know. It probably isn't straightforward, but it's doable 
in principle.


Longer answer: Django hasn't been designed with this case in mind. It's possible 
it's not the appropriate tool for the job (but again it might be, I don't know). 
In my experience you should avoid doing such things—it's likely to lead to an 
unmanageable code mess. Keep it simple. Consider working without a relational 
database.


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 27/02/2022 05.40, Prashanth Patelc wrote:

How to create dynamic models in django rest framework?
Is there any chance to create dynamic models with APIs

Any examples please send me thanks in advance..

1) Requirement is need create table name and fields in frontend
2) we are  getting the data and store in to the db create db structure
3) get the table name and fields create table in backend  store to
4)this code don't update or add into the models
5)store the data into the tables
4)get the data into the tables using orm or any raw queries

--
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/CAMCU6Coop%3DVU67%2B1Ui%2BswvA2xijUYcre%2B%3D-Z_CzLnf-1pRRXUw%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAMCU6Coop%3DVU67%2B1Ui%2BswvA2xijUYcre%2B%3D-Z_CzLnf-1pRRXUw%40mail.gmail.com?utm_medium=email_source=footer>.


--
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/86427c17-5103-2370-2bf4-c951c77b288e%40antonischristofides.com.


Re: Login & Register

2022-02-26 Thread Antonis Christofides

Hello,

A discussion about this occurred just a few days ago (less than a week) in this 
list. Take a look at the archives.


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 26/02/2022 17.09, Ankit Chaurasia wrote:
Hey, I am new in Djnaog and I want to make Login and Register Page with Email 
Verification.

Can anone share the code ?
and please gide me for the same.
--
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/2eb50cd8-73cb-4d9a-be31-4635d01c8641n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/2eb50cd8-73cb-4d9a-be31-4635d01c8641n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/214cd135-c4a2-d602-8969-22e03a27f77b%40antonischristofides.com.


Re: Slow page load performance with a large number of formsets (over 25)

2022-02-26 Thread Antonis Christofides

However, caching the queryset solves only part of the problem.

If you have a formset with 100 forms, and each of these forms has a choice field 
with 100 choices (say 50 bytes each), then you have altogether 10k choices or 
500k bytes of data. While, depending on the particular case, this may be 
manageable, it can get quickly out of hand if the forms become 200 or the 
choices become 200 or more etc.


A technical solution to that problem could be to retrieve the choices only once 
and have some JavaScript fill in the choices in the forms. But this departs from 
the Django formset paradigm and might require significant development.


The alternative I see would be to redesign the UI so that it doesn't need a 
formset (at least such a big formset). While I don't know the specifics of this 
particular case, I would hack my brains to see whether I can present this 
information in a more simple manner to the user (because 100 forms would be 
overwhelming I guess). Once I have a saner UI, the implementation details would 
follow naturally.


Antonis Christofides
+30-6979924665 (mobile)



On 26/02/2022 05.43, Jacob Greene wrote:
You would need to cache the queryset and pass it to each form instance that 
the formset creates. I've done this a few different ways in the past. I've 
never understood why there isn't a more straight forward way to do this. 
Here's a post with a few legit options depending on your use case:


https://stackoverflow.com/questions/8176200/caching-queryset-choices-for-modelchoicefield-or-modelmultiplechoicefield-in-a-d

Hard to be more specific without knowing anything about your code.

On Fri, Feb 25, 2022, 8:53 PM Steve Smith  wrote:

If in fact I am….how do I avoid this?  I have been playing with
alternatives for a week and I’m starting to lose it…lol

Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

*From: *Jacob Greene <mailto:jacobgreene1...@gmail.com>
*Sent: *Friday, February 25, 2022 5:58 PM
*To: *django-users@googlegroups.com
*Subject: *Re: Slow page load performance with a large number of formsets
(over 25)

If you're using model choice fields, it's very likely you are making an
SQL query for each form set. It should be pretty obvious in the log with
debug turned on.

On Fri, Feb 25, 2022, 4:31 PM Ryan Nowakowski  wrote:

Steven, are you using ModelFormSet?  If so, Is it the initial query
that's slow?  The form rendering?  Or is it the POST back to the server
that's slow?  You can use django-debug-toolbar[1] to profile your page
and get these metrics.

Once you figure out what part is slowest, then you can optimize.

Hope this helps!

Ryan N

[1] https://django-debug-toolbar.readthedocs.io/en/latest/

On Mon, Feb 07, 2022 at 09:12:48AM -0800, Steven Smith wrote:
> Did this issue ever get resolved?  I'm experiencing the same thing. 
Once
> it hits 100 forms or so it gets pretty slow.
>
> On Monday, September 22, 2014 at 10:48:52 AM UTC-5 Collin Anderson
wrote:
>
> > Yes, if you want speed, using javascript and ajax is probably your
best
> > bet. It will probably also reduce merge-conflicts.
> >

-- 
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
<mailto:django-users%2bunsubscr...@googlegroups.com>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/20220225222926.GH11627%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/CAF-Y%3De5Fp7kDtLq47Z3Y4GEjXMne2PcTLYxOJ8St5gkKCkpUpw%40mail.gmail.com

<https://groups.google.com/d/msgid/django-users/CAF-Y%3De5Fp7kDtLq47Z3Y4GEjXMne2PcTLYxOJ8St5gkKCkpUpw%40mail.gmail.com?utm_medium=email_source=footer>.

-- 
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/CH0PR18MB42923C9432F56E071FA9716CD23F9%40CH0PR18MB4292.namprd18.prod.outlook.com

<https://groups.google.com/d/msgid/django-users/CH0PR18MB42923C9432F56E071FA9716CD23F9%40CH0PR18MB4292.namprd18.p

Re: Email verification

2022-02-23 Thread Antonis Christofides
You can try django-registration-redux 
.


Regards,

Antonis


On 23/02/2022 17.10, Rushikesh Chavan wrote:
I am new to django, i am working on one project which requires a feature of 
email verification  , how do I do it? Like , I want to send the email to the 
user who registered on my site and give one link in this mail which will 
verify the user

--
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/CAKFN6W5HZR_bShSfBrTsb492bpv0dmOamtXMbxQQtfyF7BKw4Q%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/fc69cc0d-cdd8-0674-3e38-06a01b3e1a23%40antonischristofides.com.


Re: Need help in User log in, someone please help

2022-02-22 Thread Antonis Christofides

You have this statement:

    user = User.objects.create_user(username=username, email=email, password = 
password)


Just before this statement, you need to insert a statement that will enable you 
to examine the value of the "username" statement. Something like this:


    print(username)
    user = User.objects.create_user(username=username, email=email, password = 
password)


This might or not might work properly with Django. What most Python programmers 
would do instead is this:


    import pdb; pdb.set_trace()
    user = User.objects.create_user(username=username, email=email, password = 
password)


but for that you need to know how to use pdb. It's quite simple though tricky at 
first. Eventually you will need to learn it, however, so now would be a good 
time. Search the web.


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)



On 22/02/2022 19.01, Raj wrote:
I am trying to create register form access in django, but i am getting this*" 
ValueError at /registerThe given username must be set" error.

*
Kindly help me how can I fix this bug.
please.
*here is the code of the views.py file.--->*
from msilib.schema import Feature
from pyexpat.errors import messages
from django.shortcuts import render, redirect
from django.contrib.auth.models import User, auth
from django.contrib import messages
from django.http import HttpResponse
from .models import Feature
# Create your views here.
def index(request):
    return render(request,'index.html',{'features': features})
#=---register function---
def register(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        email = request.POST.get('email')
        password = request.POST.get('password')
        password2 = request.POST.get('password2')
        # username = request.POST['username']
        # email = request.POST['email']
        # password = request.POST['password']
        # password2 = request.POST['password2']
        if password == password2:
            if User.objects.filter(email = email).exists():
                messages.info(request, 'Email already has been used!')
                return redirect('register')
            elif User.objects.filter(username= username).exists():
                messages.info(request, 'Username already exist')
                return redirect('register')
            else:
                user = User.objects.create_user(username=username, 
email=email, password = password)

                user.save();
                print("User created")
                return redirect('login')  #check
        else:
            messages.info(request, 'Incorrect password')
            return redirect('register')
    else:
        return render(request, 'register.html')
def login(request):
    if request.method == 'POST':
        # username = request.POST['username']
        # password = request.POST['password']
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = auth.authenticate(username = username, password = password)
        if user is not None:
            auth.login(request, user)
            return redirect('/')
        else:
            messages.info(request,'Credential Invalid')
            return redirect('login')
    else:
        return render(request, 'login.html')
*here is the SS of the error*Screenshot (75).png
--
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/c7bcf4b5-f8e7-4f84-97df-02e4655e42f1n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/c7bcf4b5-f8e7-4f84-97df-02e4655e42f1n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/cdfef3b3-37b4-801d-c53c-85d8176e3025%40antonischristofides.com.


Re: Needs help

2022-02-22 Thread Antonis Christofides

Hello Loic,


Please how to turn a picture into a LEGO version?
A project that does this will be welcome.
Not sure what you mean by that and what it has to do with Django. You aren't 
going to get any useful answers in this list unless you change the way you ask 
questions.


You should really take some time to read 
http://www.catb.org/~esr/faqs/smart-questions.html.


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 22/02/2022 11.30, loic ngounou wrote:

Please how to turn a picture into a LEGO version?
A project that does this will be welcome.
--
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/26ef7fae-d58c-45f7-b132-c863aa2ebb03n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/26ef7fae-d58c-45f7-b132-c863aa2ebb03n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/990f2eab-b8d3-5ecc-1f5f-635d44e06c05%40antonischristofides.com.


Re: collectstatic files chown'ed by root

2022-02-14 Thread Antonis Christofides
Everything works fine except for the collectstatic command (in entrypoint.sh), 
which creates the "staticfiles" directory but it's owned by root.
This is not possible. If "manage.py" is running as a non-root user, it wouldn't 
be possible for it to create a directory owned by root. Something else is going 
on. Could you share your entrypoint.sh script?


Antonis Christofides
+30-6979924665 (mobile)


On 14/02/2022 13.14, 'Tim' via Django users wrote:

Hi all,
I'm deploying Django 4 via docker-compose. For security reasons, the 
Dockerfile creates a non-root user before running the entrypoint.sh script 
(which does migrations, collectstatic and starts the server with gunicorn). 
All app files are "chown"ed by this non-root user.


Everything works fine except for the collectstatic command (in entrypoint.sh), 
which creates the "staticfiles" directory but it's owned by root. This leads 
to permission denied errors when the collectstatic command tries to delete a 
static file.


My question: Why does collectstatic assign the folder to "root" despite the 
non-root user calling the collectstatic command? How to prevent this?


I tried doing the collectstatic command before switching to the non-root user 
(in the Dockerfile) which works. But it stops working when I put the Django 
SECRET_KEY in a .env file (as we should in production) since this env var is 
not available during docker build time.


Now I could find a hackier way by making the secret key available during build 
time or switching back to a root user in entrypoint.sh, but all of this is a 
bad workaround in my opinion.


I'm sure everyone deploying Django with docker and being mindful of security 
has come across this - Any hints about why collectstatic is owned by root? Is 
this a bug?


Should I add additional details?

Thanks for any tips!
Tim
--
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/c3381f62-4bf1-4142-b27f-189ef45a75fan%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/c3381f62-4bf1-4142-b27f-189ef45a75fan%40googlegroups.com?utm_medium=email_source=footer>.


--
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/f6b72435-84e4-ffc7-a1c4-ac9f4b7ced96%40antonischristofides.com.


Re: Formsets?!?!?!?!?!?!?!?!?!?

2022-02-12 Thread Antonis Christofides

Hello,


I have also seen some discussions about formsets recently. I think it's not as 
simple as that. I don't believe there's any rule that applies to all cases. Each 
case is probably different.



You say you have 100 rows with 12 fields each, and that it takes 19 seconds to 
render. Where are these 19 seconds spent? It could be that the data is fetched 
from the database instantly and that the 19 seconds are spent in order for some 
template to render. Or it could be that even this is done quite fast and that 
the resulting html is too complicated and the browser takes too long to render 
it. Or something else.



While I don't have much experience with formsets, I've made some pretty 
complicated stuff in the admin (which makes heavy use of formsets). I once had a 
database of scientific publications, and each publication could have an 
indefinite number of authors. If a publication had, say, 10 authors, then the 
author formset would repeat itself 10 times (plus two or three more empty ones 
for any additional you'd want to register). Each of these 12-13 formsets had an 
"author" dropdown field. There were hundreds of authors in the database, so each 
of the 12-13 dropdowns had hundreds of options. Imagine this:



  

    Antonis Christofides

    Steve Smith


    [... 300 more options here]


  


all this repeated 13 times. There wasn't that anything in there that was 
particularly slow, it was the sheer volume of information that made it slow. In 
that case the solution was obvious—I just needed to use the admin's 
raw_id_fields option.



So there's no generic way to diagnose the problem. You need to investigate. 
Start with the Django Debug Toolbar and check where this time is spent. Then try 
reducing the code gradually to arrive at a minimal example. When you have 
identified what causes the delay, you will be able either to solve it yourself 
or to ask us a more specific question. (Either way tell us what happened.)



Regards,


Antonis

Antonis Christofides
+30-6979924665 (mobile)



On 12/02/2022 07.38, Steve Smith wrote:

Hello all

I have formsets workingbut I seem to be encountering some performance 
issues if I have more than 25 rows.  I've looked at my database 
callsselect_related...prefetch_related...and I've polled several 
audiences...SOFacebook Groupsand the consensus seems to be that 
Formsets are bad if you have a lot of rows.  I'm having trouble accepting that 
because if that was the case why do they exist?  And why is the default like 
1000 forms?  I really like the formset conceptbut I'm having a hard time 
accepting that if you have more than 25 rows it's just gonna be "slow".  And 
by slow I mean when I try to render the form using formsets and I have 100 
rows of data with like 12 fields each...it takes 19 seconds or so for the form 
to render. Does this sound like normal behavior?  I'm legitimately asking as I 
honestly don't know.


Thanks in advance for any thoughts or feedback.

Steve

--
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/CH0PR18MB4292692992A37BD51AAEB0AFD2319%40CH0PR18MB4292.namprd18.prod.outlook.com 
<https://groups.google.com/d/msgid/django-users/CH0PR18MB4292692992A37BD51AAEB0AFD2319%40CH0PR18MB4292.namprd18.prod.outlook.com?utm_medium=email_source=footer>.


--
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/e70386b4-b00c-a1b6-7fc0-dd43df984cbb%40antonischristofides.com.


Re: Off topic slightly - Apache https redirect

2022-02-07 Thread Antonis Christofides
Technically the correct way here is to include 'permanent'. This may help search 
engines do the correct thing.


But there is a problem. At least until a few years ago, the RFC mandated that 
permanent redirects be cachable forever, and browsers were doing this. Assuming 
this continues today, if for any reason you ever decide to undo this permanent 
redirect or point it elsewhere, or simply if you make an error while configuring 
apache, you are out of luck. In my opinion, this is an error in the RFC, and as 
someone had commented, it is silly to have a provision that lets you so easily 
give up control of a resource for ever.


Because of this, I always include this in my apache configuration (not in the 
host configuration but in the general configuration which applies to all hosts):


Header always set Cache-Control "no-store, no-cache, must-revalidate" 
"expr=%{REQUEST_STATUS} == 301"
Header always set Expires "Thu, 01 Jan 1970 00:00:00 GMT" 
"expr=%{REQUEST_STATUS} == 301"


Antonis Christofides
+30-6979924665 (mobile)


On 07/02/2022 23.27, Mike Dewhirst wrote:
Yes ... that's almost what I went with after reading up on the topic. I left 
the 'permanent' off.


Thanks Bob and everyone.

Cheers

Mike

--
(Unsigned mail from my phone)



 Original message 
From: Bob Kline 
Date: 8/2/22 06:30 (GMT+10:00)
To: Django users 
Subject: Re: Off topic slightly - Apache https redirect

On Sunday, February 6, 2022 at 9:12:38 PM UTC-5 Mike Dewhirst wrote:

There seems to be a multitude of ways to redirect from http to https.
Any pointers to the absolutely correct way?


How about something like this?


  ServerName example.com
  ServerAlias www.example.com
  Redirect permanent / https://example.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/c8c8177d-49c0-45f7-b382-31855ccb6b0an%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/c8c8177d-49c0-45f7-b382-31855ccb6b0an%40googlegroups.com?utm_medium=email_source=footer>.

--
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/62018eb3.1c69fb81.e0fe.0b9fSMTPIN_ADDED_MISSING%40gmr-mx.google.com 
<https://groups.google.com/d/msgid/django-users/62018eb3.1c69fb81.e0fe.0b9fSMTPIN_ADDED_MISSING%40gmr-mx.google.com?utm_medium=email_source=footer>.


--
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/90a16663-f1e5-183c-ae22-5d1491b2c08d%40antonischristofides.com.


Re: Resource leaks from FieldFile's implicit open?

2022-02-02 Thread Antonis Christofides
I think that the documentation is not entirely clear. I wouldn't say that the 
object "wrapped by" FieldFile is "a wrapper around the result of" 
Storage.open(). It is actually FieldFile.open() that is a wrapper around 
Storage.open(). Therefore I think I'd rephrase as follows:


   FieldFile is a subclass of File. While File is a wrapper around Python's
   built-in file object, FieldFile uses the underlying Storage.

As far as I can see by reading the code, you can write code like this:

   with some_file_field:
    ...

Inside the "with" block you will probably access `some_file_field.file`. 
Apparently accessing that attribute is what opens the file (but accessing the 
`size` attribute also seems to be opening it, which is probably suboptimal.)


I'm not certain about files that don't exist. You might want to wrap the "with" 
block in a try-except, but I'm not certain about which exceptions you want to 
catch. It's probably ValueError and IOError.


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 01/02/2022 21.22, Carsten Fuchs wrote:

Dear group,

despite a lot of reading and searching I still don't understand how FieldFiles 
work.

The documentation 
athttps://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.fields.files.FieldFile
  says:


The API of FieldFile mirrors that of File, with one key difference: The object 
wrapped by the class is not necessarily a wrapper around Python’s built-in file 
object. Instead, it is a wrapper around *** the result of the Storage.open() 
method ***, which may be a File object, or it may be a custom storage’s 
implementation of the File API.

(I added markers to indicate the portion that I have trouble with.)

As far as I understand this, whenever a `FieldFile` is instantiated, 
`Storage.open()` is called. Thus, if the underlying storage is the 
`FileSystemStorage`, a Python file object is opened.

However, how is this file handle closed again?

It looks as if it stays open until garbage collected, that is, possibly for a 
very long time.

Another consequence besides the potential resource leak seems to be that the 
implicit open will raise an exception if the file that the `FieldFile` refers 
to doesn't exist. As I don't exactly understand when this opening occurs, a lot 
of code must be wrapped in try-except blocks to handle this?

Best regards,
Carsten



--
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/ea9e066d-49b4-2c75-c477-10f9306d6221%40antonischristofides.com.


Re: In django you can either obtain a `csrftoken` from a cookie or the form can generate a nonce `csrftoken`. How does django validate both?

2021-06-30 Thread Antonis Christofides
What if I can copy that cookie (samesite)  in developer tools from 
legitimate-site.com <http://legitimate-site.com> and create a new cookie for 
malicious-site.com <http://malicious-site.com> using developer tools. After I 
do that I make a request. Will it be successful?
I think it would probably work. (This is not a security issue, though, since the 
user agrees. The problem is when malicious-site.com tries to do something to 
legitimate-site.com using the user's credentials without the user knowing.)


Antonis Christofides
+30-6979924665 (mobile)



On 01/07/2021 01.48, Patrice Chaula wrote:
What if I can copy that cookie (samesite)  in developer tools from 
legitimate-site.com <http://legitimate-site.com> and create a new cookie for 
malicious-site.com <http://malicious-site.com> using developer tools. After I 
do that I make a request. Will it be successful?


On Wed, Jun 30, 2021, 3:43 PM Antonis Christofides 
mailto:anto...@antonischristofides.com>> wrote:


Django does not store csrftoken on the server.

Django provides the csrftoken in two places: 1) The cookie; 2) A hidden
form field.

When the browser makes a POST request, then:

 1. It sends back the cookie anyway (that's what cookies do)
 2. It submits the csrftoken as a form field (or as the X-CSRFToken HTTP
header in case of AJAX).

All Django does after that is verify that the token it receives with (2)
is the same as the token it receives with (1).

Why this helps? Because the attack it is designed to mitigate is one where
you visit malicious-site.com <http://malicious-site.com> which contains
the following:

https://legitimate-site.com;
<https://legitimate-site.com>>
    
    
    


For this attack to succeed, malicious-site.com <http://malicious-site.com>
would need to specify a csrftoken as, say, a hidden form field (which is
possible) AND provide the same token through a cookie. This is not
possible. malicious-site.com <http://malicious-site.com> can't set cookies
of another site. The post request may indeed send a csrftoken as a cookie
to legitimate-site.com <http://legitimate-site.com>, but this will be the
csrftoken received the previous time the user visited legitimate-site.com
<http://legitimate-site.com>. It will not be the same as the csrftoken
sent as a hidden field, because malicious-site.com
<http://malicious-site.com> can't read cookies of another site, so it
can't possibly read that cookie and set the hidden field to its value.

Antonis Christofides
+30-6979924665 (mobile)




On 30/06/2021 15.14, Patrice Chaula wrote:

In django you can either obtain a `csrftoken` from a cookie. Or the form
can generate a nonce `csrftoken`. How does django validate both and where
are they stored on the server. Are they stored as part of the session?
-- 
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
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/83f3da74-ecbc-4197-9627-0c9ab9e8492fn%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/83f3da74-ecbc-4197-9627-0c9ab9e8492fn%40googlegroups.com?utm_medium=email_source=footer>.
-- 
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
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/7732c858-fd8c-53de-9a0f-99ae704ae4c6%40antonischristofides.com

<https://groups.google.com/d/msgid/django-users/7732c858-fd8c-53de-9a0f-99ae704ae4c6%40antonischristofides.com?utm_medium=email_source=footer>.

--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE%3DG6DY1gG71vdqEUiax%3DQqfuqukC%3Dyi-qo9zKnwyra4i3ujDw%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAE%3DG6DY1gG71vdqEUiax%3DQqfuqukC%3Dyi-qo9zKnwyra4i3ujDw%40mail.gmail.com?utm_medium=email_source=footer>.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe f

Re: In django you can either obtain a `csrftoken` from a cookie or the form can generate a nonce `csrftoken`. How does django validate both?

2021-06-30 Thread Antonis Christofides

Django does not store csrftoken on the server.

Django provides the csrftoken in two places: 1) The cookie; 2) A hidden form 
field.

When the browser makes a POST request, then:

1. It sends back the cookie anyway (that's what cookies do)
2. It submits the csrftoken as a form field (or as the X-CSRFToken HTTP header
   in case of AJAX).

All Django does after that is verify that the token it receives with (2) is the 
same as the token it receives with (1).


Why this helps? Because the attack it is designed to mitigate is one where you 
visit malicious-site.com which contains the following:


https://legitimate-site.com;>
    
    
    



For this attack to succeed, malicious-site.com would need to specify a csrftoken 
as, say, a hidden form field (which is possible) AND provide the same token 
through a cookie. This is not possible. malicious-site.com can't set cookies of 
another site. The post request may indeed send a csrftoken as a cookie to 
legitimate-site.com, but this will be the csrftoken received the previous time 
the user visited legitimate-site.com. It will not be the same as the csrftoken 
sent as a hidden field, because malicious-site.com can't read cookies of another 
site, so it can't possibly read that cookie and set the hidden field to its value.


Antonis Christofides
+30-6979924665 (mobile)




On 30/06/2021 15.14, Patrice Chaula wrote:
In django you can either obtain a `csrftoken` from a cookie. Or the form can 
generate a nonce `csrftoken`. How does django validate both and where are they 
stored on the server. Are they stored as part of the session?

--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/83f3da74-ecbc-4197-9627-0c9ab9e8492fn%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/83f3da74-ecbc-4197-9627-0c9ab9e8492fn%40googlegroups.com?utm_medium=email_source=footer>.


--
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/7732c858-fd8c-53de-9a0f-99ae704ae4c6%40antonischristofides.com.


Re: Diploy django on DigitalOcean

2021-06-24 Thread Antonis Christofides

Hi,

you can try "Deploying Django on a single Debian or Ubuntu server" at 
djangodeployment.com or djangodeployment.readthedocs.io.


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 24/06/2021 10.20, Eugene TUYIZERE wrote:

Hello Team,

I need some tutorials and steps to deploy a django app on DigitalOcean. Note 
that I already have the domain what it remaining is only to host.


Thank you

--
*Eugene*

--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABxpZHsoWK1zUBgu8a4CERk0AcK2pm3zG_pa8Kv%3D7vGtXXbr_g%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CABxpZHsoWK1zUBgu8a4CERk0AcK2pm3zG_pa8Kv%3D7vGtXXbr_g%40mail.gmail.com?utm_medium=email_source=footer>.


--
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/b9895365-b303-948f-88c6-3b7f43a57c82%40antonischristofides.com.


Re: os module import error

2021-05-31 Thread Antonis Christofides

Hi!

Could you show exactly which command(s) you are running, and the exact error 
message?


Regards,

Antonis Christofides
+30-6979924665 (mobile)

On 31/05/2021 17.57, James Ndubuisi wrote:

Good afternoon.
It seems on creating the Django project using django-admin startproject 
command , the os module isn't imported by default, causing an error.

--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK4ckVVeaT75CAPQWZeD6q6ewraHmaRH07W_6JQRemX6QV%2BXNA%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAK4ckVVeaT75CAPQWZeD6q6ewraHmaRH07W_6JQRemX6QV%2BXNA%40mail.gmail.com?utm_medium=email_source=footer>.


--
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/cf967d61-ef98-0cdc-8f39-991641ba5728%40antonischristofides.com.


Re: Newbee help on deploying Django App to Apache2

2021-05-30 Thread Antonis Christofides
Apache and nginx are called "web servers". Windows and FreeBSD are called 
"operating systems". What is the term for Gunicorn, uWSGI and mod_wsgi? I 
believe there's no good term, which is one reason for the confusion.


Gunicorn, uWSGI and mod_wsgi are specialized web servers that run Python 
WSGI-compliant applications. For lack of a better name, I'll call them Python 
application servers, but don't forget that they are nothing more (and nothing 
less) than specialized web servers that run Python WSGI-compliant applications.


What the Python application server does is

    from djpro.wsgi import application

and then, in each HTTP request, it calls application() in a standard way that is 
specified by the WSGI specification. The fact that the interface of this 
function is standardized is what permits you to choose between many different 
Python application servers such as Gunicorn, uWSGI, or mod_wsgi, and why each of 
these can interact with many Python application frameworks like Django or Flask.


The Python application server does not *communicate* with the Django project, it 
*imports* the Django project. From the point of view of the operating system, it 
is the same process. You don't have a separate server which "runs" or 
"communicates with" Django, which would mean that the Python application server 
and Django could run in separate virtualenvs. You have a single Python program 
and there is only one virtualenv. What we do for Gunicorn, for example, is 
install it in the same virtualenv where we have Django (pip install gunicorn), 
and then run it from there.


I am not familiar with mod_wsgi, but the thing is, by the time it's ready to 
import the Django project, Python is already running, and you can't select or 
change a virtualenv any more. So selecting a virtualenv (which I assume is 
possible) must be in the mod_wsgi configuration. I hope these principles help 
you understand mod_wsgi's documentation.


I find Gunicorn an easier and better way to deploy, regardless the web server. 
More information:


 * How to setup Apache with Gunicorn
   <https://djangodeployment.com/2016/11/30/how-to-setup-apache-with-gunicorn/>
 * Detailed instructions on setting up Gunicorn
   <https://djangodeployment.readthedocs.io/en/latest/06-gunicorn.html>

Antonis Christofides
+30-6979924665 (mobile)



On 30/05/2021 09.29, Moose Smith wrote:
App written in ubuntu virtual environment python 3.8.5. Works well on Visual 
Studio Code development server. Am trying to make it run on Apache2 
development server.  I have been able to install WSGI module on Apache Server 
and ran a test Hello World in Python and it worked. However, the django app 
when ported over does not work.

The error log confirms that the mod_wsgi has been created using by Python 3.8
[mpm_event:notice] [pid 607786:tid 140700034231360] AH00489: Apache/2.4.41 
(Ubuntu) mod_wsgi/4.6.8 Python/3.8 configured -- resuming normal operations
The error I am getting indicates that the Apache / WSGI is reading the files 
in the virtual environment I copied over.


mod_wsgi (pid=609049): Exception occurred processing WSGI script '/ File 
"/usr/public/apache/MCE/learn/djpro/wsgi.py", line 12, in 

from django.core.wsgi import get_wsgi_application
ModuleNotFoundError: No module named 'django'

My research indicates that this error occurs when the mod--wsgi in being 
interpreted by a different version than what was used to create my virtual 
environment. It also might be permissions/ownership issues with the file and 
directories copied over to the server, or improperly configured module.


My question is this: Does the mod_WSGI module have to be the same as the one 
that created my virtual environment?  My understanding is that WSGI has two 
components, the server side, and the application side. It would not make sense 
that the Server side MUST match the application side because it would not be 
possible to service various apps with different versions of Python/Django. I 
assumed the server side was python version independent and that the 
requirement for Python similarity was only on the application side in that the 
Python used to create the virtual environment and my app must match the 
version used to create the WSGI interface on the application side (this side 
not the server). That said, I have discovered there is a Python 2.7 version of 
the mod_WSGI for the server side which differs from the 3.7 version.


Can someone clear up the Python version requirement and if it does require a 
match between the server and the app side, how will I be able to run future 
versions of Python/Django apps without having to go back and "recomplie"?


Also if someone has any clues on solving my error that would be very much 
appreciated.


Thanks
Moose
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from thi

Re: Tables missing in SQLite but viewable in admin (confusion)

2021-05-29 Thread Antonis Christofides
The table name by default has the app name prepended; so the table for 
PastSurgicalHistory will be named superhealth_pastsurgicalhistory (assuming that 
your app is named superhealth).


Other than that, I'd make absolutely sure that the database I'm examining with 
the sqlite3 command (or whatever tool you have) is really the same as the one 
that is being read by Django. E.g. move the database file somewhere else (and 
restart Django) and make sure that the data in Django admin is gone.


Antonis Christofides
+30-6979924665 (mobile)


On 29/05/2021 02.56, Ryan Kite wrote:

Greetings!

Am very confused about why the local dev SQLite DB 'appears' to be missing 
several tables.


In the Django Admin they exist and have data.

I would be expecting to see the following tables in the DB but can't find them.
(These are the model names since I don't know what the table name look like 
yet.)

  * Model: Allergies | Table: ?
  * Model: DoctorsAndProviders | Table: ?
  * Model: FamilyContacts | Table: ?
  * Model: PastSurgicalHistory | Table: ?
  * Model: HealthProfile | Table: ?

But, I do see these two models with their tables in the DB

  * Model: Med | Table: meds
  * Model: PastMedicalHistory  | Table: past_med_hx


The application seems to be working for the most part, we can still add and 
remove objects. But was encountering errors when trying to build a ForeignKey 
from the Allergies model to the HealthProfile Model that lives under the Users 
app. The error said something along the lines about the ID did not exist in 
the table? Which caused me to view the DB and notice this.


Any help appreciated :)

screenshots attached.


--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9f7fecd6-b152-4e6d-8a9e-d22508b9d975n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/9f7fecd6-b152-4e6d-8a9e-d22508b9d975n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/7ef773e1-3c6e-86e5-c9c5-f9668daa5439%40antonischristofides.com.


Re: Telnet problem

2021-05-27 Thread Antonis Christofides
Google doesn't officially support using its email service as a smarthost (at 
least not so with free accounts). Therefore some things may be working for a 
time and then they might stop working.


Antonis Christofides
+30-6979924665 (mobile)


On 27/05/2021 14.27, Mostapha Bouderka wrote:

Hi.

I know this isn't django related but I searched everywhere and couldn't find 
any help.
The issue is, in order to send emails using smtp (or even django's send_mail), 
I had to initiate " telnet smtp.gmail.com 587 ", which worked for a while, but 
now I can't get it to work. When I type this command in the terminal, I get 
this error :


Connecting To smtp.gmail.com...Could not open connection to the host, on port 
587: Connect failed


I'm using Windows. Can someone please help me?

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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3ab43b83-eaac-408c-b062-3ac00b8f1ed8n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/3ab43b83-eaac-408c-b062-3ac00b8f1ed8n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/2531164c-d879-7417-3d5a-b11c12c4bc55%40antonischristofides.com.


Re: How can I pass input value to view function without forms

2021-05-27 Thread Antonis Christofides
You have a typo somehwere; in the HTML you have "numbered", whereas in the code 
you have "numberid".


Antonis Christofides
+30-6979924665 (mobile)

On 27/05/2021 13.20, Bhanu prasad Ch wrote:

Hello Boris,
      I was thinking of passing number from the input to view function 
/call_me_when_ten()/

/_index.html_/
...

...
/_
_/
/_views.py_/
def call_me_when_ten(request):
    if request.post == 'POST':
          number = request.POST['numberid']
          if number == 10:
                 print('hello world')
    return render(request,'index.html')

I got this code from StackOverflow, but this isn't worked. Please, help me in 
solving out this problem.


On Wednesday, May 26, 2021 at 5:02:04 AM UTC+5:30 Boris Pérez wrote:

Hi!!! usually HttpResponseRedirects work with reverse
function...something like this
def myview(request):
return HttpResponseRedirect(reverse('arch-summary', args=[1945]))
where 'arch-summary' is the path name and args=[1945] the args it expects...
You need to modify also your urls.py to add tyhe name argument to your 
url...
Greetings

2021-05-25 0:57 GMT-04:00, Bhanu prasad Ch :
> Hello everyone,
> Please help me out in understanding how to pass the redirected view
> with some arguments like userid to connect the URLs in Django
> [image: Screenshot_2.png][image: Screenshot_3.png]
> When I am doing this way it is redirecting to the self page that is login.
> But I need the
> HttpResponseRedirect to redirect to the progress.
>
> --
> 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 view this discussion on the web visit
>

https://groups.google.com/d/msgid/django-users/2ebc28b3-0e99-4ace-9868-aad10564a172n%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/2ebc28b3-0e99-4ace-9868-aad10564a172n%40googlegroups.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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f17dd6c8-4228-46d4-b9f4-fb4059e5d536n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/f17dd6c8-4228-46d4-b9f4-fb4059e5d536n%40googlegroups.com?utm_medium=email_source=footer>.


--
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/9d4b4e6e-dfe1-7195-815c-85df71b94b59%40antonischristofides.com.


Re: Best way to deal with members registration in Django apps

2021-05-25 Thread Antonis Christofides

using Sendmail code that we added in our Django project
You really added sendmail code to your Django project? Or did you configure your 
Django project to use sendmail?


There is no single answer to what you are asking. What I do, and I also propose 
to people to do 
<https://djangodeployment.readthedocs.io/en/latest/07-settings.html>, is:


 * Use a small forward-only local name server, namely the DragonFly Mail Agent
   or dma.
 * Use an external service like Runbox or mailbox.org as a mail server. I think
   that paid Google mail accounts will also work.

As for regularly emailing members, again I'd use an external service such as 
mailchimp, but I have no experience integrating such a service with a Django app.


Antonis Christofides
+30-6979924665 (mobile)


On 25/05/2021 08.02, Ram wrote:

Hi,

We have members registration module where members will enter email ID as a 
login name. Upon submitting the Sign Up form, we generate an email to the 
given email address using Sendmail code that we added in our Django project.


So far we used a personal gmail account as an admin email account to generate 
and send emails to registered members ( as shown below)


EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'  # added by me
EMAIL_HOST = 'smtp.gmail.com <http://smtp.gmail.com>'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'xxad...@gmail.com <mailto:xxad...@gmail.com>'
EMAIL_HOST_PASSWORD = '122hhhlll'
EMAIL_USE_TLS = True


but we need to move on to next step on our development and production servers 
to have a real time admin email to handle member registrations and further 
communication with members, like sending newsletters and some important 
security notifications.


Could you please suggest what you been using with zero issues in your Django 
application?


Best regards,
~Ram


--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BOi5F0C17vnf4vEvZgMYha0b2XB49iZpJ4UzqKb56-Tmar-cQ%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CA%2BOi5F0C17vnf4vEvZgMYha0b2XB49iZpJ4UzqKb56-Tmar-cQ%40mail.gmail.com?utm_medium=email_source=footer>.


--
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/e8186cd2-9a0e-899c-227f-489ae74cf227%40antonischristofides.com.


Re: Making a rather small web app, is Django right for it?

2021-05-24 Thread Antonis Christofides
It's hard to say. While Django /is/ suitable, it's also large. If you don't know 
it already, you might not want to learn it just for this. It's possible Flask 
would be a better choice, since it's smaller and (I think) easier. (Note: I'm a 
Django developer, and I'm not a Flask developer.)


So I think it's mostly a question of what you want: Why do you want to do this 
project? Is it commercial? Is it a hobby? Is it something you do because you 
find it appealing? If it's something like a hobby, pick up whatever seems more 
fun to you.


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)



On 24/05/2021 17.37, Devin Prater wrote:
Hi all. I am a rather new Python learner, although I've made the following 
script:


https://github.com/prater-devin/src/blob/main/lunch/lunch.py 
<https://github.com/prater-devin/src/blob/main/lunch/lunch.py>


I want to turn this into a central place where students can get not just the 
lunch menu, but also other menus, upcoming events, things like that, but not 
much more than that. So, in order to bypass the need for submitting to the App 
Store because this isn't that big of an app, I decided to go with web 
development instead. Since I already know Python, enough to make that simple 
program at least, I thought I'd just use Django to make this.


Now, I've also tried using Beeware to make an actual app, and that seems easy 
compared to getting started with Django, but I don't want to disregard Django 
just because Beeware is easier. Plus Beeware doesn't seem to have web app 
creation support yet. So, any ideas? How hard would it be to take something 
like that simple code, probably for the backend more than frontend, and 
enhance it, mainly adding more requests to a URL, then getting text using BS4, 
then showing it on the app? I imagine tabs at the bottom of the screen for 
"menus", "vending machines", and "events and news." Stuff like that, then the 
main content in the middle, then buttons at the top to change between menu 
sources on the menus tab and such. So, not that much interaction I'd think. 
So, what do you all think? Thanks for any help.


Devin Prater

Technical Assistant


256 761-3423

Alabama Institute for Deaf and Blind

P.O. Box 698 | 1105 Fort Lashley Ave.

Talladega, AL 35161


www.aidb.org <http://www.aidb.org/>

FacebookDiscover how we’re limitless. 
<https://www.facebook.com/AlabamaInstituteforDeafandBlind?ref=notif_t=fbpage_fan_invite>


--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKXtajAeZPSpgZg9a38YtCksi4N7VF51DJYxWAQ1K0P3V%3D-P_A%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAKXtajAeZPSpgZg9a38YtCksi4N7VF51DJYxWAQ1K0P3V%3D-P_A%40mail.gmail.com?utm_medium=email_source=footer>.


--
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/90a0185c-d744-826c-c1b7-d459d23d18a3%40antonischristofides.com.


Re: django utils Integrity error

2021-05-19 Thread Antonis Christofides

Could you show the full error message?

Antonis Christofides
+30-6979924665 (mobile)

On 19/05/2021 02.36, Peter Kirieny wrote:
am adding class category in the models.py and adding it as a foreign key in 
the products model but i get this error while migrating

somebody, please help
here is the code
class Category(models.Model):
 name = models.CharField(max_length=50)

 def __str__(self):
 return self.name


class Product(models.Model):
 name = models.CharField(max_length=200)
 category = models.ForeignKey(Category, on_delete=models.CASCADE)
 price = models.FloatField()
 digital = models.BooleanField(default=False, null=True, blank=True)
 image = models.ImageField(null=True, blank=True)

 def __str__(self):
 return self.name
--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL8t8eqJsenwOmJA%3DO_pdcb8Vk4KnjSijoiUNe5H%3DRpPO6%3D32A%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAL8t8eqJsenwOmJA%3DO_pdcb8Vk4KnjSijoiUNe5H%3DRpPO6%3D32A%40mail.gmail.com?utm_medium=email_source=footer>.


--
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/a3b0ab19-e675-fdeb-04f2-274f2018988b%40antonischristofides.com.


Re: Decoupling Postgres database credentials in django for deployment.

2018-03-30 Thread Antonis Christofides
> Environment variables are the best option for not embedding sensitive
> information in files 
However some people (me that is :-) think that environment variables, though
widely used, are an ugly hack for this problem.


I explain the way I do it (TLDR; production settings must be stored in a
different "deployment" repository, preferably with any secrets encrypted) in
https://www.crowdcast.io/e/deploying-django, from 38m10s to 46m30s.


Regards,


Antonis

Antonis Christofides
http://djangodeployment.com


On 2018-03-30 13:06, PASCUAL Eric wrote:
>
> Hi,
>
>
> Environment variables are the best option for not embedding sensitive
> information in files which have chances to be stored in places such as
> external source repositories (GitHub et al.).
>
>
> If you are working with orchestrators such as Kubernetes, you can use the
> "secrets", which are specialized shared configuration data, stored in
> encrypted form. As shared configuration data, they bring the extra benefit
> over env vars of being manageable from a single central place, and then
> distributed to all the replicas and services which need them.
>
>
> Best regards
>
>
> Eric
>
> 
> *From:* django-users@googlegroups.com <django-users@googlegroups.com> on
> behalf of Andréas Kühne <andreas.ku...@hypercode.se>
> *Sent:* Friday, March 30, 2018 11:08:52 AM
> *To:* django-users@googlegroups.com
> *Subject:* Re: Decoupling Postgres database credentials in django for 
> deployment.
>  
> Hi, 
>
> I am sorry, but this doesn't really make sense. What do you mean by decoupling
> the data? 
>
> Deploying to the cloud, will mean that you will need to setup a new database
> for your project - there you will get a completly new database, that won't be
> connected to your development data in any way. 
>
> You can then add system variables for the username and password for the
> database - and thats about all you need?
>
> Regards,
>
> Andréas
>
> 2018-03-29 22:24 GMT+02:00 prince gosavi <princegosav...@gmail.com
> <mailto:princegosav...@gmail.com>>:
>
> Hi,
> I have made a django project and want to deploy it on cloud.
> Before that i want to decouple all the private information.
> I want to decouple the database info too, like the username password etc.
> Any help is 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit
> 
> https://groups.google.com/d/msgid/django-users/4b09223d-d58f-4fda-b3f7-64b230960d94%40googlegroups.com
> 
> <https://groups.google.com/d/msgid/django-users/4b09223d-d58f-4fda-b3f7-64b230960d94%40googlegroups.com?utm_medium=email_source=footer>.
> For more options, visit https://groups.google.com/d/optout
> <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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/CAK4qSCeZFiw9D7Sa213H_MkPgcH-aTQ3fk-j5HLjZdHK%2B5ps%2BQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK4qSCeZFiw9D7Sa213H_MkPgcH-aTQ3fk-j5HLjZdHK%2B5ps%2BQ%40mail.gmail.com?utm_medium=email_source=footer>.
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@goo

Re: Sample of GeoDjanco websites

2018-03-20 Thread Antonis Christofides
Hello,

I think that much work is done on GeoDjango. I maintain 3 or 4 apps that use it,
if not anything else to show points on a map. I don't claim to be an expert.
I've concluded that GIS is a strange world. Not only blog posts and tutorials
and references, there are also few books and they are mostly lacking. I've used
gdal and OpenLayers and I've been baffled by the lack of documentation.

I can point you to some of my own work, which is by no means complete. First, I
think that anyone dealing with GIS must understand the basics of co-ordinate
reference systems. Even if all you want to do is show points on a map, you will
eventually need to know what the numbers 4326 and 3857 mean. So read my
introduction to geographical co-ordinate systems
<http://antonischristofides.com/2009/10/31/introduction-to-geographical-co-ordinate-systems/>.
My few OpenLayers>=3 writings <https://medium.com/gis-tips> can be useful if
(like me) you are an OpenLayers>=3 beginner. That's all.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2018-03-20 00:14, M Hashmi wrote:
> I've been searching for one from last couple of weeks and after using
> Djnago-map-widgets, django-google-maps, django-forms I came to conclusion that
> no much work done in GeoDjango. All these apps do not work very well with
> everything GeoDjango has to offer.
>
> Only way out for me is that using GoogleAPI Javascript code in templates and
> then create a GET/POST requests to manage user interaction with api. Saving
> that to database based on JS triggers. If you happen to find something please
> let me know as well.
>
> Making a tutorial will help community to great deal coz location aware
> applications are in demand.
>
> Regards,
> Mudassar
>
> On Mon, Mar 19, 2018 at 12:37 PM, Zachary Nickens <znick...@usc.edu
> <mailto:znick...@usc.edu>> wrote:
>
> I’m really interested in this too. Please share if you find anything. 
>
> On Mon, Mar 19, 2018 at 2:28 PM Ezequias Rocha <ezequias.ro...@gmail.com
> <mailto:ezequias.ro...@gmail.com>> wrote:
>
> Hi
>
> I would like to know if there is any list of websites that are using
> GeoDjango on the web.
>
> Could anyone tell me if you have experiences putting Leaflet in the
> frontend and GeoDjango in the backend (geoprocessing).
>
> Sincerely
> Ezequias
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users
> 
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_group_django-2Dusers=DwMFaQ=clK7kQUTWtAVEOVIgvi0NU5BOUHhpN0H8p7CSfnc_gI=tcxwEFWul8EmzesK5dqtHA=HDIEjiVN3JnJ4RZLb5p_rIswZ_ZtDXpVipTWH2L8UW0=eT0OXUyGFTYvakxg-ABKImkRRWzTwU4L-eaeizEAKWw=>.
> To view this discussion on the web visit
> 
> https://groups.google.com/d/msgid/django-users/09ae2680-65d0-4c6e-bb32-9f776a76f138%40googlegroups.com
> 
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_msgid_django-2Dusers_09ae2680-2D65d0-2D4c6e-2Dbb32-2D9f776a76f138-2540googlegroups.com-3Futm-5Fmedium-3Demail-26utm-5Fsource-3Dfooter=DwMFaQ=clK7kQUTWtAVEOVIgvi0NU5BOUHhpN0H8p7CSfnc_gI=tcxwEFWul8EmzesK5dqtHA=HDIEjiVN3JnJ4RZLb5p_rIswZ_ZtDXpVipTWH2L8UW0=ZK7YOasVQJqffkQfEkTomR92l7o5KhlF0WUgA8tmOR0=>.
> For more options, visit https://groups.google.com/d/optout
> 
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_optout=DwMFaQ=clK7kQUTWtAVEOVIgvi0NU5BOUHhpN0H8p7CSfnc_gI=tcxwEFWul8EmzesK5dqtHA=HDIEjiVN3JnJ4RZLb5p_rIswZ_ZtDXpVipTWH2L8UW0=rFTy-3rPQlKc2jCxCZk2E6QeqDt6_AAbtKnkRzaJyjU=>.
>
> -- 
> Fight On!
>
> Zachary Nickens
> znick...@usc.edu <mailto:znick...@usc.edu>
>
> <mailto:znick...@usc.edu>
>
> <mailto:znick...@usc.edu>
>
>
> <mailto:znick...@usc.edu>
> Become a Member of the Wild Sheep Foundation to Put and Keep Wild Sheep on
> the Mountain <https://www.wildsheepfoundation.org/>
>
> -- 
> 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+

Re: Deploying SSL for my Django 2.0.1 server with Apache on Ubuntu 16.04 (droplet)

2018-01-27 Thread Antonis Christofides
>
> But the following is still saying, “Forbidden”:
>
>
> https://www.angeles4four.info/static/admin/
>
This is normal. The reason is not the filesystem permissions, but that Apache is
configured to not list files inside that directory (to change that you'd need to
use "Options Indexes" somewhere, but you don't want to change that). You can
still access any file in that directory, but it will not tell you which files
are available. This is the correct thing to do.

> ...
>
> drwxrwxr-x  5 tranq www-data  4096 Jan 25 23:12 cel2fah
>
>
> Does this look right to all of you?
>
It's OK, though it could be better. Apache only needs to read that directory,
not write it. Apache is user www-data and group www-data, and this directory is
writeable by group www-data, that is, writeable by Apache. So better permissions
for that would be drwxr-xr-x (which you can achieve with "chmod 755 cel2fah" or
"chmod g-w cel2fah").

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2018-01-27 07:20, drone4four wrote:
>
> The username on my droplet is ‘tranq’ but there is a line in both my vhost
> config files which reads:
>
>
> 
>
>
> So I swapped out ‘user’ for ‘tranq’. That line now reads:
>
>
> 
>
>
> Now some of my static files are accessible.  For example you can see here:
>
>
> https://www.angeles4four.info/static/admin/css/responsive.css
>
> https://www.angeles4four.info/static/admin/css/login.css
>
>
> But the following is still saying, “Forbidden”:
>
>
> https://www.angeles4four.info/static/admin/
>
>
> This may be pointing to an issue I noticed with how my user and group
> permissions are set up for Django.  The sqlite.db file was grouped in with
> ‘tranq’. According to the guide I’ve been using, it should be: ‘www-data’.
>  I’m not sure how I overlooked this mistake because I very clearly remember
> doing it properly.  I think I’m conflating this with one of my multiple recent
> previous attempts following this guide. Anyways, here is what my group
> permissions look like now from within my project directory:
>
>
> $ ls -la
>
> total 68
>
> drwxrwxr-x  5 tranq www-data  4096 Jan 25 23:12 .
>
> drwxr-xr-x 18 tranq tranq 4096 Jan 26 21:57 ..
>
> drwxrwxr-x  3 tranq tranq 4096 Jan 25 23:13 cel2fah
>
> -rw-rw-r--  1 tranq www-data 38912 Jan 25 23:11 db.sqlite3
>
> -rwxrwxr-x  1 tranq tranq  539 Jan 25 23:05 manage.py
>
> drwxrwxr-x  3 tranq tranq 4096 Jan 25 23:12 static
>
> drwxrwxr-x  5 tranq tranq 4096 Jan 25 23:04 venv
>
>
> Notice sqlite.db above? It now says ‘www-data’.  This is how it should be, 
> right?
>
>
> The parent directory (home user folder) shows these permissions for my 
> project:
>
>
> ...
>
> drwxrwxr-x  5 tranq www-data  4096 Jan 25 23:12 cel2fah
>
>
> Does this look right to all of you?
>
>
> The steps I took to arrange the permissions as such were from the bottom of
> the mod_wsgi guide on DigitalOcean
> <https://www.google.ca/url?sa=t=j==s=web=3=0ahUKEwjJ_d_P0OfYAhVlxoMKHZlBBkEQFgg0MAI=https%3A%2F%2Fwww.digitalocean.com%2Fcommunity%2Ftutorials%2Fhow-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04=AOvVaw2wt2StyReKq9zmPyQnkrO7>which
> I referred to initially.
> Thanks for your attention.
> On Friday, January 26, 2018 at 1:21:07 AM UTC-5, drone4four wrote:
>
> You’re right, @Antonis, that I don’t want my Django source code exposed.
> No sysadmin would.  I have since moved my Django project folder to my home
> user’s directory. However (out of curiosity), if I continued to house
> Django in my public_html folder (which I am not any more, but say if i
> did) I would think that my .htaccess config file would prevent
> unauthorized access to my Django source.  Am I right?
>
>
> I didn’t realize that Django was suppose to be run using wsgi.  I was just
> foolishly running the server with ``$ python manage.py runserver
> 0.0.0.0:8000`` like when I was testing locally when I was coding my app.
> The keyword here is mod_wsgi.  So I found this guide
> 
> <https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04>.
> I followed along but the issue I now have is that Apache serves my
> public_html folder (just some light  HTML, CSS and Js).  Serving these
> contents take priority over Django.  I’m OK with this. I would prefer to
> keep my public_html folder accessible as it is, but how do I arrange for
> wsgi to serve Django from a subdirectory, say:
> www.angeles4four.info/cel2fah <http://www.angeles4four.info/cel2fah>or
> someth

Re: Contributing to Django

2018-01-25 Thread Antonis Christofides
Hello,

Yes, I believe you have it right. In the documentation there's a "How to get
involved" section that describes all the details, but they're too many to take
in, so you will need some help anyway. You will receive better help for such
questions in the django-developers list and in the django developers irc 
channel.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2018-01-25 09:35, 'Anoosha Masood Keen' via Django users wrote:
> Hi,
>    I have assigned a ticket to myself. Now what do I need to do ? Fork django
> project and create branch for that ticket and push it ? Am I right?
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/6e715641-d6aa-4cdd-8ba4-a2f0a4f57fc2%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/6e715641-d6aa-4cdd-8ba4-a2f0a4f57fc2%40googlegroups.com?utm_medium=email_source=footer>.
> 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/a9073653-99a2-a96c-fb49-7764993a1924%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: PostrgreSQL Inside Virtualenv

2018-01-25 Thread Antonis Christofides
Hello,

as many people have said, you can't install PostgreSQL in a virtualenv (but you
can install the Python package for connecting to PostgreSQL (such as psycopg2)
in a virtualenv). Maybe my article virtualenv demystified
<https://djangodeployment.com/2016/11/01/virtualenv-demystified/> could clear up
some confusion as to what a virtualenv is and what it does.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2018-01-24 18:56, johnf wrote:
>
> I doubt it is possible to install Postgres into virtualenv??? 
>
> At least I'm not aware that it can be done.  I'll do a little research and see
> if I can be done.  Of course it can be installed on VM.
>
> Johnf
>
>
> On 01/24/2018 02:25 AM, tango ward wrote:
>> Noted. Thanks
>>
>> On Wed, Jan 24, 2018 at 5:56 PM, Avraham Serour <tovm...@gmail.com
>> <mailto:tovm...@gmail.com>> wrote:
>>
>> In any case you'll need to pip install the postgres drivers for python, I
>> suggest doing that inside the env
>>
>>
>> On Wed, Jan 24, 2018 at 11:32 AM, tango ward <tangowar...@gmail.com
>> <mailto:tangowar...@gmail.com>> wrote:
>>
>> Got it. Thanks Anoosha
>>
>> On Wed, Jan 24, 2018 at 5:29 PM, 'Anoosha Masood Keen' via Django
>> users <django-users@googlegroups.com
>> <mailto:django-users@googlegroups.com>> wrote:
>>
>> Install it on your computer.
>>
>> On Wednesday, January 24, 2018 at 8:49:17 AM UTC, tangoward15 
>> wrote:
>>
>>
>> Hi,
>>
>>
>> Newbie question, since I installed django and pillow inside
>> virtualenv, shall I also install PostgreSQL inside
>> Virtualenv? At the moment I am still using SQLite in my pet
>> project.
>>
>>
>> Regards,
>> Jarvis
>>
>>
>> -- 
>> 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
>> <mailto:django-users+unsubscr...@googlegroups.com>.
>> To post to this group, send email to
>> django-users@googlegroups.com 
>> <mailto:django-users@googlegroups.com>.
>> Visit this group at https://groups.google.com/group/django-users
>> <https://groups.google.com/group/django-users>.
>> To view this discussion on the web visit
>> 
>> https://groups.google.com/d/msgid/django-users/962726a2-e3b3-4ee1-b81b-c1227656b7da%40googlegroups.com
>> 
>> <https://groups.google.com/d/msgid/django-users/962726a2-e3b3-4ee1-b81b-c1227656b7da%40googlegroups.com?utm_medium=email_source=footer>.
>>
>>
>> For more options, visit https://groups.google.com/d/optout
>> <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
>> <mailto:django-users+unsubscr...@googlegroups.com>.
>> To post to this group, send email to django-users@googlegroups.com
>> <mailto:django-users@googlegroups.com>.
>> Visit this group at https://groups.google.com/group/django-users
>> <https://groups.google.com/group/django-users>.
>> To view this discussion on the web visit
>> 
>> https://groups.google.com/d/msgid/django-users/CAA6wQLKYD2z4dvuxESSp67CSiDDOttMJuGxizhFHyVRhA%2BHq6w%40mail.gmail.com
>> 
>> <https://groups.google.com/d/msgid/django-users/CAA6wQLKYD2z4dvuxESSp67CSiDDOttMJuGxizhFHyVRhA%2BHq6w%40mail.gmail.com?utm_medium=email_source=footer>.
>>
>> For more options, visit https://groups.google.com/d/optout
>> <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
>> <mailto

Re: Strange the global variable behavior

2018-01-23 Thread Antonis Christofides
Global variables might work with runserver (because it starts threads, not
processes, but I'm not certain about that so please correct me), but they're
unlikely to work in production, because typically Django is run as at least two
WSGI processes.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2018-01-24 02:51, Costja Covtushenko wrote:
> Hi,
>
> Sorry for asking but how exactly you decided that those `global` variables was
> not updated?
>
> Regards,
> C
>
>> On Jan 23, 2018, at 6:47 AM, Максим Королёв <maxcoo...@gmail.com
>> <mailto:maxcoo...@gmail.com>> wrote:
>>
>> Hi there.
>> Could someone explain what happens. I had a little project on Python 2.7 and
>> decided to move it on 3.6. Everything has gone by perfectly. The project
>> works well as before but there is one exception noticed by me: the global
>> statement works not always. The code below doesn't update the global variable
>> zip_file_name and I can't grasp why. Any suggestions.
>>
>> zip_file_name = os.path.join(MEDIA_ROOT, 'wb`s.zip')
>> file_list = []
>>
>>
>> @permission_required("wb_search.change_wbsearch", login_url='access_denied')
>> @csrf_exempt def input_data_form(request):
>> global zip_file_name, file_list
>> if request.method == 'POST':
>> form = WbSearchForm(request.POST)
>> if form.is_valid():
>> text = request.POST['wbs_nums']
>> picked = form.cleaned_data.get('category')
>> try:
>> wb_nums = process_input(text, LENGTH_OF_STR_TO_PROCESS)
>> zip_file_name, file_list = get_wb_pdf_as_zip(wb_nums, picked)
>> m = SearchHistory(user=str(request.user), 
>> curr_date=datetime.now(), list_desired_docs=', '.join([str(rec[0]) for rec 
>> in file_list]))
>> m.save()
>> return HttpResponseRedirect('/wb_search/search_finished/')
>> except NoDataToSearch:
>> return 
>> HttpResponseRedirect('/wb_search/wb_search_incorrect_data/')
>> else:
>> return 
>> HttpResponseRedirect('/wb_search/wb_search_incorrect_data/')
>> else:
>> form = WbSearchForm()
>> # context = context.update(csrf(request)) return 
>> render_to_response('wb_search_input_data_form.html',
>>   {'form': form, 'title': 'Номера для поиска',
>>'header': 'Поиск PDF файлов вэйбилов',
>>'text': 'Вставте в это поле номера вэйбилов 
>> PDF файлы которых необходимо найти.',
>>'textarea_title': 'Вставте в это поле номера 
>> вэйбилов PDF файлы которых необходимо ' 'найти.',
>>'submit_title': 'Начать поиск',
>>'element_id': 'find_button', 
>> 'element_method': 'click',
>>'spinner_message': 'Ожидайте окончания 
>> поиска...', },
>>   RequestContext(request))
>>
>> -- 
>> 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
>> <mailto:django-users+unsubscr...@googlegroups.com>.
>> To post to this group, send email to django-users@googlegroups.com
>> <mailto: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/e833541c-0b75-486c-a06e-5aa8ccb5d446%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/e833541c-0b75-486c-a06e-5aa8ccb5d446%40googlegroups.com?utm_medium=email_source=footer>.
>> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/3DB54166-0F6B-4F44-9DB1-05BFE47D578F%40gmail.com
> <https://groups.goo

Re: Deploying SSL for my Django 2.0.1 server with Apache on Ubuntu 16.04 (droplet)

2018-01-21 Thread Antonis Christofides
Hello,

I'm not certain I understand what you are describing. Is Apache listening on
port 8000? How is it possible that you are using "runserver" when you are
running Django through mod_wsgi? Something is wrong there.

Also, don't put your Django app's files in public_html or any other directory
that is publicly served by Apache. You don't want visitors from the web reading
your source code (or, much worse, your settings file with its secrets). If you
haven't done this before you may be confused by static files, in which case this
article (of mine)
<https://djangodeployment.com/2016/11/21/how-django-static-files-work-in-production/>
may help.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2018-01-21 05:00, drone4four wrote:
> I’ve played with a little Django (v2.0.1) locally. Now I am trying to
> implement a test case on my production Apache web server. I’m running an
> Ubuntu 14.04 DigitalOcean droplet (will upgrade to 18.04 later this year).
>
> I got Django running.
>
> Here it is: http://www.angeles4four.info:8000/
>
> Before I log into my admin panel, I figure it’s best practices to set up HTTPS
> first. But when I visit that URL, Chrome throws this message:
>
>
> This site can’t provide a secure connection http://www.angeles4four.info
> sent an invalid response. ERR_SSL_PROTOCOL_ERROR
>
>
> And my shell on my server shows this message:
>
> [20/Jan/2018 23:54:39] "GET / HTTP/1.1" 200 16559 [21/Jan/2018 00:01:23]
> code 400, message Bad request syntax
> 
> ('\x16\x03\x01\x00Ì\x01\x00\x00È\x03\x03&6U\x10µ\x82\x97\x7f´8\x1e«\x0e¿ÿ§\x89æ\x82\r¢G§\x01ç°P%\x80)ÕÃ\x00\x00\x1c
> * À+À/À,À0̨̩À\x13À\x14\x00\x9c\x00\x9d\x00/\x005\x00') [21/Jan/2018
> 00:01:23] *You're accessing the development server over HTTPS, but it only
> supports HTTP.*
>
>
> That’s because SSL isn’t set up. My current SSL Certificate Authority is Let’s
> Encrypt. SSL is running properly for my public_html content but not for my
> recent deployment of Django.
>
> I found some resources elsewhere on SO for setting up SSL with Django.
>
> In an SO post titled, “Configure SSL Certificate on Apache for Django
> Application (mod_wsgi)”, a highly upvoted answer by Alexey Kuleshevich
> suggests a template for 000-default.conf and default-ssl.conf for Apache
> vhosts. See here: Configure SSL Certificate on Apache for Django Application
> (mod_wsgi)
> <https://stackoverflow.com/questions/32812570/configure-ssl-certificate-on-apache-for-django-application-mod-wsgi>
>
> I did my best to change up the suggested values and entries so that they refer
> to my specific configuration. Here are what these two vhost configuration
> files of mine look like now.
>
> /etc/apache2/sites-available/angeles4four.info-le-ssl.conf:
>
> |
> 
> <VirtualHost*:443>
> #ServerName http://www.example.com
> ServerAdmin coffee.drinker.dan...@gmail.com
> ServerName angeles4four.info
> ServerAlias http://www.angeles4four.info
> DocumentRoot /var/www/html/angeles4four.info/public_html
>
>
> ErrorLog ${APACHE_LOG_DIR}/error.log
> CustomLog ${APACHE_LOG_DIR}/access.log combined
>
>
> # Django Application
> Alias /static /var/www/html/angeles4four.info/public_html/Cel2FahConversion
> 
> Require all granted
> 
> 
> 
> Require all granted
> 
> 
> WGIDaemonProcess cel
> python-path=/var/www/html/angeles4four.info/public_html/Cel2FahConversion/venv/bin/python3
> WSGIProcessGroup cel
> WSGIScriptAlias /
> /var/www/html/angeles4four.info/public_html/Cel2FahConversion/Cel2FahConversion/Cel2FahConversion/wsgi.py
>
>
> SSLCertificateFile /etc/letsencrypt/live/angeles4four.info/cert.pem
> SSLCertificateKeyFile /etc/letsencrypt/live/angeles4four.info/privkey.pem
> Include /etc/letsencrypt/options-ssl-apache.conf
> SSLCertificateChainFile /etc/letsencrypt/live/angeles4four.info/chain.pem
> 
> 
> |
>
>
> angeles4four.info.conf:
>
> |
> Quote:
> <VirtualHost*:80>
>
>
> #ServerName http://www.example.com
> serveradmincoffee.drinker.dan...@gmail.com
> ServerNameangeles4four.info
> ServerAliashttp://www.angeles4four.info
> DocumentRoot/var/www/html/angeles4four.info/public_html
> <Directory"/var/www/html/angeles4four.info/public_html">
> OptionsIndexesFollowSymlinks
> AllowOverrideAll
> Requireall granted
> 
>
>
> ErrorLog ${APACHE_LOG_DIR}/error.log
> CustomLog${APACHE_LOG_DIR}/access.log combined
>
>
> RewriteEngineon
> RewriteCond%{SERVER_NAME}=angeles4four.info [OR]
> RewriteCond%{SERVER_NAME}=www.angeles4four.info
> RewriteRule^https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
> 
> |
>
> No dice. I still get the same t

Re: Is CSRF middleware to be taken seriously (from a XSRF point of view)?

2018-01-15 Thread Antonis Christofides
Hi,

> 1) Write a script that just harvests the middleware token from a form
> "protected" with such token and use the value of that as the csrftoken cookie.

You visit web site A (the attacker). Web site A wants to send a malicious POST
request to site D (a Django app). The thing is that scripts of web site A don't
have access to forms of site D, so they can't get the csrf token.

> 2) Learn the easy cipher algorithm the csrf middleware uses and present a csrf
> token cookie that will decode to the right value.

This is not possible. You can't decode such ciphered messages. If S is the
original message and C = F(S) the ciphered message, you can't reverse the
function and find S given C.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2018-01-16 00:03, Stephan Doliov wrote:
> Just curious, I recently went on a source code studying binge and took a look
> at the CSRF middleware that comes with Django. I appreciate the work and
> effort of the authors, but I am not sure I gain anything by deploying it to my
> site. Here is why:
> The middleware token assigned to a form and to a csrftoken cookie are
> ciphertexts of the same underlying key (by default, the underlying key is
> chosen as 32 randomly chosen (with replacement) chars from a set of 62 chars.
> So the easy workaround can be done in one of two ways
>
> 1) Write a script that just harvests the middleware token from a form
> "protected" with such token and use the value of that as the csrftoken cookie.
> As the middlewaretoken is a cipher of the underlying token, obviously using
> the the same string as the value to the csrftoken cookie will satisfy the
> middleware's demand for authorization of the resource (e.g. POSTing to the 
> form)
>
> 2) Learn the easy cipher algorithm the csrf middleware uses and present a csrf
> token cookie that will decode to the right value.
>
> In either case, I am not convinced that meaningful protection against CSRF
> types of requests are provided by the middleware. Am I missing something?
>
> Wouldn't it be more secure to just have middleware that whitelists as a series
> of origins (aka CORS) and then, unlike CORS, actually perform reverse lookups
> on the dns of the whitelisted domains? (Of course, this assumes that the hosts
> that might want to make cross-site requests ahve access to managing their
> reverse DNS).
>
> Am I missing something; or, if serving performance is a top goal of mine,
> should I just ditch the csrf middleware? (and maybe rate limit client requests
> to prevent DoS attacks)?
>
> Thanks,
> Steve
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/9c4a794f-aa9e-4c00-ba20-779ad7a87d2a%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/9c4a794f-aa9e-4c00-ba20-779ad7a87d2a%40googlegroups.com?utm_medium=email_source=footer>.
> 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/77523ef5-0f2f-fff3-5c96-4fcaa9b210b3%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Running 2 django project in different port number at the same time.

2018-01-15 Thread Antonis Christofides
Hello,

DATABASES['...']['PORT'] is the port to which the database server is listening
(your django app is a client of the database, and it connects to that port in
order to access the database); it has nothing to do with what you want.

AFAIK specifying the port number in "runserver" is the only way to do what you
want in development.

Production is a whole another story.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2018-01-16 06:31, cherngyo...@gmail.com wrote:
> As what the title said, is it possible to run 2 django project at the same 
> time ?
>
> My task is this:
>  Integration of django 1 api and django 2 api, to setup two django app, on
> same server / PC, with different port
>
>
> As far from what i know, i can change the port number in the settings.py
> database section.
>
> DATABASES = {
>     'default': {
>         'ENGINE': 'django.db.backends.postgresql',
>         'NAME': 'Project',
>         'USER': 'admin',
>         'PASSWORD': 'pass1234',
>         'HOST': 'localhost',
>         'PORT': '',
>     }
> }
>
> Do i change the port number here ? As default is http://127.0.0.1:8000/
>
> So i change the 'PORT': '8001', but got this error instead:
> could not connect to server: Connection refused (0x274D/10061)
>         Is the server running on host "localhost" (127.0.0.1) and accepting
>         TCP/IP connections on port 8001?
>
> Is there a way to set it up so i can run 2 different django project with
> different port number ?
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/ae611f43-645f-42a9-a78b-a9ef6fd22eb7%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/ae611f43-645f-42a9-a78b-a9ef6fd22eb7%40googlegroups.com?utm_medium=email_source=footer>.
> 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/718e9b54-4f60-ea89-1490-2a36d225ce9e%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Deprecations not listed within release notes

2018-01-15 Thread Antonis Christofides
Hello,

was custom_sql_for_model ever documented in the Django documentation? If not,
then it is (or was) an internal API. Internal APIs can change without notice,
and if you use them you do so at your own risk.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2018-01-15 14:16, Murat Sert wrote:
> There are some deprecations such as the custom_sql_for_model and couple of
> other methods within django.core.management.sql file which isn't listed on any
> of the release notes 1.8/1.9/1.11 or deprecation timeline.
>
> Does anyone know if there methods are deprecated or moved elsewhere?
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/aba23083-90dc-4204-9316-aacc5ae50b4c%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/aba23083-90dc-4204-9316-aacc5ae50b4c%40googlegroups.com?utm_medium=email_source=footer>.
> 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/4bee90a4-27f2-2399-ce93-298af8e4775d%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding Junk code to your django project

2018-01-11 Thread Antonis Christofides
Hello,

Instagram is written in Django; however when you use Instagram you can't see or
modify the code, can you? Same thing in every web application, whether written
in RoR, PHP, Java, whatever.

So what exactly do you mean? What is the "user" of your code? Why would the user
be able to read/modify your code in the first place?

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2018-01-11 07:58, ashish.bha...@exponentiadata.com wrote:
> Hello,
> I have a requirement which says that the user should not be able to
> read/modify my code.I thought to add some junk code to the project
> is it possible??
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/b0ca1234-ec4e-41e2-8e20-de87651d1b36%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/b0ca1234-ec4e-41e2-8e20-de87651d1b36%40googlegroups.com?utm_medium=email_source=footer>.
> 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/d7d47123-8da8-f434-c42f-20b3de08a065%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: varchar and text

2018-01-10 Thread Antonis Christofides
Hello,

this is an RDBMS question, not a django question, so if you search the web
without including "django" in the search you will probably get the answer. For
example, I'm searching with "difference between varchar and text" and it returns
nice results (most about MySQL, but in PostgreSQL the principles are the same,
although the details might differ).

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2018-01-10 12:36, Rakhee Menon wrote:
> Hello!!!
> I am using django with postgresql..
> I am just not getting the difference between varchar and text..
> Can someone clear my doubt??
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/102891a1-b5d7-4738-9506-a78bcdba304f%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/102891a1-b5d7-4738-9506-a78bcdba304f%40googlegroups.com?utm_medium=email_source=footer>.
> 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/11ef795f-3d80-8df4-159c-007d7ee2196d%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Handling secret keys in digitalocean

2018-01-10 Thread Antonis Christofides
Hello,

this is actually a big question that is a pain for lots of people. The other
time I held a webinar and I spent some time on this; if you are interested it's
at https://www.crowdcast.io/e/deploying-django, and together with the related
question about different settings in development vs. deployment, I start
treating this issue at 38m10s.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2018-01-10 11:34, yingi keme wrote:
> I am aware that its a bad idea to put your secret keys and other API keys in 
> your settinggs.py file. 
>
> In a production environment like for instance hosting your site in 
> digitalocean, where will you have to store your secret keys. And how will you 
> load it in your settings.py file.?
>
> I am a newbie when it comes to deploying, anyhelp will please.!!!
>

-- 
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/3273cbef-5b12-4ed5-0378-0dcf4f85c6c6%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Antonis Christofides
Ah, OK, sorry I didn't read all the discussion. So I guess that if you keep that
in a global variable, it won't work if your Django app is running in many
processes. (Besides, global variables are rarely a good idea.)

If I understand the problem correctly, what I would do would probably be to
touch a file whenever I make a change and examine the file modification date
each time—if it's more recent than last time I checked, the data has been 
modified.

Another option is to use the cache. For example, use memcached and store some
data in there. IIRC the cache is shared among all instances of Django.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2018-01-09 00:00, Kasper Laudrup wrote:
> Hi Antonis,
>
> On 2018-01-08 22:46, Antonis Christofides wrote:
>> OK, but why do you need this? What functionality is this going to have?
>>
>
> As I wrote in my original question, I'm attempting to write a Django
> application for managing DHCP leases and DNS entries.
>
> So, if a user changes an entry by modifying a model in Django, I need to
> update some external files and restart a process so the new files will be 
> reread.
>
> I might be approaching this the wrong way, but I would really like my Django
> application to "own" this process, so I would like a global instance of that
> which I could start/restart/kill from my Django application.
>
> I'm perfectly open for other ways to solve this, it just seemed like a fairly
> obvious way to do it, but I could very well be wrong.
>
> Thanks a lot and kind regards,
>
> Kasper Laudrup
>

-- 
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/a504b4ac-1ee8-b39d-21a5-dc9042fef25e%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Antonis Christofides
OK, but why do you need this? What functionality is this going to have?

Antonis Christofides
http://djangodeployment.com

On 2018-01-08 23:43, Kasper Laudrup wrote:
> Hi Antonis,
>
> On 2018-01-08 22:10, Antonis Christofides wrote:
>> Hello,
>>
>> When you say "call [an instance of an object]", what exactly do you mean?
>>
>
> Sorry, I meant an instance of a class or just an object.
>
>> Could you tell us more about what this class/object is and why you need to
>> "call" (access?) it in an unusual way?
>>
>
> Nothing unusual about the class or object, sorry about the confusion.
>
> My question is probably fairly simple and I'm really sorry if there's
> something very basic that I'm missing.
>
> I want to create an instance of some class when the Django application I'm
> creating is ready (eg. by connecting to the ready() signal or similar) and
> then be able to call methods on that single instance from my models.
>
> Thanks a lot for the help so far.
>
> Kind regards,
>
> Kasper Laudrup
>

-- 
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/aca7b60d-3aa5-a711-8ab1-cb36a538895a%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Antonis Christofides
Hello,

When you say "call [an instance of an object]", what exactly do you mean?

Could you tell us more about what this class/object is and why you need to
"call" (access?) it in an unusual way?

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2018-01-08 22:02, Kasper Laudrup wrote:
> Hi again,
>
>>
>>     So my question is more related to any kind of process that should be
>>     managed from a Django app.
>>
>>
>> Django does not manages processes, Django is a web framework. Python can
>> manage processes. What kind? Any :)
>>
>
> I am fully aware of that, thank you :-)
>
> I guess my question is then actually more: if I would like to have one single
> instance of an object that I can call safely from models (or possibly views or
> whatever) where would be the right place to put that class and code?
>
> It seems like a fairly basic question, but I haven't found any obvious
> solution for that by reading the documentation, so maybe I'm just missing
> something basic? I must admit my experience with Django (although a good one)
> is fairly limited.
>
> Thanks a lot for your help so far.
>
> Kind regards,
>
> Kasper Laudrup
>

-- 
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/374499b1-76b0-654a-92dd-e506523fc1a4%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Constant Invalid HTTP_HOST header spam

2017-12-19 Thread Antonis Christofides
So nginx chooses the "server {}" block that contains "default_server" to choose
the SSL certificate, and after it receives the headers it choose another "server
{}" block as needed? If that is the case, you can create another "server {}"
block with "default_server" (usually this is somewhere like
/etc/nginx/sites-available/default) that shall contain the certificate and
always return 404.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-12-19 14:18, Jon Ribbens wrote:
> On Tuesday, 19 December 2017 07:24:23 UTC, Antonis Christofides wrote:
>
> I may be wrong of course, but I don't recall SNI having anything to do
> with it. Just using something like
>
> server {
> listen 80;
> listen 443 ssl;
> server_name my.django.site.com <http://my.django.site.com>;
> ...
> }
>
> will only send requests for my.django.site.com <http://my.django.site.com>
> to the django project. I really don't know about SNI, but I recall having
> used SSL on Apache before SNI existed and I don't remember any difference
> with respect to that. Why does SNI affect this?
>
>
> Because unless I'm misremembering something, if you /don't/ add default_server
> to the listen directive then requests without SNI will not end up being served
> the desired SSL certificate, but if you /do/ add default_server then requests
> with the wrong/missing/IP-literal Host: header will end up going to Django,
> which is what we wanted to avoid.
>
> I guess I'll just have to decide which of lack-of-SNI support and
> alerting-on-wrong-Host I want to lose.
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/bf3e62f2-2584-4a28-8680-5cb83dd88753%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/bf3e62f2-2584-4a28-8680-5cb83dd88753%40googlegroups.com?utm_medium=email_source=footer>.
> 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/7d3d97b1-c6e0-6a84-1f7c-573d80862650%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Constant Invalid HTTP_HOST header spam

2017-12-18 Thread Antonis Christofides
I may be wrong of course, but I don't recall SNI having anything to do with it.
Just using something like

server {
listen 80;
listen 443 ssl;
server_name my.django.site.com;
...
}

will only send requests for my.django.site.com to the django project. I really
don't know about SNI, but I recall having used SSL on Apache before SNI existed
and I don't remember any difference with respect to that. Why does SNI affect 
this?

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-12-19 02:05, Jon Ribbens wrote:
> On 18 Dec 2017, at 23:26, Antonis Christofides <anto...@djangodeployment.com
> <mailto:anto...@djangodeployment.com>> wrote:
>>
>> the documentation describes how to silence this error at
>> https://docs.djangoproject.com/en/2.0/topics/logging/#django-security.
>>
>
> It’s not obvious from that how to silence it only for IP literals. I’d still
> like to receive it for actual unknown hosts.
>>
>> How have you deployed your Django project? I always configure Apache or nginx
>> in such a way so that such invalid requests never reach Django.
>>
> A couple of weeks. The nginx configuration idea is a good one, although I was
> trying to allow the site to work without SNI, but it’s probably not vital.
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/11A18532-A2F4-4F02-AA24-9B6AD9C90DE2%40gmail.com
> <https://groups.google.com/d/msgid/django-users/11A18532-A2F4-4F02-AA24-9B6AD9C90DE2%40gmail.com?utm_medium=email_source=footer>.
> 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/79f09932-3ca0-fd19-505c-47563f1cd08a%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Constant Invalid HTTP_HOST header spam

2017-12-18 Thread Antonis Christofides
Hello Jon,

the documentation describes how to silence this error at
https://docs.djangoproject.com/en/2.0/topics/logging/#django-security.

How have you deployed your Django project? I always configure Apache or nginx in
such a way so that such invalid requests never reach Django.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-12-18 21:44, Jon Ribbens wrote:
> I'm getting spammed with constant "Invalid HTTP_HOST header: '10.9.8.7:443'.
> You may need to add '10.9.8.7' to ALLOWED_HOSTS" emails, due to the Internet
> being the Internet. How can I disable these emails, without turning off error
> emails completely? I don't particularly want to add the IP address to the
> ALLOWED_HOSTS. It seems to me this email shouldn't be being generated if the
> HTTP_HOST value is an IP literal.
>
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/0f07d6ca-626c-4887-86e5-a5d10190bc49%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/0f07d6ca-626c-4887-86e5-a5d10190bc49%40googlegroups.com?utm_medium=email_source=footer>.
> 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/cb07e237-4a1b-7677-f758-f08ac6856d27%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why get "Server Error 500" instead of 404 template?

2017-12-11 Thread Antonis Christofides
Hello,

Usually when you get a mere "Server error 500" without it showing you the Debug
page though you have DEBUG=True, this means that the error occurs very early,
before Django has had the opportunity to run. In that case, the error should
have been logged in the gunicorn/uwsgi/whatever log, i.e. in whatever program it
is that runs Django.

For more information, you need to show us your nginx configuration and your wsgi
server configuration.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2017-12-10 18:42, Chris Seberino wrote:
> I cannot track down why 404 page isn't being used.  I can't get any help from
> syslog or Nginx log files.
> I tried adding DEBUG=True to settings.py and still no clues.
> I only get "Server Error 500".
>
> Here is settings.py
>
> TEMPLATES        = [{"BACKEND" :
>                         "django.template.backends.django.DjangoTemplates",
>                      "DIRS"    : [VIEWS.format(e) for e in APPS],
>                      "OPTIONS" :
>                         {"context_processors" :
>                          ["django.template.context_processors.debug",
>                           "django.template.context_processors.request"]}}]
> MIDDLEWARE       = ["django.middleware.security.SecurityMiddleware",
>                     "django.contrib.sessions.middleware.SessionMiddleware",
>                     "django.middleware.common.CommonMiddleware",
>                     "django.middleware.csrf.CsrfViewMiddleware",
>                     "django.contrib.auth.middleware.AuthenticationMiddleware",
>                     "django.contrib.messages.middleware.MessageMiddleware",
>                     "django.middleware.clickjacking.XFrameOptionsMiddleware"]
> WSGI_APPLICATION = "nginx.wsgi.application"
> INSTALLED_APPS   = APPS + ["django.contrib.admin",
>                            "django.contrib.auth",
>                            "django.contrib.contenttypes",
>                            "django.contrib.messages",
>                            "django.contrib.sessions",
>                            "django.contrib.staticfiles"]
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/977652c4-f86e-491c-a5af-ccbba38dc733%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/977652c4-f86e-491c-a5af-ccbba38dc733%40googlegroups.com?utm_medium=email_source=footer>.
> 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/b01b12c2-91c4-086c-c290-bc6ad46727b4%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: memory leak in django app?

2017-12-06 Thread Antonis Christofides
The "SSL handshake failed" doesn't seem related to the alleged memory leak.

Now, you say you have this problem only in production. If you restart uwsgi,
does memory usage go immediately up? Does it go after a few requests? How many
requests? Do you have the same data in development and production? If, for
example, your app loads a whole db table in memory, and this db table has a
million records in production and only a few in development, there would be a
difference.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-12-06 19:38, Etienne Robillard wrote:
> Hi Antonis,
>
> My development server appears unaffected by this problem. Plus I can get heap
> stats using guppy, which is pretty cool. :)
>
> Both my production and development servers have __debug__ enabled in Python
> 2.7.13.
>
> However when using ab -c 100 to benchmark my nginx server I get:
>
> SSL handshake failed (1).
>
> Do you have any ideas how to configure nginx to allow a minimum of 100
> concurrent connections when using SSL encryption?
>
> I have worker_connections set to 512 in my nginx.conf
>
> Regards,
>
> Etienne
>
>
> Le 2017-12-06 à 12:17, Antonis Christofides a écrit :
>> Does this happen only in production? What about when you run a development
>> server? What is the memory usage of your development server?
>>
>> Antonis Christofides
>> http://djangodeployment.com
>>
>>
>> On 2017-12-06 15:05, Etienne Robillard wrote:
>>> Hi Antonis,
>>>
>>> Thank you for your reply. I installed the htop utility and found that 2 of 
>>> my
>>> 4 uWSGI processes are using 882M (42.7%) of resident memory each. Theses two
>>> processes takes about  (85%) of the available RAM memory! That can explain 
>>> why
>>> I get "out of memory" errors when no more memory is available for sshd.
>>>
>>> I tried to debug memory allocation with guppy following instructions here:
>>> https://www.toofishes.net/blog/using-guppy-debug-django-memory-leaks/
>>>
>>> But I get "hp.Nothing" when I attempt to get the heap stats from the master
>>> uWSGI process.
>>>
>>> Example:
>>>>>> hp.setref()
>>>>>> hp.heap()
>>> hp.Nothing
>>>
>>> Any help would be appreciated!
>>>
>>> Etienne
>>>
>>>
>>> Le 2017-12-06 à 07:53, Antonis Christofides a écrit :
>>>> Hello,
>>>>
>>>> the amount of memory you need depends on what Django does and how many 
>>>> workers
>>>> (instances of Django) you run (which usually depends on how many requests 
>>>> you
>>>> are getting and how I/O intensive your Django application is). For many
>>>> applications, 512 MB is enough.
>>>>
>>>> Why are you worried? The only symptom you describe is that your free 
>>>> memory is
>>>> decreasing. This is absolutely normal. The operating system doesn't like 
>>>> RAM
>>>> that is sitting down doing nothing, so it will do its best to make free RAM
>>>> nearly zero. Whenever there's much RAM available, it uses more for its 
>>>> caches.
>>>>
>>>> How much memory is your Django app consuming? You can find out by executing
>>>> "top" and pressing "M" to sort by memory usage.
>>>>
>>>> Regards,
>>>>
>>>> Antonis
>>>>
>>>> Antonis Christofides
>>>> http://djangodeployment.com
>>>>
>>>> On 2017-12-06 14:04, Etienne Robillard wrote:
>>>>> Hi all,
>>>>>
>>>>> I'm struggling to understand how django/python may allocate and unallocate
>>>>> memory when used with uWSGI.
>>>>>
>>>>> I have a Debian system running Python 2.7 and uwsgi with 2GB of RAM and 2
>>>>> CPUs.
>>>>>
>>>>> Is that enough RAM memory for a uWSGI/Gevent based WSGI app running 
>>>>> Django?
>>>>>
>>>>> I'm running uWSGI with the --gevent switch in order to allow cooperative
>>>>> multithreading, but my free RAM memory is always decreasing when nginx is
>>>>> running.
>>>>>
>>>>> How can I debug memory allocation in a Django/uWSGI app?
>>>>>
>>>>> I defined also in my sitecustomize.py "gc.enable()" to allow garbage
>>>>> collection, but it does not appears to make any differences.
>>>>>
>>>>> Can you recommend any libraries to debug/profile memory allocation in 
>>>>> Python
>>>>> 2.7 ?
>>>>>
>>>>> Is Django more memory efficient with --pymalloc or by using the default 
>>>>> linux
>>>>> malloc() ?
>>>>>
>>>>> Thank you in advance,
>>>>>
>>>>> Etienne
>>>>>
>

-- 
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/4f43e326-313f-7808-09fc-c7087b46b0a7%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: memory leak in django app?

2017-12-06 Thread Antonis Christofides
Does this happen only in production? What about when you run a development
server? What is the memory usage of your development server?

Antonis Christofides
http://djangodeployment.com


On 2017-12-06 15:05, Etienne Robillard wrote:
> Hi Antonis,
>
> Thank you for your reply. I installed the htop utility and found that 2 of my
> 4 uWSGI processes are using 882M (42.7%) of resident memory each. Theses two
> processes takes about  (85%) of the available RAM memory! That can explain why
> I get "out of memory" errors when no more memory is available for sshd.
>
> I tried to debug memory allocation with guppy following instructions here:
> https://www.toofishes.net/blog/using-guppy-debug-django-memory-leaks/
>
> But I get "hp.Nothing" when I attempt to get the heap stats from the master
> uWSGI process.
>
> Example:
> >>> hp.setref()
> >>> hp.heap()
> hp.Nothing
>
> Any help would be appreciated!
>
> Etienne
>
>
> Le 2017-12-06 à 07:53, Antonis Christofides a écrit :
>> Hello,
>>
>> the amount of memory you need depends on what Django does and how many 
>> workers
>> (instances of Django) you run (which usually depends on how many requests you
>> are getting and how I/O intensive your Django application is). For many
>> applications, 512 MB is enough.
>>
>> Why are you worried? The only symptom you describe is that your free memory 
>> is
>> decreasing. This is absolutely normal. The operating system doesn't like RAM
>> that is sitting down doing nothing, so it will do its best to make free RAM
>> nearly zero. Whenever there's much RAM available, it uses more for its 
>> caches.
>>
>> How much memory is your Django app consuming? You can find out by executing
>> "top" and pressing "M" to sort by memory usage.
>>
>> Regards,
>>
>> Antonis
>>
>> Antonis Christofides
>> http://djangodeployment.com
>>
>> On 2017-12-06 14:04, Etienne Robillard wrote:
>>> Hi all,
>>>
>>> I'm struggling to understand how django/python may allocate and unallocate
>>> memory when used with uWSGI.
>>>
>>> I have a Debian system running Python 2.7 and uwsgi with 2GB of RAM and 2 
>>> CPUs.
>>>
>>> Is that enough RAM memory for a uWSGI/Gevent based WSGI app running Django?
>>>
>>> I'm running uWSGI with the --gevent switch in order to allow cooperative
>>> multithreading, but my free RAM memory is always decreasing when nginx is
>>> running.
>>>
>>> How can I debug memory allocation in a Django/uWSGI app?
>>>
>>> I defined also in my sitecustomize.py "gc.enable()" to allow garbage
>>> collection, but it does not appears to make any differences.
>>>
>>> Can you recommend any libraries to debug/profile memory allocation in Python
>>> 2.7 ?
>>>
>>> Is Django more memory efficient with --pymalloc or by using the default 
>>> linux
>>> malloc() ?
>>>
>>> Thank you in advance,
>>>
>>> Etienne
>>>
>

-- 
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/0c2788c4-d6c2-3e5c-1eb4-222a3a9620ce%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: memory leak in django app?

2017-12-06 Thread Antonis Christofides
Hello,

the amount of memory you need depends on what Django does and how many workers
(instances of Django) you run (which usually depends on how many requests you
are getting and how I/O intensive your Django application is). For many
applications, 512 MB is enough.

Why are you worried? The only symptom you describe is that your free memory is
decreasing. This is absolutely normal. The operating system doesn't like RAM
that is sitting down doing nothing, so it will do its best to make free RAM
nearly zero. Whenever there's much RAM available, it uses more for its caches.

How much memory is your Django app consuming? You can find out by executing
"top" and pressing "M" to sort by memory usage.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-12-06 14:04, Etienne Robillard wrote:
> Hi all,
>
> I'm struggling to understand how django/python may allocate and unallocate
> memory when used with uWSGI.
>
> I have a Debian system running Python 2.7 and uwsgi with 2GB of RAM and 2 
> CPUs.
>
> Is that enough RAM memory for a uWSGI/Gevent based WSGI app running Django?
>
> I'm running uWSGI with the --gevent switch in order to allow cooperative
> multithreading, but my free RAM memory is always decreasing when nginx is
> running.
>
> How can I debug memory allocation in a Django/uWSGI app?
>
> I defined also in my sitecustomize.py "gc.enable()" to allow garbage
> collection, but it does not appears to make any differences.
>
> Can you recommend any libraries to debug/profile memory allocation in Python
> 2.7 ?
>
> Is Django more memory efficient with --pymalloc or by using the default linux
> malloc() ?
>
> Thank you in advance,
>
> Etienne
>

-- 
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/f58de0a9-8a9d-cbf5-e7c9-99b898d657a2%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Password reset to Gmail addresses fails

2017-12-04 Thread Antonis Christofides
Hello,

could you show your EMAIL_* settings?

(Meanwhile
https://djangodeployment.com/2017/01/18/why-does-django-not-email-me-the-500-internal-server-error/
might help.)

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2017-12-04 11:22, Alastair Campbell wrote:
> Hi everyone,
>
> I have a very strange problem, I'm looking for ideas on where to debug.
>
> Using the standard password reset in Django (v 1.10), it silently fails to
> send to Gmail addresses.
>
> There is no error generated by Django, and it works for non-Gmail addresses.
>
> In /var/log/mail.log (a Debian VM on Linode), nothing gets passed to the mail
> log (and I checked .err, .warn and .info as well), it is like it didn't 
> happen.
>
> I can send email from that box to gmail addresses via my email client, that
> works fine and shows up in the logs. (And the TLS cert is being used, and I
> have done SPF.)
>
> Is there somewhere between the mail log and django that I need to check? Any
> clues or similar problems recently?
>
> Thanks,
>
> -Alastair
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/CAC5%2BKCFBuei5Cnue8yRwac%3Da92yr2e9AmUzuN_Q6OTf8mMV5vg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAC5%2BKCFBuei5Cnue8yRwac%3Da92yr2e9AmUzuN_Q6OTf8mMV5vg%40mail.gmail.com?utm_medium=email_source=footer>.
> 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/94c24625-7c36-cf2b-cb0e-2957001e086b%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to Speed up Loading the First Page of Django Project?

2017-11-19 Thread Antonis Christofides
Hello,

How does the verification work?

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-11-19 02:38, flora.xiaoyun.hu...@gmail.com wrote:
> Thank you for your reply. The first page always loads slowly while the rest of
> the pages loads at a normal speed. Whether I restart the apache or not doesn't
> affect the speed of loading the first page - always slow.
>
> Below is the configuration file in the sites-available folder under apache. My
> apache is 2.4.
> 
>         ServerAdmin webmaster@localhost
>
>         DocumentRoot /var/www/html
>         
>                 Options FollowSymLinks
>                 AllowOverride None
>         
>         
>                 Options Indexes FollowSymLinks MultiViews
>                 AllowOverride None
>                 Require all granted
>         
>
>         ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
>         
>                 AllowOverride None
>                 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
>                 Require all granted
>         
> ErrorLog /var/log/apache2/error.log
>
>         # Possible values include: debug, info, notice, warn, error, crit,
>         # alert, emerg.
>         LogLevel warn
>
>         CustomLog /var/log/apache2/access.log combined
>
>     Alias /doc/ "/usr/share/doc/"
>     
>         Options Indexes MultiViews FollowSymLinks
>         AllowOverride None
>         Require all granted
>         Allow from 127.0.0.0/255.0.0.0 ::1/128
>     
>
> Alias /static path/to/my/project/static
>         
>                 Require all granted
>         
>
>   
>         
>                 Require all granted
>         
>         
>
>
>   WSGIDaemonProcess myproject
> python-path=path/to/my/project:path/to/my/project/lib/python2.7/site-packages
>   WSGIProcessGroup myproject
>   WSGIScriptAlias / path/to/my/project/myproject/wsgi.py
> 
>
> Thank you!
>
> 在 2017年11月17日星期五 UTC-5上午8:27:24,Jason写道:
>
> I would suggest you post the configuration file here as well as the server
> specifications and average CPU/memory usage.  Because what you're
> describing is definitely not normal and is most likely related to how
> Apache is configured.
>
> A point of clarification: does the first page always load slowly, or is it
> just the first page after you restart the server?
>
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/4cb4d8a9-6709-4f89-923f-bf5cc311e05a%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4cb4d8a9-6709-4f89-923f-bf5cc311e05a%40googlegroups.com?utm_medium=email_source=footer>.
> 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/a9e4105e-fcbd-dc36-235c-97182ed730c4%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django field model for HTML parser?

2017-11-19 Thread Antonis Christofides
Hello,

First of all: If you are just starting to learn, and because the amount you have
to learn can be overwhelming, I'd suggest to not care about the wysiwyg editor
at this stage. Pretend that your users can enter HTML in the field, and do all
the rest. After you get some understanding of static files, only then come back
to this issue.

But to (prematurely) answer your question, if you have DEBUG=True and running
django with manage.py runserver, you shouldn't need to care about STATIC_ROOT
and STATIC_URL and collectstatic. Just forget about them. When the time comes to
deploy your application and turn DEBUG off, then you will need to understand how
static files work in production
<https://djangodeployment.com/2016/11/21/how-django-static-files-work-in-production/>.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2017-11-19 01:38, drone4four wrote:
>
> The official Django docs specify that STATIC_ROOT is indicated in settings.py
> at the STATIC_URL variable (which is near the bottom).  The official Django
> docs says:
>
> Configure your web server to serve the files in STATIC_ROOT
> 
> <https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-STATIC_ROOT>under
> the URL STATIC_URL
> 
> <https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-STATIC_URL>.
>  
>
> (link <https://docs.djangoproject.com/en/1.11/howto/static-files/deployment/>)
>
>
> I’m not running Apache. My Django serving is running locally. The absolute
> path in my file tree to my Django root directory is:
>
> /home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/dobbs_portal_blog/
>
> Inside dobbs_portal_blog is where I placed the static folder. Therefore, the
> line in my settings.py where I declare the variable, I changed from the 
> default:
>
> |
> *STATIC_URL ='/static/'*
> |
>
> to:
>
> *|
> STATIC_URL
> ='/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/dobbs_portal_blog/static/'
> |*
>
> That is my best guess at attempting resolve the “pretty obvious” error 
> message:
>
> You're using the staticfiles app without having set the STATIC_ROOT
> setting to a filesystem path.
>
>
> Yet I am still doing something wrong because invoking python3
> dobbs_portal_blog/manage.py collectstatic, I still get the same message:
>
>
> $ python3 dobbs_portal_blog/manage.py collectstatic
> You have requested to collect static files at the destination location as
> specified in your settings.
> This will overwrite existing files! Are you sure you want to do this?
> Type 'yes' to continue, or 'no' to cancel: yes Traceback (most recent call
> last):  File "dobbs_portal_blog/manage.py", line 22, in 
>    execute_from_command_line(sys.argv)  File
> 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/__init__.py",
> line 364, in execute_from_command_line    utility.execute()  File
> 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/__init__.py",
> line 356, in execute
>    self.fetch_command(subcommand).run_from_argv(self.argv)  File
> 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/base.py",
> line 283, in run_from_argv    self.execute(*args, **cmd_options)  File
> 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/base.py",
> line 330, in execute    output = self.handle(*args, **options)  File
> 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
> line 199, in handle    collected = self.collect()  File
> 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
> line 124, in collect    handler(path, prefixed_path, storage)  File
> 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
> line 354, in copy_file    if not self.delete_file(path, prefixed_path,
> source_storage):  File
> 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/s

Re: static files in production

2017-11-07 Thread Antonis Christofides
Hello,

You might find my drawings on how django static files work in production
<https://djangodeployment.com/2016/11/21/how-django-static-files-work-in-production/>
helpful. Unfortunately they are only for nginx and apache, but the same
principles apply to IIS.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2017-11-07 19:21, Tony King wrote:
>
> Hi again,
>
> I'm having to deploy my project using IIS 8.5 as this all I have access too
> and I've been relatively successful, however, my static image files are not
> displaying in the way they did in the development environment.
>
> I've tried adding what I believe to be the recommended settings but I'm still
> not getting any images too load.
>
> In an almost desperate attempt to understand the search path logic, I've ended
> up with several static folders in my folder structure and still I do not have
> any images.
>
> The attached file includes a screen shot of the settings.py and folder
> structure, which I'm hoping will be useful.
>
> Can someone please help?
>
> Kind regards,
>
>   Tony
>
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/eae9ab3b-8a2b-49ae-ae24-c837545af7ce%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/eae9ab3b-8a2b-49ae-ae24-c837545af7ce%40googlegroups.com?utm_medium=email_source=footer>.
> 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/5eb8b037-8f4c-68e0-24fd-d71f4e644886%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: tutorial site refers to a module which does not exist

2017-11-04 Thread Antonis Christofides
The tutorial does not ask you to put anything in that file because the command
"python manage.py startapp polls" automatically puts in that file what is
needed. If your apps.py file does not contain anything, the most likely
explanation is that you accidentally deleted its contents while you were
experimenting. Try starting again from scratch.

Antonis Christofides
http://djangodeployment.com

On 2017-11-05 00:22, Kyle Foley wrote:
> But if you look at the previous page where the apps.py is created
>
> https://docs.djangoproject.com/en/1.11/intro/tutorial01/
>
> you'll see that in no case do they ask you to put anything in the apps.py
> It's blank, there's no pollsconfig in that file.
>
>
> On Saturday, November 4, 2017 at 3:01:15 PM UTC-7, Kyle Foley wrote:
>
> I'm trying to teach myself Django on this site:
>
> https://docs.djangoproject.com/en/1.11/intro/tutorial02/
> <https://docs.djangoproject.com/en/1.11/intro/tutorial02/>
>
> If you look at this sentence:
>
> To include the app in our project, we need to add a reference to its
> configuration class in the |INSTALLED_APPS|
> 
> <https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-INSTALLED_APPS>
>  setting.
> The |PollsConfig| class is in the |polls/apps.py| file, so its dotted path
> is |'polls.apps.PollsConfig'|.
>
> They haven't told me what the pollsconfig class consists in, nor have they
> told me to build the apps.py module.  When I run the command line
>
> python manage.py makemigrations polls
>
> ModuleNotFoundError: No module named 'polls.apps.PollsConfig';
> 'polls.apps' is not a package
>
>
> So what am I supposed to put in that module?
>
>
>
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/20b5350b-deb3-4656-87a0-f5c5981e79d8%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/20b5350b-deb3-4656-87a0-f5c5981e79d8%40googlegroups.com?utm_medium=email_source=footer>.
> 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/3c23eb80-4490-e616-369b-acfff46995ea%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: tutorial site refers to a module which does not exist

2017-11-04 Thread Antonis Christofides
Hello,

This is the second part of the tutorial. In the first part, at some point you
were told to execute "python manage.py startapp polls". This should have created
an appropriate apps.py file.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-11-04 23:09, Kyle Foley wrote:
> I'm trying to teach myself Django on this site:
>
> https://docs.djangoproject.com/en/1.11/intro/tutorial02/
>
> If you look at this sentence:
>
> To include the app in our project, we need to add a reference to its
> configuration class in the |INSTALLED_APPS|
> <https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-INSTALLED_APPS>
>  setting.
> The |PollsConfig| class is in the |polls/apps.py| file, so its dotted path
> is |'polls.apps.PollsConfig'|.
>
> They haven't told me what the pollsconfig class consists in, nor have they
> told me to build the apps.py module.  When I run the command line
>
> python manage.py makemigrations polls
>
> ModuleNotFoundError: No module named 'polls.apps.PollsConfig'; 'polls.apps' is
> not a package
>
>
> So what am I supposed to put in that module?
>
>
>
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/5cd8bacd-dae2-4c87-99b0-c83da4520edf%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5cd8bacd-dae2-4c87-99b0-c83da4520edf%40googlegroups.com?utm_medium=email_source=footer>.
> 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/d9955a9f-69b6-a9e3-f8a2-6e1e0c498f6d%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: postgres library in django using jython

2017-11-02 Thread Antonis Christofides
Hi,

apparently you are confusing sqlite with postgresql. Could you show the full
stack trace and error message, and your DATABASES setting?

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-11-02 20:23, Felipe Salazar wrote:
> Hi all
>
> I a python developer that I don't use Django very frequently. I am facing a 
> struggle these days because I am development APIs in Django but to deploy the
> project I want to pack the project in a war file, so that is the reason that 
> I am using Jython. However, I am getting errors when I try to connect the
> project to Postgres database because it said that the library sqlite2 is not
> supported in Jython. I installed pysqlite3 1.3 but it looks like that this
> version does not support Postgres until version 1.7 of, but when I tried to
> install the package I get an error:" ' NoneType' object has no attribute
> 'startswith' ".
>
> Please does anyone have an idea of how to solve this issue? 
>
> I appreciate any help and thank you 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/e526aed1-8685-41ac-88f7-371f1bd54224%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/e526aed1-8685-41ac-88f7-371f1bd54224%40googlegroups.com?utm_medium=email_source=footer>.
> 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/3527894d-f4e4-af31-349f-563356903249%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to store a key to a something that can be either a person or an organization?

2017-10-21 Thread Antonis Christofides
Hello James,

You are right that the correct term in everyday language for the superclass of
organization and person is "entity". However, I didn't want to name it "entity"
in the code, because, really, "entity" is a different thing in programming, it's
a term like "object". It would be very confusing. The reason I didn't name it
LegalEntity is exactly that it might not be legal. I chose to invent a new term,
"Lentity", which ensures that someone will not (mis)understand it just by
looking at the name and will necessarily look it up.

I think that my design is "correct" from a theoretical point of view.
Inheritance is the way to solve such a problem in OOP, and multi-table
inheritance is the way to solve this problem in relational databases. That's
what the books say anyway.

In theory, theory and practice are the same. In practice they differ. :-)

My design generally works and I'm quite satisfied with it. This doesn't mean
it's without problems. So, for example, the original definition of Lentity in an
app of mine was this:

class Lentity(models.Model):

def __str__(self):
try:
return str(self.person)
except Person.DoesNotExist:
return str(self.organization)

class Meta:
 verbose_name_plural = 'Lentities'

Then, when I had too many persons and organizations, I had to use raw_id_fields
in the admin, and for this I had to make this change:

class Lentity(models.Model):
# descr is a redundant field; see save() for more information.
descr = models.CharField(max_length=111, blank=True, editable=False)

def __str__(self):
try:
return str(self.person)
except Person.DoesNotExist:
return str(self.organization)

def save(self, *args, **kwargs):
# descr is a redundant, calculated field that is automatically filled
# in during save(). We introduce this redundancy because there is
# currently no other way in which the Django admin can sort lentities,
# i.e. we can use descr as a field in "ordering" or "get_ordering", but
# it's not possible to use an expression. (We need the Django admin to
# manage lentities in general, as well as persons and organizations, in
# order to make it possible to use raw_id_fields in AuthorInline.)
self.descr = str(self)
super(Lentity, self).save(*args, **kwargs)

class Meta:
verbose_name_plural = 'Lentities'

So I had to put Lentity in the admin, ensuring users have no permissions to edit
or delete or create "Lentity" directly, and I told users to just ignore that.
(I'm can't tell whether these problems are worse than having two fields plus a
discriminator field in the admin).

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 10/21/2017 10:29 AM, James Schneider wrote:
>
>
> What I do is I create a superclass that I call Lentity (short for "legal
> entity", despite the fact that it could refer to a group of people and is 
> not
> necessary legal) and the two subclasses Person and Organization, with
> multi-table inheritance.
>
>
> Seems silly to name a model as such given that it can easily be
> nonrepresentative of the data in the table.
>
> Is it an abstract class? If yes, why not just call it Entity? A legal status
> can easily be represented by a field in the model.
>
> If a Person and Organization are treated the same, you can also use just an
> Entity table with a field designating the type of Entity, such as 'person' or
> 'organization'. Querying all Person and Organization objects would then
> constitute only a single query, rather than two queries, one for each model
> type. If you add other similar models, you also increase the number of queries
> required to pull all of the objects, whereas a field designation allows you to
> pull some or all objects regardless of type.
>
> There are a ton of reasons to keep them separate, though, so your design may
> still be correct.
>
> -James
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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%2Be%2BciX21jrrdceNoq4VpthKoc%2BH-g2LbOs%3D4xkV5HKxo0cVJA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2Be%2BciX21jrrdceNoq4VpthKoc%2BH-g2LbOs%3D4xkV5H

  1   2   3   >