Re: Images and pdfs for production level

2020-02-13 Thread Devender Kumar
I will suggest you go with AWS S3 you can use boto3 lib available for
python

On Thu, 13 Feb, 2020, 12:32 pm Soumen Khatua, 
wrote:

> Yes,I want to use CDN for my static files. But I don't know how to
> implement it.
>
> On Wed, Feb 12, 2020 at 9:04 PM Devender Kumar 
> wrote:
>
>> Some CDN
>>
>> On Wed, 12 Feb, 2020, 7:18 pm Soumen Khatua, 
>> wrote:
>>
>>> Hi Folks,
>>> Where I need to store images and pdfs for production level.
>>>
>>> Thank you in advance
>>>
>>> regards,
>>> Soumen
>>>
>>> --
>>> 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/CAPUw6WY-jq3bbC%3DxnreXGMf8c0k_0TDb%3DXXG5Czc6kC_-Q%3D0aQ%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/CALZ%3DbEL1tD5FwY27i8OgK4iYgcnmzbzE3-FtHAP4GFqNKGe2XA%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/CAPUw6WZEzjT7nz3mVWyacLUs8k4C8jZBfmDOi-CPWEkJvTziXg%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/CALZ%3DbEJRahf2C9FO%2BQp1V%2Br2SjQZK6L4PNE3Pv2w%3D8Tb9fyepg%40mail.gmail.com.


Re: 'list' object is not callable

2020-02-13 Thread Bhoopesh sisoudiya
Thanks, Jorge Gimeno this is working fine.

On Fri, Feb 14, 2020 at 9:19 AM Jorge Gimeno  wrote:

>
>
> On Thu, Feb 13, 2020 at 7:16 PM Bhoopesh sisoudiya 
> wrote:
>
>> Hi all,
>>
>> How to resolve this exception in generic view of rest-framework- api
>> Exception===
>> 2020-02-14 08:30:33,523 - D:\futuredatapoints\futuredatapoints\logs\
>> 14022020.log - ERROR
>> ERROR:D:\futuredatapoints\futuredatapoints\logs\14022020.log:
>> %% Exception
>>  Start %%
>> 2020-02-14 08:30:33,523 - D:\futuredatapoints\futuredatapoints\logs\
>> 14022020.log - ERROR
>> 2020-02-14 08:30:33,523 - D:\futuredatapoints\futuredatapoints\logs\
>> 14022020.log - ERROR
>> ERROR:D:\futuredatapoints\futuredatapoints\logs\14022020
>> .log:Traceback (most recent call last):
>>   File
>> "D:\futuredatapoints\env\lib\site-packages\django\core\handlers\base.py"
>> , line 124, in _get_response
>>
>> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>>   File
>> "D:\futuredatapoints\env\lib\site-packages\django\views\decorators\csrf.py"
>> , line 54, in wrapped_view
>> return view_func(*args, **kwargs)
>>   File
>> "D:\futuredatapoints\env\lib\site-packages\django\views\generic\base.py"
>> , line 68, in view
>> return self.dispatch(request, *args, **kwargs)
>>   File
>> "D:\futuredatapoints\env\lib\site-packages\rest_framework\views.py"
>> , line 479, in dispatch
>> request = self.initialize_request(request, *args, **kwargs)
>>   File
>> "D:\futuredatapoints\env\lib\site-packages\rest_framework\views.py"
>> , line 380, in initialize_request
>> authenticators=self.get_authenticators(),
>>   File
>> "D:\futuredatapoints\env\lib\site-packages\rest_framework\views.py"
>> , line 274, in get_authenticators
>> return [auth() for auth in self.authentication_classes]
>>   File
>> "D:\futuredatapoints\env\lib\site-packages\rest_framework\views.py"
>> , line 274, in 
>> return [auth() for auth in self.authentication_classes]
>> TypeError: 'list' object is not callable
>>
>> WARNING:django.request:Bad Request: /api/send/otp/
>>
>>
>> url== ===
>> url(r'^api/send/data/$',UserViewSetCustom.as_view(),name=
>> 'user-view-set-custom'),
>>
>>
>>  view generic class 
>> class UserViewSetCustom(generics.CreateAPIView):
>> """
>> A simple CreateAPIView that for sending otp for user.
>> """
>> # permission_classes = (AllowAny,)
>> authentication_classes = [TokenAuthentication,],
>> queryset = User.objects.all()
>> def create(self, request):
>> print("***")
>> return Response(
>> data=jsonResponse([],
>> msg=Message.getMessage('NOT_ALLOWED'),
>> status=status.HTTP_200_OK),
>> status=status.HTTP_200_OK,
>> )
>>
>> Thanks
>> Bhoopesh Sisoudiya
>>
>> --
>> 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/CAAk3c1N0JBOFkF7tyMLJdMY3bh3H54r-QVh6_x-KW9peaRo9dA%40mail.gmail.com
>> 
>> .
>>
>
> I did some experimenting in the Python shell.   What I found is this:
>
>  jlgimeno@jlgimeno-Lenovo-G50-45  ~  python3.8
> Python 3.8.1 (default, Dec 31 2019, 11:21:33)
> [GCC 9.2.1 20191008] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> a = [1]
> >>> b = [1,]
> >>> c = [1,],
> >>> a
> [1]
> >>> b
> [1]
> >>> c
> ([1],)
>
> The variables a and b are both lists with a single object, but c is
> different.  It is a tuple, with the first (and only) element is a list.  c
> is similar to your authentication_classes variable in your view because of
> that trailing comma which makes it a tuple.  As you can see in the last two
> lines of your traceback, django rest framework is trying to get a list of
> authenticators using a list comprehension, by calling each class that is an
> element of self.authentication_classes.  It's not getting a callable back,
> it's getting back a list.  Lists are not callables, and so Python raises an
> exception.
>
> To fix this, remove the trailing comma in your authentication_classes
> variable like so:
> authentication_classes = [TokenAuthentication,]
>
> That should work. Hope this helped!
>
> -Jorge
>
> --
> 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 

Re: 'list' object is not callable

2020-02-13 Thread Jorge Gimeno
On Thu, Feb 13, 2020 at 7:16 PM Bhoopesh sisoudiya 
wrote:

> Hi all,
>
> How to resolve this exception in generic view of rest-framework- api
> Exception===
> 2020-02-14 08:30:33,523 - D:\futuredatapoints\futuredatapoints\logs\
> 14022020.log - ERROR
> ERROR:D:\futuredatapoints\futuredatapoints\logs\14022020.log:
> %% Exception
>  Start %%
> 2020-02-14 08:30:33,523 - D:\futuredatapoints\futuredatapoints\logs\
> 14022020.log - ERROR
> 2020-02-14 08:30:33,523 - D:\futuredatapoints\futuredatapoints\logs\
> 14022020.log - ERROR
> ERROR:D:\futuredatapoints\futuredatapoints\logs\14022020
> .log:Traceback (most recent call last):
>   File
> "D:\futuredatapoints\env\lib\site-packages\django\core\handlers\base.py"
> , line 124, in _get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>   File
> "D:\futuredatapoints\env\lib\site-packages\django\views\decorators\csrf.py"
> , line 54, in wrapped_view
> return view_func(*args, **kwargs)
>   File
> "D:\futuredatapoints\env\lib\site-packages\django\views\generic\base.py"
> , line 68, in view
> return self.dispatch(request, *args, **kwargs)
>   File "D:\futuredatapoints\env\lib\site-packages\rest_framework\views.py"
> , line 479, in dispatch
> request = self.initialize_request(request, *args, **kwargs)
>   File "D:\futuredatapoints\env\lib\site-packages\rest_framework\views.py"
> , line 380, in initialize_request
> authenticators=self.get_authenticators(),
>   File "D:\futuredatapoints\env\lib\site-packages\rest_framework\views.py"
> , line 274, in get_authenticators
> return [auth() for auth in self.authentication_classes]
>   File "D:\futuredatapoints\env\lib\site-packages\rest_framework\views.py"
> , line 274, in 
> return [auth() for auth in self.authentication_classes]
> TypeError: 'list' object is not callable
>
> WARNING:django.request:Bad Request: /api/send/otp/
>
>
> url== ===
> url(r'^api/send/data/$',UserViewSetCustom.as_view(),name=
> 'user-view-set-custom'),
>
>
>  view generic class 
> class UserViewSetCustom(generics.CreateAPIView):
> """
> A simple CreateAPIView that for sending otp for user.
> """
> # permission_classes = (AllowAny,)
> authentication_classes = [TokenAuthentication,],
> queryset = User.objects.all()
> def create(self, request):
> print("***")
> return Response(
> data=jsonResponse([],
> msg=Message.getMessage('NOT_ALLOWED'),
> status=status.HTTP_200_OK),
> status=status.HTTP_200_OK,
> )
>
> Thanks
> Bhoopesh Sisoudiya
>
> --
> 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/CAAk3c1N0JBOFkF7tyMLJdMY3bh3H54r-QVh6_x-KW9peaRo9dA%40mail.gmail.com
> 
> .
>

I did some experimenting in the Python shell.   What I found is this:

 jlgimeno@jlgimeno-Lenovo-G50-45  ~  python3.8
Python 3.8.1 (default, Dec 31 2019, 11:21:33)
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = [1]
>>> b = [1,]
>>> c = [1,],
>>> a
[1]
>>> b
[1]
>>> c
([1],)

The variables a and b are both lists with a single object, but c is
different.  It is a tuple, with the first (and only) element is a list.  c
is similar to your authentication_classes variable in your view because of
that trailing comma which makes it a tuple.  As you can see in the last two
lines of your traceback, django rest framework is trying to get a list of
authenticators using a list comprehension, by calling each class that is an
element of self.authentication_classes.  It's not getting a callable back,
it's getting back a list.  Lists are not callables, and so Python raises an
exception.

To fix this, remove the trailing comma in your authentication_classes
variable like so:
authentication_classes = [TokenAuthentication,]

That should work. Hope this helped!

-Jorge

-- 
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/CANfN%3DK-juSt_MBYz3c7vvj%3DFmdA8iFpMhCQOO6u85Sgrj2dYLw%40mail.gmail.com.


'list' object is not callable

2020-02-13 Thread Bhoopesh sisoudiya
Hi all,

How to resolve this exception in generic view of rest-framework- api
Exception===
2020-02-14 08:30:33,523 - D:\futuredatapoints\futuredatapoints\logs\14022020
.log - ERROR
ERROR:D:\futuredatapoints\futuredatapoints\logs\14022020.log:
%% Exception
 Start %%
2020-02-14 08:30:33,523 - D:\futuredatapoints\futuredatapoints\logs\14022020
.log - ERROR
2020-02-14 08:30:33,523 - D:\futuredatapoints\futuredatapoints\logs\14022020
.log - ERROR
ERROR:D:\futuredatapoints\futuredatapoints\logs\14022020
.log:Traceback (most recent call last):
  File
"D:\futuredatapoints\env\lib\site-packages\django\core\handlers\base.py"
, line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File
"D:\futuredatapoints\env\lib\site-packages\django\views\decorators\csrf.py"
, line 54, in wrapped_view
return view_func(*args, **kwargs)
  File
"D:\futuredatapoints\env\lib\site-packages\django\views\generic\base.py"
, line 68, in view
return self.dispatch(request, *args, **kwargs)
  File "D:\futuredatapoints\env\lib\site-packages\rest_framework\views.py"
, line 479, in dispatch
request = self.initialize_request(request, *args, **kwargs)
  File "D:\futuredatapoints\env\lib\site-packages\rest_framework\views.py"
, line 380, in initialize_request
authenticators=self.get_authenticators(),
  File "D:\futuredatapoints\env\lib\site-packages\rest_framework\views.py"
, line 274, in get_authenticators
return [auth() for auth in self.authentication_classes]
  File "D:\futuredatapoints\env\lib\site-packages\rest_framework\views.py"
, line 274, in 
return [auth() for auth in self.authentication_classes]
TypeError: 'list' object is not callable

WARNING:django.request:Bad Request: /api/send/otp/


url== ===
url(r'^api/send/data/$',UserViewSetCustom.as_view(),name=
'user-view-set-custom'),


 view generic class 
class UserViewSetCustom(generics.CreateAPIView):
"""
A simple CreateAPIView that for sending otp for user.
"""
# permission_classes = (AllowAny,)
authentication_classes = [TokenAuthentication,],
queryset = User.objects.all()
def create(self, request):
print("***")
return Response(
data=jsonResponse([],
msg=Message.getMessage('NOT_ALLOWED'),
status=status.HTTP_200_OK),
status=status.HTTP_200_OK,
)

Thanks
Bhoopesh Sisoudiya

-- 
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/CAAk3c1N0JBOFkF7tyMLJdMY3bh3H54r-QVh6_x-KW9peaRo9dA%40mail.gmail.com.


Re: Trouble after create a pool

2020-02-13 Thread Jorge Gimeno
On Thu, Feb 13, 2020, 10:49 AM Rodrigo Silva <
carvalhaes.silva.rodr...@gmail.com> wrote:

>Hi, I'm starting in django and learning about the tutorials.
> After I have been created and set up, when I run the server the shell show
> me a error
>
> Someone can help me? Than you!
>
> C:\Users\carva\mysite>python manage.py runserver
> Watching for file changes with StatReloader
> Performing system checks...
>
> Exception in thread django-main-thread:
> Traceback (most recent call last):
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\threading.py",
> line 932, in _bootstrap_inner
> self.run()
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\threading.py",
> line 870, in run
> self._target(*self._args, **self._kwargs)
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\utils\autoreload.py",
> line 53, in wrapper
> fn(*args, **kwargs)
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\management\commands\runserver.py",
> line 117, in inner_run
> self.check(display_num_errors=True)
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\management\base.py",
> line 392, in check
> all_issues = self._run_checks(
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\management\base.py",
> line 382, in _run_checks
> return checks.run_checks(**kwargs)
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\checks\registry.py",
> line 72, in run_checks
> new_errors = check(app_configs=app_configs)
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\checks\urls.py",
> line 13, in check_url_config
> return check_resolver(resolver)
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\checks\urls.py",
> line 23, in check_resolver
> return check_method()
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\urls\resolvers.py",
> line 407, in check
> for pattern in self.url_patterns:
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\utils\functional.py",
> line 48, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\urls\resolvers.py",
> line 588, in url_patterns
> patterns = getattr(self.urlconf_module, "urlpatterns",
> self.urlconf_module)
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\utils\functional.py",
> line 48, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\urls\resolvers.py",
> line 581, in urlconf_module
> return import_module(self.urlconf_name)
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py",
> line 127, in import_module
> return _bootstrap._gcd_import(name[level:], package, level)
>   File "", line 1014, in _gcd_import
>   File "", line 991, in _find_and_load
>   File "", line 975, in
> _find_and_load_unlocked
>   File "", line 671, in _load_unlocked
>   File "", line 783, in exec_module
>   File "", line 219, in
> _call_with_frames_removed
>   File "C:\Users\carva\mysite\mysite\urls.py", line 20, in 
> path('pools/', include('pools.urls')),
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\urls\conf.py",
> line 34, in include
> urlconf_module = import_module(urlconf_module)
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py",
> line 127, in import_module
> return _bootstrap._gcd_import(name[level:], package, level)
>   File "", line 1014, in _gcd_import
>   File "", line 991, in _find_and_load
>   File "", line 961, in
> _find_and_load_unlocked
>   File "", line 219, in
> _call_with_frames_removed
>   File "", line 1014, in _gcd_import
>   File "", line 991, in _find_and_load
>   File "", line 973, in
> _find_and_load_unlocked
> ModuleNotFoundError: No module named 'pools'
> Traceback (most recent call last):
>   File "manage.py", line 21, in 
> main()
>   File "manage.py", line 17, in main
> execute_from_command_line(sys.argv)
>   File
> "C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\management\__init__.py",
> line 401, in 

Has anyone ever deployed a Django project that uses Pyo to Heroku?

2020-02-13 Thread Kevin Dublin
Hi all,

I'm trying to deploy an mvp of a django project on Heroku that works fine
locally but only works online when I uninstall the package Pyo (
http://ajaxsoundstudio.com/pyodoc/index.html) or move my import to the
specific function that uses it, but it throws an OSerror whenever it is
initialized (OSError at / Exception Value:
/app/.pyo/3.6_64/libs/libasound-fb332ab3.so.2.0.0: cannot open shared
object -- see below for full traceback). I've added a buildpack that
installs the libasound and recommened packages, but I still get the error.
What am I missing? I see the Linux wheel fix symlink (
https://github.com/belangeo/pyo/blob/master/pyo/_linux_wheel_fix_symlinks.py
).

After an exchange on the Pyo usergroup via email, it was clear that a part
of the issue is here on line 35 of the above file:

userlibdir = os.path.join(os.path.expanduser("~"), ".pyo", version, "libs")


The missing file is supposed to be created the first time pyo loads, but it
fails. I even tried just copying the files locally and force pushing them
up into the directory, but it still returns the same error. I don't know if
this is permissions related or what, but it's become increasingly
frustrating. Any help would be greatly appreciated.

Error:

Request Method: GETRequest URL: ---
Django Version: 3.0.3Python Version: 3.6.10Installed
Applications:['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'core',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'allauth.socialaccount.providers.facebook',
 'allauth.socialaccount.providers.google']Installed
Middleware:('whitenoise.middleware.WhiteNoiseMiddleware',
 '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')


Traceback (most recent call last):
  File 
"/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py",
line 34, in inner
response = get_response(request)
  File 
"/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py",
line 100, in _get_response
resolver_match = resolver.resolve(request.path_info)
  File 
"/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py",
line 544, in resolve
for pattern in self.url_patterns:
  File 
"/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py",
line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py",
line 588, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File 
"/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py",
line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py",
line 581, in urlconf_module
return import_module(self.urlconf_name)
  File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line
126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 994, in _gcd_import

  File "", line 971, in _find_and_load

  File "", line 955, in _find_and_load_unlocked

  File "", line 665, in _load_unlocked

  File "", line 678, in exec_module

  File "", line 219, in _call_with_frames_removed

  File "/app/autosubclub/urls.py", line 20, in 
from core import views
  File "/app/core/views.py", line 8, in 
from pyo import PVMix, PVMorph, PVAnal, SfPlayer, Vocoder, Server,
Record, sndinfo
  File "/app/.heroku/python/lib/python3.6/site-packages/pyo/__init__.py",
line 25, in 
from . import _linux_wheel_fix_symlinks
  File 
"/app/.heroku/python/lib/python3.6/site-packages/pyo/_linux_wheel_fix_symlinks.py",
line 88, in 
libasound = ctypes.CDLL(libasound, mode=ctypes.RTLD_GLOBAL)
  File "/app/.heroku/python/lib/python3.6/ctypes/__init__.py", line
348, in __init__
self._handle = _dlopen(self._name, mode)
Exception Type: OSError at /Exception Value:
/app/.pyo/3.6_64/libs/libasound-fb332ab3.so.2.0.0: cannot open shared
object file: No such file or directory

Thank you,


Kevin Dublin (he / him / his)
Writer of poetry, prose, scripts, and code (Django/MERN Full Stack
Developer)
Author of *How to Fall in Love in San Diego
*
Follow me @parteverything

*Happiness is a state of being, just be.*

*Believe it, and it will be.*

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

Re: Sending json data to postgres once received from API

2020-02-13 Thread Ilya Rustamov
Thank you Jody, I will take a look at this and see how it goes.

On Thursday, February 13, 2020 at 3:27:03 PM UTC-5, Jody Fitzpatrick wrote:
>
> Hello Ilya
>
> I would read the following:
>
> https://docs.djangoproject.com/en/3.0/topics/db/models/
>
> Essentially, what you do in shell is what you would do in your code. 
>
> I also believe you might want to look at how you are grabbing the posted 
> data.
>
> I would use something like url = request.GET.get('url', False)
>
> So you want break your code and can validate if it was indeed sent. 
>
> Best of luck
>
> ps.
>
> Also, look at postgres models.JsonField
>

-- 
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/2142e140-794f-4447-ba5e-8f7e69fa11ab%40googlegroups.com.


Re: Sending json data to postgres once received from API

2020-02-13 Thread Jody Fitzpatrick
Hello Ilya

I would read the following:

https://docs.djangoproject.com/en/3.0/topics/db/models/

Essentially, what you do in shell is what you would do in your code. 

I also believe you might want to look at how you are grabbing the posted 
data.

I would use something like url = request.GET.get('url', False)

So you want break your code and can validate if it was indeed sent. 

Best of luck

ps.

Also, look at postgres models.JsonField

-- 
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/b85cc4ac-54eb-47bb-b78e-2364363f28d6%40googlegroups.com.


Sending json data to postgres once received from API

2020-02-13 Thread Ilya Rustamov
Hey Devs,

   First time poster here, if I am missing anything or am not following 
general rules and practices feel free to let me know.

I am in the process of building an app that asks user for a url and on 
submit makes post request to said url, receives json data and simply prints 
it in a new view.

This part of the app works well and does the job it is supposed to do, my 
only issue is that once the app has received that data, not only do I want 
it printed but would also like for it to be entered into a table in my 
postgres db. 

I have already connected a postgres db and it has a table that is built 
from my models that can receive this data.

I am struggling to understand how to actually send data to the db from the 
app, the only understanding I have of entering data into db is using the 
shell which does not solve my issue. 

My goal is to be able to save the json data i receive from the url into 
that table in my postgres db? What is the best and most efficient way to go 
about accomplishing this?

I will attach some of my code so you can see what I am working with so far.


views.py 

from django.shortcuts import HttpResponse, render
import urllib.request
import json


def home(request):
return render(request, 'djangoAPI/response.html')


def result(request):
url = request.GET['url']
operUrl = urllib.request.urlopen(url)
if operUrl.getcode() == 200:
data = operUrl.read()
jsonData = json.loads(data)
final = json.dumps(jsonData, indent=2, sort_keys=True)
else:
print("Error receiving data", operUrl.getcode())

return render(request, 'djangoAPI/request.html', {'result': final})




models.py

from django.db import models


class URLData(models.Model):
id  = models.IntegerField(primary_key=True)
title   = models.CharField(max_length=200)
summary = models.TextField()
description = models.TextField()
url = models.URLField(max_length=200)
rssFeed = models.TextField(blank=True, null=True)
links   = models.TextField(blank=True, null=True)

def __str__(self):
return self.title



-- 
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/67f33d50-3dca-4391-a54e-ec420d833912%40googlegroups.com.


Re: Django server indention

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 9:02 PM Sathiya S 
wrote:

> How to format Indention in server?
>

Are you talking about how to indent your code in Django? If yes then a
learner's approach would be, well to do it yourself, I mean entire Python
depends on indentation right? You can also look at psf/black
 if you want to skip ahead.


> --
> 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/68652648-1dd6-4d33-9d6e-c069388d29a4%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/CAD%3DM5eSfWiiAErd6DM656RmWJQNwwSEHBrBSV43rg8cLm7OKRA%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 8:14 PM sachinbg sachin 
wrote:

> Fistly for setup create use instance for setup user credentials then call
> that the reverse url in that post put delite
>

I have already created my test users in the *setUpClass()* method. As
mentioned my problem was not something related to URL dispatching but more
on how to prepare a POST request with the proper payload. I looked into the
documentation and RequestFactory is exactly what i was looking for.


> On Thu, Feb 13, 2020, 8:01 PM Adam Mičuda  wrote:
>
>> Hi,
>> or you can extract the business logic from view to some service and unit
>> test it instead. =)
>>
>> Regards.
>>
>> Adam
>>
>> st 12. 2. 2020 v 21:15 odesílatel onlinejudge95 
>> napsal:
>>
>>> On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
>>> wrote:
>>>
 Hi Devs,

 I was implementing unit-tests in my Django project and stumbled upon
 the following issue.

 I want to unit-test my POST route. I do not want to use the test client
 already shipped with Django (using it in my e2e tests). I want to know how
 do I prepare my request object to pass to my view. Here is what I have done
 currently.

 test_views.py

> class CreateBlogTest(BaseViewTest):

 @classmethod
> def setUpClass(cls):
> cls.request.method = "POST"

 def test_create_valid_blog(self):
> self.request.content_type = "application/json"
> self.request._body = json.dumps({"title": "new title", "body":
> "new body"})
>
> response = views.blog_collection(self.request)
> self.assertEqual(response.status_code, 201)
>

 In my view, I am accessing the data through *request.data* and passing
 it to a serializer.

 In my current setting, I am getting a 400 error message when I have
 checked that the user does not exist.

 Any suggestions regarding the same?

 Thanks,
 onlinejudge95

>>>
>>> In case if someone needs it in the future, go and look at
>>> *django.test.RequestFactory *
>>>
>>> https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory
>>>
>>> --
>>> 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/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%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/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%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/CAOs61rxaSRrE239aZrbBpZSo7QBoZx2BKxx4nBiERhio0RGSJg%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/CAD%3DM5eTyjickDTJVCMgHOGWVpXrTdS%2BRsyiJOtJSBpfWPrb44g%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 8:02 PM Adam Mičuda  wrote:

> Hi,
> or you can extract the business logic from view to some service and unit
> test it instead. =)
>

I am following the same, it's just that I am also performing serialization
as of now in my views, since I want to push it out first, and have
documented the refactor I would be performing. My question was on how to
prepare a post request with proper payload, while i was running this test
my response object was an empty dictionary.

>
> Regards.
>
> Adam
>
> st 12. 2. 2020 v 21:15 odesílatel onlinejudge95 
> napsal:
>
>> On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
>> wrote:
>>
>>> Hi Devs,
>>>
>>> I was implementing unit-tests in my Django project and stumbled upon the
>>> following issue.
>>>
>>> I want to unit-test my POST route. I do not want to use the test client
>>> already shipped with Django (using it in my e2e tests). I want to know how
>>> do I prepare my request object to pass to my view. Here is what I have done
>>> currently.
>>>
>>> test_views.py
>>>
 class CreateBlogTest(BaseViewTest):
>>>
>>> @classmethod
 def setUpClass(cls):
 cls.request.method = "POST"
>>>
>>> def test_create_valid_blog(self):
 self.request.content_type = "application/json"
 self.request._body = json.dumps({"title": "new title", "body":
 "new body"})

 response = views.blog_collection(self.request)
 self.assertEqual(response.status_code, 201)

>>>
>>> In my view, I am accessing the data through *request.data* and passing
>>> it to a serializer.
>>>
>>> In my current setting, I am getting a 400 error message when I have
>>> checked that the user does not exist.
>>>
>>> Any suggestions regarding the same?
>>>
>>> Thanks,
>>> onlinejudge95
>>>
>>
>> In case if someone needs it in the future, go and look at
>> *django.test.RequestFactory *
>>
>> https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory
>>
>> --
>> 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/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%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/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%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/CAD%3DM5eTWpMRcZ%2BG_zRf%2B9hB2Xds3SKB%3Dm6PT5C60cCDvGUa5EA%40mail.gmail.com.


Trouble after create a pool

2020-02-13 Thread Rodrigo Silva
   Hi, I'm starting in django and learning about the tutorials.
After I have been created and set up, when I run the server the shell show 
me a error

Someone can help me? Than you!

C:\Users\carva\mysite>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\threading.py", 
line 932, in _bootstrap_inner
self.run()
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\threading.py", 
line 870, in run
self._target(*self._args, **self._kwargs)
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\utils\autoreload.py",
 
line 53, in wrapper
fn(*args, **kwargs)
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\management\commands\runserver.py",
 
line 117, in inner_run
self.check(display_num_errors=True)
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\management\base.py",
 
line 392, in check
all_issues = self._run_checks(
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\management\base.py",
 
line 382, in _run_checks
return checks.run_checks(**kwargs)
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\checks\registry.py",
 
line 72, in run_checks
new_errors = check(app_configs=app_configs)
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\checks\urls.py",
 
line 13, in check_url_config
return check_resolver(resolver)
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\checks\urls.py",
 
line 23, in check_resolver
return check_method()
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\urls\resolvers.py",
 
line 407, in check
for pattern in self.url_patterns:
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\utils\functional.py",
 
line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\urls\resolvers.py",
 
line 588, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", 
self.urlconf_module)
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\utils\functional.py",
 
line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\urls\resolvers.py",
 
line 581, in urlconf_module
return import_module(self.urlconf_name)
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py",
 
line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1014, in _gcd_import
  File "", line 991, in _find_and_load
  File "", line 975, in _find_and_load_unlocked
  File "", line 671, in _load_unlocked
  File "", line 783, in exec_module
  File "", line 219, in 
_call_with_frames_removed
  File "C:\Users\carva\mysite\mysite\urls.py", line 20, in 
path('pools/', include('pools.urls')),
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\urls\conf.py",
 
line 34, in include
urlconf_module = import_module(urlconf_module)
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py",
 
line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1014, in _gcd_import
  File "", line 991, in _find_and_load
  File "", line 961, in _find_and_load_unlocked
  File "", line 219, in 
_call_with_frames_removed
  File "", line 1014, in _gcd_import
  File "", line 991, in _find_and_load
  File "", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pools'
Traceback (most recent call last):
  File "manage.py", line 21, in 
main()
  File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\management\__init__.py",
 
line 401, in execute_from_command_line
utility.execute()
  File 
"C:\Users\carva\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django-3.0.3-py3.8.egg\django\core\management\__init__.py",
 
line 395, in execute

Re: Manually running a script that imports a Django model

2020-02-13 Thread maninder singh Kumar
Could it be an improperly configured database ?
Also check installed apps.  
It is most likely a syntax error in settings like a comma, colon or apostrophe

Sent from my iPad

> On 13-Feb-2020, at 7:34 PM, onlinejudge95  wrote:
> 
>> On Thu, Feb 13, 2020 at 6:34 PM Sourish Kundu  
>> wrote:
> 
>> So I am trying to access one of my models created in views.py in another 
>> script. This second script is the one I would like manually run. It imports 
>> the model without any errors; however, when I try to run it using PyCharm, I 
>> get this error:
> 
> Firstly, what are your models doing in views.py? I am assuming it was a typo.
>  
>> 
>> django.core.exceptions.ImproperlyConfigured: Requested setting 
>> INSTALLED_APPS, but settings are not configured. You must either define the 
>> environment variable DJANGO_SETTINGS_MODULE or call settings.configure() 
>> before accessing settings.
>> 
>> Any help on resolving this issue would be very much appreciated.
> 
> For scripts like these that are not part of your web server or that do not 
> take part in the request-response cycle, I like to implement them as custom 
> Django commands. You can read more about them here.
>  
>> 
>> 
>> Thanks,
>> Sourish
>> -- 
>> 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/2c9b2d34-a9ab-4a2f-a1e4-e2694c265ea0%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/CAD%3DM5eSBrbLvnFBzoGfOaJk3NnWG8t1N2aOQTmHR6TDsup3F%2BA%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/824DE3AE-7DEE-4A00-8AF2-F709F371E06A%40gmail.com.


Saving np.nan to sqlite database Django 2.1 in unit test fails

2020-02-13 Thread BK
I upgraded to django 2.1 and some of my unit tests (which use a sqlite 
database) are failing with the following:

  File 
"/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/django/db/models/query.py",
 line 268, in __iter__
2113self._fetch_all()
2114  File 
"/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/django/db/models/query.py",
 line 1186, in _fetch_all
2115self._result_cache = list(self._iterable_class(self))
2116  File 
"/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/django/db/models/sql/compiler.py",
 line 1042, in apply_converters
2117value = converter(value, expression, connection)
2118  File 
"/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/django/db/backends/sqlite3/operations.py",
 line 254, in converter
2119return create_decimal(value).quantize(quantize_value, 
context=expression.output_field.context)
2120TypeError: argument must be int of float



The unit test involves adding numpy.nan (among other things) to the database 
(in a models.DecimalField field) and at some point later in the test we are 
querying that data and when it try's to evaluate the query set the above error 
occurs.


The following code in sqlite/operations.py was changed from 2.0 to 2.1 which 
seems to be the source of the error.

FROM Django 2.0

def convert_decimalfield_value(self, value, expression, connection):
if value is not None:
value = expression.output_field.format_number(value)
# Value is not converted to Decimal here as it will be converted
# later in BaseExpression.convert_value().
return value



FROM Django 2.1

def get_decimalfield_converter(self, expression):
# SQLite stores only 15 significant digits. Digits coming from
# float inaccuracy must be removed.
create_decimal = decimal.Context(prec=15).create_decimal_from_float
if isinstance(expression, Col):
quantize_value = 
decimal.Decimal(1).scaleb(-expression.output_field.decimal_places)

def converter(value, expression, connection):
if value is not None:
return create_decimal(value).quantize(quantize_value, 
context=expression.output_field.context)
else:
def converter(value, expression, connection):
if value is not None:
return create_decimal(value)
return converter



Has anyone faced this issuenot sure what other details to provide...happy 
to provide more upon request.

Python 3.5.9 (default, Nov 24 2019, 01:35:13)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.0.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import sqlite3

In [2]: sqlite3.version
Out[2]: '2.6.0'

In [3]: sqlite3.sqlite_version
Out[3]: '3.22.0'


Django==2.1.15
mysqlclient==1.3.9

NumPy==1.11.1
pandas==0.19.2


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/68734337-fa09-4ea1-8834-e1a76ea734bb%40googlegroups.com.


Re: Is a Custom User Model worth the headache?

2020-02-13 Thread maninder singh Kumar
Here's my opinion on this :
1. It requires the.user model to be the first migration
2.  You could either want to extend or customise the User model
3.  If extending is all you want then use the default authentication

I tried customising it didn't find it worth my time

Willy

Sent from my iPad

> On 13-Feb-2020, at 9:00 PM, bnmng  wrote:
> 
> Thanks for the reply.  That is a good post and I'll go along with the 
> recommendation, though I still don't completely understand why adding a 
> profile isn't as good as creating a custom user, and I wish I could figure 
> out how to group custom users and auth groups together in the same admin 
> section
> 
> Ben 
> 
>> On Thursday, February 13, 2020 at 8:04:18 AM UTC-5, SikoraD wrote:
>> Hi Ben,
>> 
>> I'll highly recommended to read fantastic post on Will Vincent blog -> 
>> https://wsvincent.com/django-tips-custom-user-model/
>> His approach is much easier than one on django website and it is worth to 
>> have look.
>> 
>> Also his djangox repo on github is very useful.
>> 
>> Best Regards
>> Damian
>> 
>> 
>>> Hi.  
>>> 
>>> I read the part where it's "highly recommended" to create a custom user 
>>> model, but I don't see why it's worth the headache.  I found these problems:
>>> 
>>> 1 In the admin panel, my auth groups are in a separate app from my users
>>> 2 There is some disagreement out there about how apps should refer to a 
>>> user model now that the user model might be custom
>>> 3 A lot of features that I would add are app specific, and therefore would 
>>> be better handled by app specific profiles
>>> 4 There's a new entry point for possible errors and glitches
>>> 
>>> So why do this? 
>>> 
>>> Thanks,
>>> Ben 
> 
> -- 
> 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/3210d917-e796-4b26-a316-fc3974bcfc0b%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/F667FDD1-50AE-4E7B-A129-B12B363DB5C7%40gmail.com.


Django server indention

2020-02-13 Thread Sathiya S
How to format Indention in 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/68652648-1dd6-4d33-9d6e-c069388d29a4%40googlegroups.com.


Re: Is a Custom User Model worth the headache?

2020-02-13 Thread bnmng
Thanks for the reply.  That is a good post and I'll go along with the 
recommendation, though I still don't completely understand why adding a 
profile isn't as good as creating a custom user, and I wish I could figure 
out how to group custom users and auth groups together in the same admin 
section

Ben 

On Thursday, February 13, 2020 at 8:04:18 AM UTC-5, SikoraD wrote:
>
> Hi Ben,
>
> I'll highly recommended to read fantastic post on Will Vincent 
>  blog -> 
> https://wsvincent.com/django-tips-custom-user-model/
> His approach is much easier than one on django website and it is worth to 
> have look.
>
> Also his djangox repo on github is very useful.
>
> Best Regards
> Damian
>
>
> Hi.  
>>
>> I read the part where it's "highly recommended" to create a custom user 
>> model, but I don't see why it's worth the headache.  I found these problems:
>>
>> 1 In the admin panel, my auth groups are in a separate app from my users
>> 2 There is some disagreement out there about how apps should refer to a 
>> user model now that the user model might be custom
>> 3 A lot of features that I would add are app specific, and therefore 
>> would be better handled by app specific profiles
>> 4 There's a new entry point for possible errors and glitches
>>
>> So why do this? 
>>
>> Thanks,
>> Ben 
>>
>

-- 
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/3210d917-e796-4b26-a316-fc3974bcfc0b%40googlegroups.com.


Re: filter objects dynamically on page render based on button click (beginner question)

2020-02-13 Thread Bill Freeman
Note that Vue is one option among many and could either be overkill or not
helpful enough for your specific use case OR BOTH.  It's just modern, and
may be useful for projects beyond this one.

It doesn't hurt to be familiar with the grand daddy of them all: jQuery
(though many sneer at it today).

On Thu, Feb 13, 2020 at 7:38 AM Phil Kauffman 
wrote:

> Bill,
>
> Thank You for taking the time to respond. I will definitely need to read
> up on the options you presented. My first inclination was to get familiar
> with the first option as it seems easiest. However, now that you mention
> VueJS I will look into that as well.
>
> On Wednesday, February 12, 2020 at 6:46:42 PM UTC-5, ke1g wrote:
>
>> What happens in the browser stays in the browser, unless you do something
>> about it.
>>
>> Forgive me if I'm being too basic below:
>>
>> There are three approaches to click and see a filtering change, with
>> trade offs in performance, complexity, and the impact if the user's browser
>> is on a humble box.
>>
>>1. When the user clicks, it's on a link, and you reload the page with
>>the filter applied.  No JavaScript required.  Pretty slow.  more network
>>load, more browser load, and more load on the server.  (I'm not going into
>>the old approach of having an iframe and the link reloads the iframe
>>because iframes are tricky, and if you're showing a big table, it's most 
>> of
>>the page anyway.)  Do be sure that your images, CSS files, and JavaScript
>>files are set to encourage the browser and/or the network to cache them,
>>but the HTML will load every time, and the URL will likely show the filter
>>settings (though you can do things with cookies and/or session store, but
>>you will surprise your users someday.
>>2. Load all the data in the first place, and use JavaScript in
>>combination with CSS to hide the stuff that's filtered out.  If you go 
>> this
>>way, do arrange to use CSS controlled by a class on a single containing
>>element to control visibility, because doing big DOM modifications in
>>JavaScript performs poorly.  This is the snappiest approach, but you have
>>to have loaded everything, at cost of network and server load, even if you
>>expect the user to filter later, and at the cost of RAM in the browser.  
>> If
>>the data's not that big, this is fine.  But if it's the catalog of a
>>hardware chain or something else huge, you probably be doing it in pages.
>>Sometimes it's natural.  For example, I once did and event calendar for a
>>school system.  I loaded a month at a time, and filtering within the month
>>was peppy, but to go to a different month required a reload, and you
>>couldn't show stuff from multiple months at one time.
>>3. Use an AJAX request to replace part of the DOM with filtered
>>data.  (The iframe hack is very much like this.)  If the data is most of
>>your page, this isn't much more light weight than option 1, but the user
>>doesn't see the page reload, which seems to count for style points.
>>
>> There are JavaScript "frameworks" (e.g. VueJS) that will help you with 2
>> and especially 3, but you have to learn how to use the framework, and how
>> to connect it to Django.  Those are useful things to learn, but they're not
>> overnight reads, and can have performance pitfalls.
>>
>> Good luck, Bill
>>
>> On Wed, Feb 12, 2020 at 3:17 PM Phil Kauffman 
>> wrote:
>>
>>> Hello, I am struggling with trying to filter child objects based on
>>> parent object selection on index.html (sites.html in example). On my
>>> sites.html, I list the office sites and a button to click for each, upon
>>> clicking I want to load the profile list for users only at that site,
>>> presently it's loading all profiles for all sites, which I assume is
>>> because the profiles are loaded statically no matter which button is
>>> clicked on sites.html.
>>>
>>> I'm thinking I need a JS onclick event?
>>>
>>> models.py:
>>> class Site(models.Model):
>>>
>>> name = models.CharField(max_length=50)
>>> date = models.DateField()
>>> manager = models.CharField(max_length=50)
>>>
>>> def save(self, *args, **kwargs):
>>> super(Site, self).save(*args, **kwargs)
>>>
>>> class Profile(models.Model):
>>> Days = '1st'
>>> Mids = '2nd'
>>> Nights = '3rd'
>>> Work_Schedule_Choices = [
>>>   (Days, 'Day Shift'),
>>>   (Mids, 'Mid Shift'),
>>>   (Nights, 'Night Shift'),
>>> ]
>>> sitename = models.ForeignKey(Site, on_delete=models.CASCADE)
>>> title = models.CharField(max_length=100)
>>> schedule = models.CharField(max_length=3,choices=
>>> Work_Schedule_Choices,default=Days)
>>> totalusers = models.PositiveSmallIntegerField(default=1, validators
>>> =[MinValueValidator(1), MaxValueValidator(50)])
>>>
>>>
>>>
>>> views.py:
>>> def sites(request):
>>> sitelist = Site.objects.all()
>>> return render (request, 'App/sites.html', 

Re: Unit Testing POST request

2020-02-13 Thread sachinbg sachin
Fistly for setup create use instance for setup user credentials then call
that the reverse url in that post put delite

On Thu, Feb 13, 2020, 8:01 PM Adam Mičuda  wrote:

> Hi,
> or you can extract the business logic from view to some service and unit
> test it instead. =)
>
> Regards.
>
> Adam
>
> st 12. 2. 2020 v 21:15 odesílatel onlinejudge95 
> napsal:
>
>> On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
>> wrote:
>>
>>> Hi Devs,
>>>
>>> I was implementing unit-tests in my Django project and stumbled upon the
>>> following issue.
>>>
>>> I want to unit-test my POST route. I do not want to use the test client
>>> already shipped with Django (using it in my e2e tests). I want to know how
>>> do I prepare my request object to pass to my view. Here is what I have done
>>> currently.
>>>
>>> test_views.py
>>>
 class CreateBlogTest(BaseViewTest):
>>>
>>> @classmethod
 def setUpClass(cls):
 cls.request.method = "POST"
>>>
>>> def test_create_valid_blog(self):
 self.request.content_type = "application/json"
 self.request._body = json.dumps({"title": "new title", "body":
 "new body"})

 response = views.blog_collection(self.request)
 self.assertEqual(response.status_code, 201)

>>>
>>> In my view, I am accessing the data through *request.data* and passing
>>> it to a serializer.
>>>
>>> In my current setting, I am getting a 400 error message when I have
>>> checked that the user does not exist.
>>>
>>> Any suggestions regarding the same?
>>>
>>> Thanks,
>>> onlinejudge95
>>>
>>
>> In case if someone needs it in the future, go and look at
>> *django.test.RequestFactory *
>>
>> https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory
>>
>> --
>> 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/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%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/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%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/CAOs61rxaSRrE239aZrbBpZSo7QBoZx2BKxx4nBiERhio0RGSJg%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-13 Thread Adam Mičuda
Hi,
or you can extract the business logic from view to some service and unit
test it instead. =)

Regards.

Adam

st 12. 2. 2020 v 21:15 odesílatel onlinejudge95 
napsal:

> On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
> wrote:
>
>> Hi Devs,
>>
>> I was implementing unit-tests in my Django project and stumbled upon the
>> following issue.
>>
>> I want to unit-test my POST route. I do not want to use the test client
>> already shipped with Django (using it in my e2e tests). I want to know how
>> do I prepare my request object to pass to my view. Here is what I have done
>> currently.
>>
>> test_views.py
>>
>>> class CreateBlogTest(BaseViewTest):
>>
>> @classmethod
>>> def setUpClass(cls):
>>> cls.request.method = "POST"
>>
>> def test_create_valid_blog(self):
>>> self.request.content_type = "application/json"
>>> self.request._body = json.dumps({"title": "new title", "body":
>>> "new body"})
>>>
>>> response = views.blog_collection(self.request)
>>> self.assertEqual(response.status_code, 201)
>>>
>>
>> In my view, I am accessing the data through *request.data* and passing
>> it to a serializer.
>>
>> In my current setting, I am getting a 400 error message when I have
>> checked that the user does not exist.
>>
>> Any suggestions regarding the same?
>>
>> Thanks,
>> onlinejudge95
>>
>
> In case if someone needs it in the future, go and look at
> *django.test.RequestFactory *
>
> https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory
>
> --
> 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/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%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/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com.


Re: Separating django business logiv from views

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 6:34 PM Mrunalini Ramnath 
wrote:

> Hey folks!
> I've been researching on effective ways to separate business logic from
> views.py. I currently also have separate files for helper functions but the
> codebase is still a little cluttered.
>

How about going on the traditional MVC way?

Your views act as controllers with only one concern i.e. to operate on the
HTTP plane, call services, raise exceptions maybe.

I generally create a *service.py* in each app to implement the business
logic and just call it inside my *views.py*. It helps to make my business
logic loosely coupled with the web-server. Also, it has an upside that it
makes testing easier.


> I found this method of implementation that involves creating a manager
> class for each model that can contain all the necessary functions, and thin
> views for executing said function. There are quite a few sources pertaining
> to this but I found this to be the strongest one in support so far:
> https://sunscrapers.com/blog/where-to-put-business-logic-django/#Idea_4_QuerySetsManagers
>
> Are there any more pros and cons that haven't been discussed in it?
>
> --
> 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/a893a097-c091-42ae-9638-ec4cf0ec8a9d%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/CAD%3DM5eTWKRMcszkWA3EEEUbauQ7n3qKoB1VBrDc9BJ4uj9a%2BYQ%40mail.gmail.com.


Re: Django: how to make queries between 2 tables that are not related in the model?

2020-02-13 Thread Mehul Anshumali
Connect one table with another table using foreign key and then in command
prompt type python manage.py shell and then import your table in shell then
write queries .

On Thu, Feb 13, 2020, 2:59 PM Jérôme Le Carrou  wrote:

> Hi,
>
> I have 2 models that are not related (maybe it should...)
>
> I need to make a query that select all records of my table Stock WITH
> related rows in Parametrage based on asp_sto_loc=asp_par_loc
>
> Something like SQL: select * from pha_asp_sto left join pha_asp_par on
> pha_asp_par.asp_par_loc=asp_sto_loc;
>
> How can I make such a query in Django?
> I have see extra() but seems to be deprecated...
> Another option would be to use raw() but not recommended...
>
> class Stock(models.Model):
>
> asp_sto_cle = models.AutoField(primary_key=True)
> asp_sto_loc = models.CharField("Site concerned", max_length=10, 
> null=True, blank=True)
> asp_sto_pla = models.IntegerField("Quantity of placebos available", 
> null=True, blank=True,)
> asp_sto_asp = models.IntegerField("Quantity of aspirin available", 
> null=True, blank=True)
> class Parametrage(models.Model):
>
> asp_par_cle = models.AutoField(primary_key=True)
> asp_par_loc = models.CharField("Site concerned by settings", 
> max_length=10, null=True, blank=True)
> asp_par_ale = models.IntegerField("Site alert value for the site", 
> null=True, blank=True,)
> asp_par_con = models.IntegerField("Site confort value for the site", 
> null=True, blank=True,)
>
> thanks for your help
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/029c93e0-4093-4a4f-bc99-b3af000c3c31%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/CAL115XxLDx4vVeGeocRSjwvnW_gz7cKwCHDd6KaEP7hpiffLTQ%40mail.gmail.com.


Re: Manually running a script that imports a Django model

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 6:34 PM Sourish Kundu 
wrote:

> So I am trying to access one of my models created in views.py in another
> script. This second script is the one I would like manually run. It imports
> the model without any errors; however, when I try to run it using PyCharm,
> I get this error:
>

Firstly, what are your models doing in views.py? I am assuming it was a
typo.


>
> *django.core.exceptions.ImproperlyConfigured: Requested setting
> INSTALLED_APPS, but settings are not configured. You must either define the
> environment variable DJANGO_SETTINGS_MODULE or call settings.configure()
> before accessing settings.*
>
> Any help on resolving this issue would be very much appreciated.
>

For scripts like these that are not part of your web server or that do not
take part in the request-response cycle, I like to implement them as custom
Django commands. You can read more about them here
.


>
>
> Thanks,
> Sourish
>
> --
> 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/2c9b2d34-a9ab-4a2f-a1e4-e2694c265ea0%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/CAD%3DM5eSBrbLvnFBzoGfOaJk3NnWG8t1N2aOQTmHR6TDsup3F%2BA%40mail.gmail.com.


Re: Django: how to make queries between 2 tables that are not related in the model?

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 2:59 PM Jérôme Le Carrou 
wrote:

> Hi,
>
> I have 2 models that are not related (maybe it should...)
>
> I need to make a query that select all records of my table Stock WITH
> related rows in Parametrage based on asp_sto_loc=asp_par_loc
>
> Something like SQL: select * from pha_asp_sto left join pha_asp_par on
> pha_asp_par.asp_par_loc=asp_sto_loc;
>

Have a look at django.db.models.SubQuery



How can I make such a query in Django?
> I have see extra() but seems to be deprecated...
> Another option would be to use raw() but not recommended...
>
> class Stock(models.Model):
>
> asp_sto_cle = models.AutoField(primary_key=True)
> asp_sto_loc = models.CharField("Site concerned", max_length=10, 
> null=True, blank=True)
> asp_sto_pla = models.IntegerField("Quantity of placebos available", 
> null=True, blank=True,)
> asp_sto_asp = models.IntegerField("Quantity of aspirin available", 
> null=True, blank=True)
> class Parametrage(models.Model):
>
> asp_par_cle = models.AutoField(primary_key=True)
> asp_par_loc = models.CharField("Site concerned by settings", 
> max_length=10, null=True, blank=True)
> asp_par_ale = models.IntegerField("Site alert value for the site", 
> null=True, blank=True,)
> asp_par_con = models.IntegerField("Site confort value for the site", 
> null=True, blank=True,)
>
> thanks for your help
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/029c93e0-4093-4a4f-bc99-b3af000c3c31%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/CAD%3DM5eQiPuR%3DsASF04wv6sdCUhiRu-oyfiLq60axZr%3D3qF-i0w%40mail.gmail.com.


Re: Manually running a script that imports a Django model

2020-02-13 Thread Adam Mičuda
Hi,
the solution is written in the error message "You must either define the
environment variable DJANGO_SETTINGS_MODULE or call
settings.configure()...". But I would recommend you to use
https://django-extensions.readthedocs.io/en/latest/runscript.html. I think
it is what you are want. ;)

Regards.

Adam

čt 13. 2. 2020 v 14:03 odesílatel Sourish Kundu 
napsal:

> So I am trying to access one of my models created in views.py in another
> script. This second script is the one I would like manually run. It imports
> the model without any errors; however, when I try to run it using PyCharm,
> I get this error:
>
> *django.core.exceptions.ImproperlyConfigured: Requested setting
> INSTALLED_APPS, but settings are not configured. You must either define the
> environment variable DJANGO_SETTINGS_MODULE or call settings.configure()
> before accessing settings.*
>
> Any help on resolving this issue would be very much appreciated.
>
>
> Thanks,
> Sourish
>
> --
> 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/2c9b2d34-a9ab-4a2f-a1e4-e2694c265ea0%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/CAB9%3DGXasEd5NmCzc9B4dw4xZUdcPZnqNg_maQJqQ%2B%2B_gjCG1mA%40mail.gmail.com.


Re: makemessages fails

2020-02-13 Thread Yves de Champlain
Actually, while 

django-admin makemessages -l fr

fails, 

python manage.py makemessages -l fr

works well, so the problem really is the custom 

/config/settings/common.py

settings file that need the DJANGO_SETTINGS_MODULE 

 environment variable included in manage,py.

Thanks for your help !

yves



Le jeudi 13 février 2020 00:20:54 UTC-5, Yash Garg a écrit :
>
> Go through i18n official documentation and specify path according to that.
>
> On Thu 13 Feb, 2020, 10:25 AM Yves de Champlain,  > wrote:
>
>> Hi
>>
>> I have
>>
>> ROOT_DIR = environ.Path(__file__) - 3  # 
>> (base_dir/config/settings/common.py - 3 = base_dir/)
>> PROJ_DIR = ROOT_DIR
>>
>> LOCALE_PATHS = [
>> PROJ_DIR('locale'),
>> ]
>>
>> Could it be the source of the problem ?
>>
>> Thanks !
>>
>>
>>
>> Le mercredi 12 février 2020 12:53:06 UTC-5, Yash Garg a écrit :
>>>
>>> Have you specified path to Locale directory in settings.py?
>>>
>>> On Wednesday, February 12, 2020 at 7:51:53 PM UTC+5:30, Yves de 
>>> Champlain wrote:

 Hi

 When I run 

 django-admin makemessages -l fr

 I get 

 Traceback (most recent call last): 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/base.py"
 , line 323, in run_from_argv 

  self.execute(*args, **cmd_options) 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/base.py"
 , line 364, in execute 

  output = self.handle(*args, **options) 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/commands/makemessages.py"
 , line 353, in handle 

  if self.settings_available: 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/utils/functional.py"
 , line 80, in __get__ 

  res = instance.__dict__[self.name] = self.func(instance) 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/commands/makemessages.py"
 , line 413, in settings_available 

  settings.LOCALE_PATHS 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/conf/__init__.py"
 , line 79, in __getattr__ 

  self._setup(name) 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/conf/__init__.py"
 , line 66, in _setup 

  self._wrapped = Settings(settings_module) 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/conf/__init__.py"
 , line 157, in __init__ 

  mod = importlib.import_module(self.SETTINGS_MODULE) 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/importlib/__init__.py", 
 line 127, in import_module 

  return _bootstrap._gcd_import(name[level:], package, level) 

  File "", line 1006, in _gcd_import 

  File "", line 983, in _find_and_load 

  File "", line 953, in 
 _find_and_load_unlocked 

  File "", line 219, in 
 _call_with_frames_removed 

  File "", line 1006, in _gcd_import 

  File "", line 983, in _find_and_load 

  File "", line 953, in 
 _find_and_load_unlocked 

  File "", line 219, in 
 _call_with_frames_removed 

  File "", line 1006, in _gcd_import 

  File "", line 983, in _find_and_load 

  File "", line 965, in 
 _find_and_load_unlocked 

 ModuleNotFoundError: No module named 'config' 


 During handling of the above exception, another exception occurred: 


 Traceback (most recent call last): 

  File "/opt/miniconda3/envs/cert_tool/bin/django-admin", line 10, in 
  

  sys.exit(execute_from_command_line()) 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/__init__.py"
 , line 381, in execute_from_command_line 

  utility.execute() 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/__init__.py"
 , line 375, in execute 

  self.fetch_command(subcommand).run_from_argv(self.argv) 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/base.py"
 , line 336, in run_from_argv 

  connections.close_all() 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/db/utils.py"
 , line 219, in close_all 

  for alias in self: 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/db/utils.py"
 , line 213, in __iter__ 

  return iter(self.databases) 

  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/utils/functional.py"
 , line 80, in 

Separating django business logiv from views

2020-02-13 Thread Mrunalini Ramnath
Hey folks!
I've been researching on effective ways to separate business logic from 
views.py. I currently also have separate files for helper functions but the 
codebase is still a little cluttered. 
I found this method of implementation that involves creating a manager 
class for each model that can contain all the necessary functions, and thin 
views for executing said function. There are quite a few sources pertaining 
to this but I found this to be the strongest one in support so far: 
https://sunscrapers.com/blog/where-to-put-business-logic-django/#Idea_4_QuerySetsManagers
 
Are there any more pros and cons that haven't been discussed in it? 

-- 
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/a893a097-c091-42ae-9638-ec4cf0ec8a9d%40googlegroups.com.


Re: Is a Custom User Model worth the headache?

2020-02-13 Thread SikoraD
Hi Ben,

I'll highly recommended to read fantastic post on Will Vincent 
 blog -> 
https://wsvincent.com/django-tips-custom-user-model/
His approach is much easier than one on django website and it is worth to 
have look.

Also his djangox repo on github is very useful.

Best Regards
Damian


Hi.  
>
> I read the part where it's "highly recommended" to create a custom user 
> model, but I don't see why it's worth the headache.  I found these problems:
>
> 1 In the admin panel, my auth groups are in a separate app from my users
> 2 There is some disagreement out there about how apps should refer to a 
> user model now that the user model might be custom
> 3 A lot of features that I would add are app specific, and therefore would 
> be better handled by app specific profiles
> 4 There's a new entry point for possible errors and glitches
>
> So why do this? 
>
> Thanks,
> Ben 
>

-- 
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/3b3d9cbf-4637-4d77-9cd4-94f12098debe%40googlegroups.com.


Manually running a script that imports a Django model

2020-02-13 Thread Sourish Kundu
So I am trying to access one of my models created in views.py in another 
script. This second script is the one I would like manually run. It imports 
the model without any errors; however, when I try to run it using PyCharm, 
I get this error:

*django.core.exceptions.ImproperlyConfigured: Requested setting 
INSTALLED_APPS, but settings are not configured. You must either define the 
environment variable DJANGO_SETTINGS_MODULE or call settings.configure() 
before accessing settings.*

Any help on resolving this issue would be very much appreciated.


Thanks,
Sourish

-- 
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/2c9b2d34-a9ab-4a2f-a1e4-e2694c265ea0%40googlegroups.com.


Re: Django Hands On with Industry Oriented application

2020-02-13 Thread Ahmed Hashim
Hi, will this be an online training session? Total duration with charges?

regards

Ahmed

On Thu, Feb 13, 2020 at 12:44 PM Saswat Ray  wrote:

> Please contact to 8885505922 for detail or direct mail me your contact
> number
>
> *Thanks*,
> *Saswat*
>
> https://www.linkedin.com/in/saswat-ray-27313316/
> https://www.quora.com/profile/Saswat-Ray
>
>
>
> On Thu, Feb 13, 2020 at 12:30 PM paarull shukla <
> shukla.paarull...@gmail.com> wrote:
>
>> Heloo sir I want to join ur session please let me know how much charge I
>> have to make and where.
>>
>> On Thu, 13 Feb, 2020, 11:50 AM Saswat Ray,  wrote:
>>
>>> Hi,
>>>
>>> I am starting a new online batch to make student or professional to
>>> learn this most sought after web development experience.Let me know if
>>> anyone interested.Its a weekend online paid session.After successfully
>>> completed the session with task, i can refer candidates to my
>>> connections(please note i am not guarantee any job, i will help candidate
>>> to make right decision and make them industry ready).
>>>
>>>
>>> *Thanks*,
>>> *Saswat*
>>>
>>> https://www.linkedin.com/in/saswat-ray-27313316/
>>> https://www.quora.com/profile/Saswat-Ray
>>> https://github.com/raysaswat
>>>
>>> --
>>> 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/CAEhPkLHPJM3-umuZs45GOviCPXdziVOCd%2BsnaHxHjLw-Jr2VaA%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/CACLQzsc0wbtrCpJy_%3DR6%2BiaE89bSwuym7CdHqhyh_79cM%2BcM%2BA%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/CAEhPkLGWxxQd24Jm4XAk1E_-%2BLHdjVtTrqNv5hri3v8ZdGutjg%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/CAM9M4N80150hfykB_n1sJOi89k3%3D_Z5pzMPebSCKPY2Z4kH4UQ%40mail.gmail.com.


Can anyone explain the incompatible change about “model.save()” in Django 3.0

2020-02-13 Thread Michael Zheng
>From the office release note, it says

Model.save() no longer attempts to find a row when saving a new Model instance 
and a default value for the primary key is provided, and always performs a 
single INSERT query. 

In order to update an existing model for a specific primary key value, use the 
update_or_create() method or QuerySet.filter(pk=…).update(…) instead. 

But when I trired this:

Class Order(models.Model):
status = models.PositiveSmallIntegerField(default=1)

order = Order.objects.filter(id=1).first()
order.status = 2
order.save()
or

order = Order()
order.id =1
order.status=2
order.save()

where id=1 has existed in db. But it still works well. Why?

-- 
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/6de039a4-482e-4a0a-90ce-735ba6c98494%40googlegroups.com.


Re: makemessages fails

2020-02-13 Thread maninder singh Kumar
Is the app installed in settings.py

Sent from my iPad

> On 13-Feb-2020, at 10:49 AM, Yash Garg  wrote:
> 
> Go through i18n official documentation and specify path according to that.
> 
>> On Thu 13 Feb, 2020, 10:25 AM Yves de Champlain,  wrote:
>> Hi
>> 
>> I have
>> 
>> ROOT_DIR = environ.Path(__file__) - 3  # (base_dir/config/settings/common.py 
>> - 3 = base_dir/)
>> PROJ_DIR = ROOT_DIR
>> 
>> LOCALE_PATHS = [
>> PROJ_DIR('locale'),
>> ]
>> 
>> Could it be the source of the problem ?
>> 
>> Thanks !
>> 
>> 
>> 
>> Le mercredi 12 février 2020 12:53:06 UTC-5, Yash Garg a écrit :
>>> 
>>> Have you specified path to Locale directory in settings.py?
>>> 
>>> On Wednesday, February 12, 2020 at 7:51:53 PM UTC+5:30, Yves de Champlain 
>>> wrote:
 
 Hi
 
 When I run 
 
 django-admin makemessages -l fr
 
 I get 
 
 Traceback (most recent call last): 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/base.py",
  line 323, in run_from_argv 
 
  self.execute(*args, **cmd_options) 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/base.py",
  line 364, in execute 
 
  output = self.handle(*args, **options) 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/commands/makemessages.py",
  line 353, in handle 
 
  if self.settings_available: 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/utils/functional.py",
  line 80, in __get__ 
 
  res = instance.__dict__[self.name] = self.func(instance) 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/commands/makemessages.py",
  line 413, in settings_available 
 
  settings.LOCALE_PATHS 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/conf/__init__.py",
  line 79, in __getattr__ 
 
  self._setup(name) 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/conf/__init__.py",
  line 66, in _setup 
 
  self._wrapped = Settings(settings_module) 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/conf/__init__.py",
  line 157, in __init__ 
 
  mod = importlib.import_module(self.SETTINGS_MODULE) 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/importlib/__init__.py", line 
 127, in import_module 
 
  return _bootstrap._gcd_import(name[level:], package, level) 
 
  File "", line 1006, in _gcd_import 
 
  File "", line 983, in _find_and_load 
 
  File "", line 953, in 
 _find_and_load_unlocked 
 
  File "", line 219, in 
 _call_with_frames_removed 
 
  File "", line 1006, in _gcd_import 
 
  File "", line 983, in _find_and_load 
 
  File "", line 953, in 
 _find_and_load_unlocked 
 
  File "", line 219, in 
 _call_with_frames_removed 
 
  File "", line 1006, in _gcd_import 
 
  File "", line 983, in _find_and_load 
 
  File "", line 965, in 
 _find_and_load_unlocked 
 
 ModuleNotFoundError: No module named 'config' 
 
 
 During handling of the above exception, another exception occurred: 
 
 
 Traceback (most recent call last): 
 
  File "/opt/miniconda3/envs/cert_tool/bin/django-admin", line 10, in 
  
 
  sys.exit(execute_from_command_line()) 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/__init__.py",
  line 381, in execute_from_command_line 
 
  utility.execute() 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/__init__.py",
  line 375, in execute 
 
  self.fetch_command(subcommand).run_from_argv(self.argv) 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/core/management/base.py",
  line 336, in run_from_argv 
 
  connections.close_all() 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/db/utils.py",
  line 219, in close_all 
 
  for alias in self: 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/db/utils.py",
  line 213, in __iter__ 
 
  return iter(self.databases) 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/utils/functional.py",
  line 80, in __get__ 
 
  res = instance.__dict__[self.name] = self.func(instance) 
 
  File 
 "/opt/miniconda3/envs/cert_tool/lib/python3.7/site-packages/django/db/utils.py",
  line 147, in databases 
 
  self._databases = settings.DATABASES 
 
  File 
 

Re: filter objects dynamically on page render based on button click (beginner question)

2020-02-13 Thread maninder singh Kumar
Have you looked at permissions ?

Sent from my iPad

> On 13-Feb-2020, at 6:06 PM, Phil Kauffman  wrote:
> 
> Bill,
> 
> Thank You for taking the time to respond. I will definitely need to read up 
> on the options you presented. My first inclination was to get familiar with 
> the first option as it seems easiest. However, now that you mention VueJS I 
> will look into that as well.
> 
>> On Wednesday, February 12, 2020 at 6:46:42 PM UTC-5, ke1g wrote:
>> What happens in the browser stays in the browser, unless you do something 
>> about it.
>> 
>> Forgive me if I'm being too basic below:
>> 
>> There are three approaches to click and see a filtering change, with trade 
>> offs in performance, complexity, and the impact if the user's browser is on 
>> a humble box.
>> When the user clicks, it's on a link, and you reload the page with the 
>> filter applied.  No JavaScript required.  Pretty slow.  more network load, 
>> more browser load, and more load on the server.  (I'm not going into the old 
>> approach of having an iframe and the link reloads the iframe because iframes 
>> are tricky, and if you're showing a big table, it's most of the page 
>> anyway.)  Do be sure that your images, CSS files, and JavaScript files are 
>> set to encourage the browser and/or the network to cache them, but the HTML 
>> will load every time, and the URL will likely show the filter settings 
>> (though you can do things with cookies and/or session store, but you will 
>> surprise your users someday.
>> Load all the data in the first place, and use JavaScript in combination with 
>> CSS to hide the stuff that's filtered out.  If you go this way, do arrange 
>> to use CSS controlled by a class on a single containing element to control 
>> visibility, because doing big DOM modifications in JavaScript performs 
>> poorly.  This is the snappiest approach, but you have to have loaded 
>> everything, at cost of network and server load, even if you expect the user 
>> to filter later, and at the cost of RAM in the browser.  If the data's not 
>> that big, this is fine.  But if it's the catalog of a hardware chain or 
>> something else huge, you probably be doing it in pages.  Sometimes it's 
>> natural.  For example, I once did and event calendar for a school system.  I 
>> loaded a month at a time, and filtering within the month was peppy, but to 
>> go to a different month required a reload, and you couldn't show stuff from 
>> multiple months at one time.
>> Use an AJAX request to replace part of the DOM with filtered data.  (The 
>> iframe hack is very much like this.)  If the data is most of your page, this 
>> isn't much more light weight than option 1, but the user doesn't see the 
>> page reload, which seems to count for style points.
>> There are JavaScript "frameworks" (e.g. VueJS) that will help you with 2 and 
>> especially 3, but you have to learn how to use the framework, and how to 
>> connect it to Django.  Those are useful things to learn, but they're not 
>> overnight reads, and can have performance pitfalls.
>> 
>> Good luck, Bill
>> 
>>> On Wed, Feb 12, 2020 at 3:17 PM Phil Kauffman  wrote:
>>> Hello, I am struggling with trying to filter child objects based on parent 
>>> object selection on index.html (sites.html in example). On my sites.html, I 
>>> list the office sites and a button to click for each, upon clicking I want 
>>> to load the profile list for users only at that site, presently it's 
>>> loading all profiles for all sites, which I assume is because the profiles 
>>> are loaded statically no matter which button is clicked on sites.html.
>>> 
>>> I'm thinking I need a JS onclick event?
>>> 
>>> models.py:
>>> class Site(models.Model):
>>> 
>>> name = models.CharField(max_length=50)
>>> date = models.DateField()
>>> manager = models.CharField(max_length=50)
>>> 
>>> def save(self, *args, **kwargs):
>>> super(Site, self).save(*args, **kwargs)
>>>  
>>> class Profile(models.Model):
>>> Days = '1st'
>>> Mids = '2nd'
>>> Nights = '3rd'
>>> Work_Schedule_Choices = [
>>>   (Days, 'Day Shift'),
>>>   (Mids, 'Mid Shift'),
>>>   (Nights, 'Night Shift'),
>>> ]   
>>> sitename = models.ForeignKey(Site, on_delete=models.CASCADE)
>>> title = models.CharField(max_length=100)
>>> schedule = 
>>> models.CharField(max_length=3,choices=Work_Schedule_Choices,default=Days)
>>> totalusers = models.PositiveSmallIntegerField(default=1, 
>>> validators=[MinValueValidator(1), MaxValueValidator(50)])
>>> 
>>> 
>>> 
>>> views.py:
>>> def sites(request):
>>> sitelist = Site.objects.all()
>>> return render (request, 'App/sites.html', {'sitelist' : sitelist})
>>> 
>>> def sitedetail(request):
>>> site = Site.objects.filter()
>>> if request.method == 'GET':
>>> return render(request, 'App/site-detail.html', {'site': site, 
>>> 'profile_set': Profile.objects.all()})
>>> 
>>> 
>>> sites.html (index)
>>> {% extends 

Re: Django: how to make queries between 2 tables that are not related in the model?

2020-02-13 Thread maninder singh Kumar
You of course mean, no foreign key ?
Are the models pre written so no change can be made to them.

Sent from my iPad

> On 13-Feb-2020, at 2:58 PM, Jérôme Le Carrou  wrote:
> 
> Hi,
> 
> I have 2 models that are not related (maybe it should...)
> 
> I need to make a query that select all records of my table Stock WITH related 
> rows in Parametrage based on asp_sto_loc=asp_par_loc
> 
> Something like SQL: select * from pha_asp_sto left join pha_asp_par on 
> pha_asp_par.asp_par_loc=asp_sto_loc;
> 
> How can I make such a query in Django?
> I have see extra() but seems to be deprecated...
> Another option would be to use raw() but not recommended...
> 
> class Stock(models.Model):
> 
> asp_sto_cle = models.AutoField(primary_key=True)
> asp_sto_loc = models.CharField("Site concerned", max_length=10, 
> null=True, blank=True)
> asp_sto_pla = models.IntegerField("Quantity of placebos available", 
> null=True, blank=True,)
> asp_sto_asp = models.IntegerField("Quantity of aspirin available", 
> null=True, blank=True)
> 
> class Parametrage(models.Model):
> 
> asp_par_cle = models.AutoField(primary_key=True)
> asp_par_loc = models.CharField("Site concerned by settings", 
> max_length=10, null=True, blank=True)
> asp_par_ale = models.IntegerField("Site alert value for the site", 
> null=True, blank=True,)
> asp_par_con = models.IntegerField("Site confort value for the site", 
> null=True, blank=True,)
> 
> thanks for your help 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/029c93e0-4093-4a4f-bc99-b3af000c3c31%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/90F33E3C-4554-44C9-BDBE-0AFCD8E46FD9%40gmail.com.


Re: filter objects dynamically on page render based on button click (beginner question)

2020-02-13 Thread Phil Kauffman
Bill,

Thank You for taking the time to respond. I will definitely need to read up 
on the options you presented. My first inclination was to get familiar with 
the first option as it seems easiest. However, now that you mention VueJS I 
will look into that as well.

On Wednesday, February 12, 2020 at 6:46:42 PM UTC-5, ke1g wrote:

> What happens in the browser stays in the browser, unless you do something 
> about it.
>
> Forgive me if I'm being too basic below:
>
> There are three approaches to click and see a filtering change, with trade 
> offs in performance, complexity, and the impact if the user's browser is on 
> a humble box.
>
>1. When the user clicks, it's on a link, and you reload the page with 
>the filter applied.  No JavaScript required.  Pretty slow.  more network 
>load, more browser load, and more load on the server.  (I'm not going into 
>the old approach of having an iframe and the link reloads the iframe 
>because iframes are tricky, and if you're showing a big table, it's most 
> of 
>the page anyway.)  Do be sure that your images, CSS files, and JavaScript 
>files are set to encourage the browser and/or the network to cache them, 
>but the HTML will load every time, and the URL will likely show the filter 
>settings (though you can do things with cookies and/or session store, but 
>you will surprise your users someday.
>2. Load all the data in the first place, and use JavaScript in 
>combination with CSS to hide the stuff that's filtered out.  If you go 
> this 
>way, do arrange to use CSS controlled by a class on a single containing 
>element to control visibility, because doing big DOM modifications in 
>JavaScript performs poorly.  This is the snappiest approach, but you have 
>to have loaded everything, at cost of network and server load, even if you 
>expect the user to filter later, and at the cost of RAM in the browser.  
> If 
>the data's not that big, this is fine.  But if it's the catalog of a 
>hardware chain or something else huge, you probably be doing it in pages.  
>Sometimes it's natural.  For example, I once did and event calendar for a 
>school system.  I loaded a month at a time, and filtering within the month 
>was peppy, but to go to a different month required a reload, and you 
>couldn't show stuff from multiple months at one time.
>3. Use an AJAX request to replace part of the DOM with filtered data.  
>(The iframe hack is very much like this.)  If the data is most of your 
>page, this isn't much more light weight than option 1, but the user 
> doesn't 
>see the page reload, which seems to count for style points.
>
> There are JavaScript "frameworks" (e.g. VueJS) that will help you with 2 
> and especially 3, but you have to learn how to use the framework, and how 
> to connect it to Django.  Those are useful things to learn, but they're not 
> overnight reads, and can have performance pitfalls.
>
> Good luck, Bill
>
> On Wed, Feb 12, 2020 at 3:17 PM Phil Kauffman  > wrote:
>
>> Hello, I am struggling with trying to filter child objects based on 
>> parent object selection on index.html (sites.html in example). On my 
>> sites.html, I list the office sites and a button to click for each, upon 
>> clicking I want to load the profile list for users only at that site, 
>> presently it's loading all profiles for all sites, which I assume is 
>> because the profiles are loaded statically no matter which button is 
>> clicked on sites.html.
>>
>> I'm thinking I need a JS onclick event? 
>>
>> models.py:
>> class Site(models.Model):
>>
>> name = models.CharField(max_length=50)
>> date = models.DateField()
>> manager = models.CharField(max_length=50)
>> 
>> def save(self, *args, **kwargs):
>> super(Site, self).save(*args, **kwargs)
>>  
>> class Profile(models.Model):
>> Days = '1st'
>> Mids = '2nd'
>> Nights = '3rd'
>> Work_Schedule_Choices = [
>>   (Days, 'Day Shift'),
>>   (Mids, 'Mid Shift'),
>>   (Nights, 'Night Shift'),
>> ]   
>> sitename = models.ForeignKey(Site, on_delete=models.CASCADE)
>> title = models.CharField(max_length=100)
>> schedule = models.CharField(max_length=3,choices=
>> Work_Schedule_Choices,default=Days)
>> totalusers = models.PositiveSmallIntegerField(default=1, validators=[
>> MinValueValidator(1), MaxValueValidator(50)])
>>
>>
>>
>> views.py:
>> def sites(request):
>> sitelist = Site.objects.all()
>> return render (request, 'App/sites.html', {'sitelist' : sitelist})
>>
>> def sitedetail(request):
>> site = Site.objects.filter()
>> if request.method == 'GET':
>> return render(request, 'App/site-detail.html', {'site': site, 
>> 'profile_set': Profile.objects.all()})
>>
>>
>> sites.html (index)
>> {% extends 'App\base.html' %}
>> {% load crispy_forms_tags %}
>> {% block title %}Site Home{% endblock %}
>> {% block content %}
>> 

Re: Running 2.7 python project with python 3.7

2020-02-13 Thread Luka Nik
Thank you very much.

Yeah, I overlooked that this is only django. My bad

Luka

On Thu, Feb 13, 2020 at 11:04 AM Kasper Laudrup 
wrote:

> Hi Luka,
>
> On 13/02/2020 10.53, Luka Nik wrote:
> > Is there a way to run a project with python 3.7 if it's written with
> > python 2.7?
> > And what are my options if not?
>
> The short answer is "it depends", the longer answer depends on you
> providing some more details, especially which kind of project you're
> talking about (are you able to modify the project to support Python 3
> etc.).
>
> Anyway, you'll probably have much more success if you ask your question
> (with more details) on a mailing list/forum dedicated to Python
> development. This is a mailing list for Django users.
>
> Kind regards,
>
> Kasper
>
> --
> 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/532cddbb-8dde-d96b-f42e-07f5befdfea4%40stacktrace.dk
> .
>

-- 
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/CAMqindt50jfJzg61y71%3D9dXJbg3o5F3t-y35ZJgoefgdVGeNUg%40mail.gmail.com.


Re: Running 2.7 python project with python 3.7

2020-02-13 Thread Kasper Laudrup

Hi Luka,

On 13/02/2020 10.53, Luka Nik wrote:
Is there a way to run a project with python 3.7 if it's written with 
python 2.7?

And what are my options if not?


The short answer is "it depends", the longer answer depends on you 
providing some more details, especially which kind of project you're 
talking about (are you able to modify the project to support Python 3 etc.).


Anyway, you'll probably have much more success if you ask your question 
(with more details) on a mailing list/forum dedicated to Python 
development. This is a mailing list for Django users.


Kind regards,

Kasper

--
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/532cddbb-8dde-d96b-f42e-07f5befdfea4%40stacktrace.dk.


Re: Running 2.7 python project with python 3.7

2020-02-13 Thread Nick Sarbicki
There is no natural reason as to why the project wouldn't run in python 3.7
unless you have written it in a way that is incompatible with 3.7

I would suggest simply trying to run it in python3.7 and seeing if you have
any errors. Do you have a test suite with high coverage? Run that in 3.7 -
it should be pretty revealing. On top of this

Otherwise there are guides online, including some advice here:
https://portingguide.readthedocs.io/en/latest/tools.html

I can recommend using pylint --py3k on your code as well, it will
immediately tell you of anything which won't work in 3.x.

If the code does not work in 3.7, your options are to rewrite the code so
that it does.


- Nick


On Thu, Feb 13, 2020 at 9:54 AM Luka Nik  wrote:

> Is there a way to run a project with python 3.7 if it's written with
> python 2.7?
> And what are my options if not?
> Cheers,
> Luka
>
> --
> 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/CAMqinds9QRA_7x5cJ4AbfzzsEpARH7NxUxYWWVf7m%3DaJD7RRMQ%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/CAGuvt925c_R-F2ZD8WCPXkONPKS%2BwjofM7LOTqF63y1oiYqktA%40mail.gmail.com.


Running 2.7 python project with python 3.7

2020-02-13 Thread Luka Nik
Is there a way to run a project with python 3.7 if it's written with python
2.7?
And what are my options if not?
Cheers,
Luka

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


Re: installation of django

2020-02-13 Thread Mohammed Alnajdi
Try this 

pip —default-timeout=10 -v install django

Your problem is either internet or antivirus.


> 
> On 13 Feb 2020, at 8:36 AM, paarull shukla  
> wrote:
> 
> 
> Sir please help me out. I m not able to install it.. Getting trouble  since 5 
> days back
> 
>> On Thu, 13 Feb, 2020, 5:29 AM Dimitri Forster,  
>> wrote:
>> Hey Paarul, 
>> 
>> The problem is that you are trying to call pip from the command prompt 
>> directly.
>> Try py -m pip install django and it should work. 
>> 
>> Better yet you could:
>> first create a new directory in a location of your choice ; > md 
>> directory_name
>> Go to the newly created directory; > cd directory_name
>> Create a virtual environment to test everything in a sandbox environment: > 
>> py -m venv .venv
>> Activate the virtual environment: > .venv\Scripts\activate
>> Install any python package with pip directly: venv > pip install 
>> python_package (example: pip install django)
>> Start a new dango project: .venv > django-admin startproject 
>> your_project_name
>> Met vriendelijke groeten | Kind regards,
>> 
>> Dimitri Forster
>> 
>> 
>>> On Tue, Feb 11, 2020 at 1:14 PM paarull shukla 
>>>  wrote:
>>> heloo guys i m not able to install django please help me it .i m facing 
>>> issue last 10 days . i m getting collecting django after tht installation 
>>> not started
>>> -- 
>>> 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/879c4e25-5ff9-4858-bf6d-b794bef3aed7%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/CAAVjHbNGJoUk4RY-rQgF8j5ofqsZXBt1BxACH%3D45wZCk-zd%2Bjw%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/CACLQzseTvirGVKSpUCS9tUv9MiqX2FRJMwi1O8Amv5XfDiSzBQ%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/9243B8E3-DCE9-4445-AB6D-82FE45C894D1%40gmail.com.


Django: how to make queries between 2 tables that are not related in the model?

2020-02-13 Thread Jérôme Le Carrou
Hi,

I have 2 models that are not related (maybe it should...)

I need to make a query that select all records of my table Stock WITH 
related rows in Parametrage based on asp_sto_loc=asp_par_loc

Something like SQL: select * from pha_asp_sto left join pha_asp_par on 
pha_asp_par.asp_par_loc=asp_sto_loc;

How can I make such a query in Django?
I have see extra() but seems to be deprecated...
Another option would be to use raw() but not recommended...

class Stock(models.Model):

asp_sto_cle = models.AutoField(primary_key=True)
asp_sto_loc = models.CharField("Site concerned", max_length=10, null=True, 
blank=True)
asp_sto_pla = models.IntegerField("Quantity of placebos available", 
null=True, blank=True,)
asp_sto_asp = models.IntegerField("Quantity of aspirin available", 
null=True, blank=True)
class Parametrage(models.Model):

asp_par_cle = models.AutoField(primary_key=True)
asp_par_loc = models.CharField("Site concerned by settings", max_length=10, 
null=True, blank=True)
asp_par_ale = models.IntegerField("Site alert value for the site", 
null=True, blank=True,)
asp_par_con = models.IntegerField("Site confort value for the site", 
null=True, blank=True,)

thanks for your help 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/029c93e0-4093-4a4f-bc99-b3af000c3c31%40googlegroups.com.