Makemigration not working.. Please help me

2018-07-02 Thread Tamilvanan Anbalagan

When i execute the makemigrations command i am getting below error 
pleae help me to resolve this




(py1) c:\TransportPortal\djangoproject>django-admin makemigrations portal
Traceback (most recent call last):
  File "c:\program files (x86)\python36-32\Lib\runpy.py", line 193, in 
_run_modu
le_as_main
"__main__", mod_spec)
  File "c:\program files (x86)\python36-32\Lib\runpy.py", line 85, in 
_run_code
exec(code, run_globals)
  File "C:\Users\nb97441\Envs\py1\Scripts\django-admin.exe\__main__.py", 
line 9,
 in 
  File 
"c:\users\nb97441\envs\py1\lib\site-packages\django\core\management\__ini
t__.py", line 371, in execute_from_command_line
utility.execute()
  File 
"c:\users\nb97441\envs\py1\lib\site-packages\django\core\management\__ini
t__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"c:\users\nb97441\envs\py1\lib\site-packages\django\core\management\__ini
t__.py", line 216, in fetch_command
klass = load_command_class(app_name, subcommand)
  File 
"c:\users\nb97441\envs\py1\lib\site-packages\django\core\management\__ini
t__.py", line 36, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
  File "c:\users\nb97441\envs\py1\lib\importlib\__init__.py", line 126, in 
impor
t_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 
"c:\users\nb97441\envs\py1\lib\site-packages\django\core\management\comma
nds\makemigrations.py", line 10, in 
from django.db.migrations.autodetector import MigrationAutodetector
  File 
"c:\users\nb97441\envs\py1\lib\site-packages\django\db\migrations\autodet
ector.py", line 11, in 
from django.db.migrations.questioner import MigrationQuestioner
  File 
"c:\users\nb97441\envs\py1\lib\site-packages\django\db\migrations\questio
ner.py", line 9, in 
from .loader import MigrationLoader
  File 
"c:\users\nb97441\envs\py1\lib\site-packages\django\db\migrations\loader.
py", line 8, in 
from django.db.migrations.recorder import MigrationRecorder
  File 
"c:\users\nb97441\envs\py1\lib\site-packages\django\db\migrations\recorde
r.py", line 9, in 
class MigrationRecorder:
  File 
"c:\users\nb97441\envs\py1\lib\site-packages\django\db\migrations\recorde
r.py", line 22, in MigrationRecorder
class Migration(models.Model):
  File 
"c:\users\nb97441\envs\py1\lib\site-packages\django\db\models\base.py", l
ine 100, in __new__
app_config = apps.get_containing_app_config(module)
  File 
"c:\users\nb97441\envs\py1\lib\site-packages\django\apps\registry.py", li
ne 244, in get_containing_app_config
self.check_apps_ready()
  File 
"c:\users\nb97441\envs\py1\lib\site-packages\django\apps\registry.py", li
ne 127, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.


(py1) c:\TransportPortal\djangoproject>python manage.py check
System check identified no issues (0 silenced).

(py1) c:\TransportPortal\djangoproject>


from django.db import models
from django.contrib.auth.models import User


class Post(models.Model):
post = models.CharField(max_length=255)
user = models.ForeignKey(User, on_delete=models.PROTECT)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/617b0048-6e23-4d82-b879-6e3b187ca039%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Set null value for floatfield

2018-07-02 Thread Rakhee Menon
Yeah! but now I get this error

'required': 'This field is required.', 'null': 'This field may not be 
null.', 'invalid': 'Invalid data. Expected a dictionary, but got 
{datatype}.'}
ipdb> serializer.errors
{'cast_weight': ['A valid number is required.']}

In models.py 
cast_weight = models.FloatField(null=True, blank=True)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9e7d3dad-776d-4515-b855-3847a1e2953c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic model fields using mysql?

2018-07-02 Thread hardik dadhich
it means that I can't do it on MySQL database! should I change the DB type 
and if so which one should I prefer! 
Postgres or NoSQL?

On Tuesday, July 3, 2018 at 3:20:40 AM UTC+5:30, Melvyn Sopacua wrote:
>
> On maandag 2 juli 2018 21:33:35 CEST hardik dadhich wrote:
>
>  
>
> > Can anyone tell me how can I make dynamic Django model fields? I mean to
>
> > say that I want to save excel file data in Django model using MySQL. and
>
> > excel column can vary. The user can upload 100 column table or he can be
>
> > upload 1000 column table in the database. so it is possible to add
>
> > dynamically in db.
>
>  
>
> It makes little sense to store this in a database, because you cannot 
> define relations for what you don't know about. But if you must ...
>
>  
>
> One way to do this is to use the EAV data model 
> . 
> This is because at 1000 columns = 1000 fields, you will most certainly hit 
> MySQL's maximum row size 
> .
>
>  
>
> -- 
>
> Melvyn Sopacua
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/058e3f9e-8168-4459-88f7-878b3462fd3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django windows apache tell if apache is working

2018-07-02 Thread Bob Bobsled
Hi,
I'm still stuck on getting Apache to verify as working with wsgi.
Wondering what I might be doing incorrectly.
I'm reading lots of tuts, but it's a jungle out there.

I changed the folder hierarchy for the project and app so
venv, django_project, and  django_app are all on the same level as manage.py
thus:
c:/wamp/www-src/django_project
c:/wamp/www-src/django_app
c:/wamp/www-src/venev
c:/wamp/www-src/manage.py

In wamp create folder named www-src alongside the www folder.
cd into www-src.

created a virtual environment:
Inside www-src run > virtualenv venv

ACTIVATE and DEACTIVATE:

then activate by
> venv\Scripts\activate

if that works see (venv) as a prefix to the command line.  To deactivate
type:
>venv\Scripts\deactivate.bat.
...or can also just use
(venv) c:\wamp\www-src >deactivate
-

DJANGO PROJECT, APP, and VENV:
Then with the virtual environment active, install Django with the local
instance of pip by typing: >pip install django

then created a new django project >python django-admin.py startproject
django_project

and on the same level as manage.py type
>django-admin.py startapp django_app

Should have django_app folder, django_project folder, venv folder, and
manage.py all on the same level.

SETUP SQLITE DATABASE:

in the top level folder (the one with manage.py in it), type this in:
> python manage.py migrate


START RUNSERVER:
> python manage.py runserver

see success...so far.
-
Trying to get Apache production server working...

SETUP STATIC files location:

in settings.py

SETTINGS.PY:

in settings.py change STATIC_URL to:

STATIC_URL = os.path.join(BASE_DIR, "static/")

...also set
STATIC_ROOT = os.path.join(BASE_DIR, "static/")

then run
>(venv) c:\wamp\www-src>manage.py collectstatic

(should see new static dir under www-src)
---

MIGRATIONS:

then from c:\wamp\www-src run
(venv) c:\wamp\www-src >manage.py makemigrations
then
(venv) c:\wamp\www-src >manage.py migrate

SETTINGS.PY

in settings.py change STATIC_URL to:

STATIC_URL = os.path.join(BASE_DIR, "static/")

...also set
STATIC_ROOT = os.path.join(BASE_DIR, "static/")

then run
>(venv) c:\wamp\www-src>manage.py collectstatic

(should see new static dir under www-src)
--
...per Jason's suggestion for simple view and url...

in DJANGO_APP/VIEWS.PY

def index(request):
return HttpResponse("Working!")

--
in DJANGO_APP/URLS.PY

from django_app.views import index
urlpatterns = [
path('', index),
]

-
APACHE HTTPD.CONF

#---mod_wgi-express config for location in python ---
LoadFile
"c:/users/administrator/appdata/local/programs/python/python36-32/python36.dll"
LoadModule wsgi_module
"c:/users/administrator/appdata/local/programs/python/python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"

WSGIPythonHome
"c:/users/administrator/appdata/local/programs/python/python36-32"
WSGIScriptAlias /django-project "C:/wamp/www-src/django_project/wsgi.py"
#WSGIPythonPath
"C:/wamp/www-src/django_project/:C:/wamp/www-src/venv/Lib/site-packages"
WSGIPythonPath "C:/wamp/www-src:C:/wamp/www-src/venv/Lib/site-packages"



Order deny,allow
Require all granted




APACHE HTTPD-VHOSTS.CONF


ServerName localhost
ServerAlias localhost
DocumentRoot c:/wamp/www

Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
#Require local
Require all granted




Alias /static c:/wamp/www-src/static

Require all granted



---

restart APACHE

...but what is the correct URL to test here?

tried localhost:8000 all pointing to various folders but nothing connects
so far.



On Sat, Jun 30, 2018 at 10:08 AM, Jason  wrote:

> I meant the tutorial at https://docs.djangoproject.
> com/en/2.0/intro/tutorial01/
>
> That said, there's a few different ways you can actually deploy, but
> digitalocean has some good resources for starting out.
>
> https://www.digitalocean.com/community/tutorials/how-to-
> serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04
>
> This one shows how to use apache on ubuntu, and you should be able to
> extrapolate to use wamp.
>
> what I would do is just set up a simple view to return a http response
> saying "working", and map that to the root.  Something like
>
> app/views
>
> def index(request):
> return HttpResponse("Working!")
>
> app/urls
>
> from app.views import index
> urlpatterns = [
> path('', index),
> ]
>
> and hit localhost.  That'll be all you need.
>
> Hi,
>> Thanks.
>> Yes, I went thru the Mozilla library tutorial on a fedora dev machine to
>> the point where I realized I needed to do more with the last mile, so to
>> speak working on setup of the production server part on Windows and wamp.
>> Seems most tuts end at manage.py runserver, or start into deployment from
>> dev to production.  I can't seem to locate a good uptodate tut 

Re: A few doubts with an implementation.

2018-07-02 Thread Vijay Khemlani
You can also use PubNub (https://www.pubnub.com/) or similar services

On Mon, Jul 2, 2018 at 10:29 AM Vineeth Sagar  wrote:

> Mikhailo Keda wrote:
>>
>> to fetch emails every N minutes or hours  -
>> http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
>> I want the user to know that the mails are being retrieved -
>> https://channels.readthedocs.io/en/latest/
>>
>
> Thanks Mikhailo for the prompt reply, I'll spend a few days reading the
> documentation of the libraries you have pointed me to. Are web sockets
> supported in IE, iirc I don't think they do. Half of our clients Will use
> IE, not edge, good old fucked up IE. Also I was expecting a critique on my
> ideas. I want to weigh the pro's and con's of my approach vs clerey's(It
> might be clear once I read the docs.)
>
> again thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/10ea3eba-a72f-4d33-8504-4658c0b810ef%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei08qdj0g5UOsjokDyQrTLPUoejqj1R_N_ot0uY2uqm13Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Running a django website on AWS EC2 on ubuntu

2018-07-02 Thread Jason
show your systemd file .  looks like an issue there

On Monday, July 2, 2018 at 7:13:44 PM UTC-4, Anirudh Jain wrote:
>
> I am getting the following error on running the command :-
>
> "sudo journalctl -u gunicorn"
>
> Error is :-
>
> Jul 02 20:05:35 ip-172-31-40-226 systemd[1]: Started gunicorn daemon.
> Jul 02 20:05:35 ip-172-31-40-226 systemd[1]: gunicorn.service: Main 
> process exited, code=exited, status=200/CHDIR
> Jul 02 20:05:35 ip-172-31-40-226 systemd[1]: gunicorn.service: Unit 
> entered failed state.
> Jul 02 20:05:35 ip-172-31-40-226 systemd[1]: gunicorn.service: Failed with 
> result 'exit-code'.
> Jul 02 20:44:45 ip-172-31-40-226 systemd[1]: Started gunicorn daemon.
> Jul 02 20:44:45 ip-172-31-40-226 systemd[1]: gunicorn.service: Main 
> process exited, code=exited, status=203/EXEC
> Jul 02 20:44:45 ip-172-31-40-226 systemd[1]: gunicorn.service: Unit 
> entered failed state.
> Jul 02 20:44:45 ip-172-31-40-226 systemd[1]: gunicorn.service: Failed with 
> result 'exit-code'.
>
>
> before running this command, I had saved the file gunicorn.service and run 
> the following commands :-
>
> sudo systemctl daemon-reload sudo systemctl start gunicorn sudo systemctl 
> enable gunicorn
>
> Command "sudo systemctl status gunicorn" also gave the eror as :-
>
> gunicorn.service - gunicorn daemon
>Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor 
> preset: enabled)
>Active: failed (Result: exit-code) since Mon 2018-07-02 23:09:49 UTC; 
> 16s ago
>  Main PID: 3671 (code=exited, status=203/EXEC)
>
> Jul 02 23:09:49 ip-172-31-40-226 systemd[1]: Started gunicorn daemon.
> Jul 02 23:09:49 ip-172-31-40-226 systemd[1]: gunicorn.service: Main 
> process exited, code=exited, status=203/EXEC
> Jul 02 23:09:49 ip-172-31-40-226 systemd[1]: gunicorn.service: Unit 
> entered failed state.
> Jul 02 23:09:49 ip-172-31-40-226 systemd[1]: gunicorn.service: Failed with 
> result 'exit-code'.
>
>
> Can anyone please tell me what is exactly the error and how to resolve it?
>
> Thank you.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a164dd88-8810-4ca8-ba4c-4f5b1bd2a14e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Running a django website on AWS EC2 on ubuntu

2018-07-02 Thread Anirudh Jain
I am getting the following error on running the command :-

"sudo journalctl -u gunicorn"

Error is :-

Jul 02 20:05:35 ip-172-31-40-226 systemd[1]: Started gunicorn daemon.
Jul 02 20:05:35 ip-172-31-40-226 systemd[1]: gunicorn.service: Main process 
exited, code=exited, status=200/CHDIR
Jul 02 20:05:35 ip-172-31-40-226 systemd[1]: gunicorn.service: Unit entered 
failed state.
Jul 02 20:05:35 ip-172-31-40-226 systemd[1]: gunicorn.service: Failed with 
result 'exit-code'.
Jul 02 20:44:45 ip-172-31-40-226 systemd[1]: Started gunicorn daemon.
Jul 02 20:44:45 ip-172-31-40-226 systemd[1]: gunicorn.service: Main process 
exited, code=exited, status=203/EXEC
Jul 02 20:44:45 ip-172-31-40-226 systemd[1]: gunicorn.service: Unit entered 
failed state.
Jul 02 20:44:45 ip-172-31-40-226 systemd[1]: gunicorn.service: Failed with 
result 'exit-code'.


before running this command, I had saved the file gunicorn.service and run 
the following commands :-

sudo systemctl daemon-reload sudo systemctl start gunicorn sudo systemctl 
enable gunicorn

Command "sudo systemctl status gunicorn" also gave the eror as :-

gunicorn.service - gunicorn daemon
   Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor 
preset: enabled)
   Active: failed (Result: exit-code) since Mon 2018-07-02 23:09:49 UTC; 
16s ago
 Main PID: 3671 (code=exited, status=203/EXEC)

Jul 02 23:09:49 ip-172-31-40-226 systemd[1]: Started gunicorn daemon.
Jul 02 23:09:49 ip-172-31-40-226 systemd[1]: gunicorn.service: Main process 
exited, code=exited, status=203/EXEC
Jul 02 23:09:49 ip-172-31-40-226 systemd[1]: gunicorn.service: Unit entered 
failed state.
Jul 02 23:09:49 ip-172-31-40-226 systemd[1]: gunicorn.service: Failed with 
result 'exit-code'.


Can anyone please tell me what is exactly the error and how to resolve it?

Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f4ed135b-362e-4838-a10a-3b2f2f46de44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie : Object copy - weird error :-)

2018-07-02 Thread Melvyn Sopacua
On vrijdag 29 juni 2018 09:44:40 CEST Mickael Barbo wrote:

> I try to create a way to archive (copy) the same object instance on an
> other DataBase.
> 
> I followed this advice : # https://stackoverflow.com/
> questions/21699707/python-how-to-copy-all-attibutes-from-
> base-class-to-derived-one

That advice is for normal python classes. Django models have some restrictions, 
one 
being that fields are special attributes. Messing with a model's __init__() is 
not something 
you normally do as a model's class creation is highly customized.

If you're really using 2 different databases, a model's save() operation 
supports a `using` 
keyword that allows you to select the database connection[1]. Archiving becomes 
really 
easy that way.


-- 
Melvyn Sopacua


[1] 
https://docs.djangoproject.com/en/2.0/topics/db/multi-db/#selecting-a-database-for-save

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2130083.vAuLGcjiVo%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Invalid HTTP_HOST header when website being accessed by public IP

2018-07-02 Thread Melvyn Sopacua
On maandag 2 juli 2018 17:25:20 CEST Kasper Laudrup wrote:

> Instead I added the following to my HTTPS server section:
> 
> if ($host != my-website.org {
> return 404;
>  }
> 
> Seems to solve my problem just fine. Letsencrypts certbot had already
> done something similar for the HTTP section redirect.

The only reason to set it up like that for HTTPS is that it's possible the SNI 
name differs from the HTTP Host header. For HTTP redirects it makes no sense: 
the HTTP header is in plain text and is used to determine the server block to 
pick. So putting an if statement there, is just doing it again, on every 
request, because electrons are cheap. Save the electrons!

Anyhow - instead of return 404, I would do:

return 301 https://$server_name$request_uri

How I normally set things up:

server {
listen 443 default_server ssl http2;
server_name localhost;

return 301 https://djangoserver.example.com$request_uri
}

server {
listen 443;
server_name djangoserver.example.com;

# ... django setup
}
-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1733971.5nBxyqRtuB%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic model fields using mysql?

2018-07-02 Thread Jason
or you can move to postgres and take advantage of the jsonfield integration 
with django.

On Monday, July 2, 2018 at 3:48:46 PM UTC-4, hardik dadhich wrote:
>
> Hello,
> Can anyone tell me how can I make dynamic Django model fields? I mean to 
> say that I want to save excel file data in Django model using MySQL. and 
> excel column can vary. The user can upload 100 column table or he can be 
> upload 1000 column table in the database. so it is possible to add 
> dynamically in db. 
>
> Any help would be appreciated.
> Thanks in advance!
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/67f4b6b9-d033-4432-95d9-d0110aa590af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic model fields using mysql?

2018-07-02 Thread Melvyn Sopacua
On maandag 2 juli 2018 21:33:35 CEST hardik dadhich wrote:

> Can anyone tell me how can I make dynamic Django model fields? I mean to
> say that I want to save excel file data in Django model using MySQL. and
> excel column can vary. The user can upload 100 column table or he can be
> upload 1000 column table in the database. so it is possible to add
> dynamically in db.

It makes little sense to store this in a database, because you cannot define 
relations for 
what you don't know about. But if you must ...

One way to do this is to use the EAV data model[1]. This is because at 1000 
columns = 1000 
fields, you will most certainly hit MySQL's maximum row size[2].

-- 
Melvyn Sopacua


[1] https://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model
[2] https://dev.mysql.com/doc/refman/5.7/en/column-count-limit.html

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1682319.7IaycB50Qv%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Dynamic model fields using mysql?

2018-07-02 Thread hardik dadhich
Hello,
Can anyone tell me how can I make dynamic Django model fields? I mean to 
say that I want to save excel file data in Django model using MySQL. and 
excel column can vary. The user can upload 100 column table or he can be 
upload 1000 column table in the database. so it is possible to add 
dynamically in db. 

Any help would be appreciated.
Thanks in advance!



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1ad8aa1c-c672-42e1-868a-69c8b96f43e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Invalid HTTP_HOST header when website being accessed by public IP

2018-07-02 Thread Kasper Laudrup

Hi Melvyn,

On 2018-07-02 11:32, Melvyn Sopacua wrote:

On zondag 1 juli 2018 19:10:15 CEST Tomasz Knapik wrote:

 > Maybe you could restrict host headers at the nginx layer, but I don't

 > think it's worth your effort...

If you think of it like that it seems like a lot of work. But if you 
simply setup a default server that redirects to the actual Django server 
with correct hostname, then all you need is 2 server blocks: 1 default, 
1 with correct `server_name`.




You are correct. That was actually fairly easy to fix by changing the 
nginx configuration.


I didn't do exactly as you mentioned since I use HTTPS (with a redirect 
for HTTP) managed by letsencrypt.


Instead I added the following to my HTTPS server section:

if ($host != my-website.org {
   return 404;
}

Seems to solve my problem just fine. Letsencrypts certbot had already 
done something similar for the HTTP section redirect.


Thanks a lot for the input.

Kind regards,

Kasper Laudrup

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eba5f004-7fde-b9d7-232d-67b4162623b1%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: A few doubts with an implementation.

2018-07-02 Thread Vineeth Sagar
Mikhailo Keda wrote:
>
> to fetch emails every N minutes or hours  - 
> http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
> I want the user to know that the mails are being retrieved - 
> https://channels.readthedocs.io/en/latest/
>

Thanks Mikhailo for the prompt reply, I'll spend a few days reading the 
documentation of the libraries you have pointed me to. Are web sockets 
supported in IE, iirc I don't think they do. Half of our clients Will use 
IE, not edge, good old fucked up IE. Also I was expecting a critique on my 
ideas. I want to weigh the pro's and con's of my approach vs clerey's(It 
might be clear once I read the docs.)

again thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/10ea3eba-a72f-4d33-8504-4658c0b810ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A few doubts with an implementation.

2018-07-02 Thread Mikhailo Keda
to fetch emails every N minutes or hours  -
http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
I want the user to know that the mails are being retrieved -
https://channels.readthedocs.io/en/latest/

On Mon, Jul 2, 2018 at 3:53 PM, Vineeth Sagar  wrote:

> Problem:
> We are developing a email-CRM. The task at hand is to fetch emails every N
> minutes or hours. I have received a codebase written by another guy who
> left the company,my job is to re-write/re-factor. The guy who previously
> wrote the code started a thread whenever a user logged and he put a
> time.sleep() inside it, There's no limit on number of threads that can be
> initialized, if 100 users log in, we will have 100 active threads, he used
> locks so that at any given time only one thread can be executed.
>
> Solution:
> It's messy in so many ways(mentioned above) and I think writing django
> middleware would be appropriate for this task. So here's what I plan to do,
> using a Django cache I store a Python datetime object and a flag to see if
> there is any other request that's already retrieving the mails, I don't
> want multiple requests to retrieving mails at once. Is this a better idea?
> Are there any other ways to do this particular task?
>
> One more doubt I have is I want the user to know that the mails are being
> retrieved so he doesn't refresh the page passive-aggressively. How can I do
> this? I want the user to know it's happening and in the background
> middleware should be executed, I have to keep retrieving mails and once
> it's completed I'll execute the view_func parameter received via the
> process_request hook.
>
> I am a junior at the company(Start up),I am fairly new to django, I keep
> reading the documentation and find new things daily,after picking my mind
> for a day this to me seems best, but please if you have any suggestion let
> me know. Please help me out. Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/c563187e-a3ee-49c0-8c56-cb924a128891%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOM-Qa1tkqF-SF6P-ThS4g3yLJJ79VrsbHJdpv6vKxDTo%2BWtUw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


A few doubts with an implementation.

2018-07-02 Thread Vineeth Sagar
Problem:
We are developing a email-CRM. The task at hand is to fetch emails every N 
minutes or hours. I have received a codebase written by another guy who 
left the company,my job is to re-write/re-factor. The guy who previously 
wrote the code started a thread whenever a user logged and he put a 
time.sleep() inside it, There's no limit on number of threads that can be 
initialized, if 100 users log in, we will have 100 active threads, he used 
locks so that at any given time only one thread can be executed. 

Solution:
It's messy in so many ways(mentioned above) and I think writing django 
middleware would be appropriate for this task. So here's what I plan to do, 
using a Django cache I store a Python datetime object and a flag to see if 
there is any other request that's already retrieving the mails, I don't 
want multiple requests to retrieving mails at once. Is this a better idea? 
Are there any other ways to do this particular task?

One more doubt I have is I want the user to know that the mails are being 
retrieved so he doesn't refresh the page passive-aggressively. How can I do 
this? I want the user to know it's happening and in the background 
middleware should be executed, I have to keep retrieving mails and once 
it's completed I'll execute the view_func parameter received via the 
process_request hook. 

I am a junior at the company(Start up),I am fairly new to django, I keep 
reading the documentation and find new things daily,after picking my mind 
for a day this to me seems best, but please if you have any suggestion let 
me know. Please help me out. Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c563187e-a3ee-49c0-8c56-cb924a128891%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Isolated virtualenv and mod_wsgi - how do I do this on Apache

2018-07-02 Thread Vinicius Assef
Maybe this other article helps you understand the essence of a
virtualenv: 
http://blog.aprendapython.com.br/articles/entendendo-virtualenv-1fr69/

Again, Google Translator is your friend.



On 2 July 2018 at 09:28, Vinicius Assef  wrote:
> I second Melvyn.
>
> On top of what he wrote, Bruce, I work in an environment with exactly
> this limitation: a shared hosting running Apache where I don't have
> access
>  to ssh.
>
> I build my environment (install libs, for that matter) locally and
> transfer all my pack through ftp in one shot.
>
> As Melvyn told us, "activate" a virtualenv means "put the path to your
> libs first, in the PATH variable". But it can also be done inside a
> Python program, too, manipulating `sys.path`.
>
> You can see an example here:
> http://blog.aprendapython.com.br/articles/setup-de-python-django-pyramid-dreamhost-1fr70/
>
> In spite the blog post is in Brazilian Portuguese, Google Translator
> is your friend and examples are in Python, afterall. ;-)
>
> Cheers.
>
>
>
> On 1 July 2018 at 09:38, Melvyn Sopacua  wrote:
>> On donderdag 28 juni 2018 17:46:42 CEST Bruce Whealton wrote:
>>
>>> In all cases, a virtualenv is recommended for any Python
>>> deployment.  In both cases, I have Apache as the web server with mod_wsgi.
>>> Obviously, I need the server, Apache, to activate the
>>> Django environment.  I can ssh to my VPS but what good is that.  I don't
>>> need my username to be activating the Python isolated environment.  As soon
>>> as I close the ssh session the activated environment
>>> is no longer activated.  My best guess is that the Apache user must
>>> activate the virtual environment and keep it activated as an isolated
>>> virtual environment.
>>
>> Virtualenv "activation" is not magic. It simply adjusts PATH so that the
>> virtualenv's bin directory is first. This means that whenever "python" or 
>> "pip"
>> is typed into the shell it will not execute `/usr/bin/python` but
>> `your-virtualenv/bin/python`. Handing apache a sanitized PATH with the
>> virtualenv bin dir as first directory, will effectively do the same as
>> "activation".
>>
>> (To be complete: activate also alters your shell prompt, this has no effect 
>> in
>> one-off application launches).
>>
>> --
>> Melvyn Sopacua
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/2410185.edddNGrWiM%40fritzbook.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFmXjSApkLBW4Mb090Mq-40N7R00YeDmeOd34439UDptaV9pYA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Isolated virtualenv and mod_wsgi - how do I do this on Apache

2018-07-02 Thread Vinicius Assef
I second Melvyn.

On top of what he wrote, Bruce, I work in an environment with exactly
this limitation: a shared hosting running Apache where I don't have
access
 to ssh.

I build my environment (install libs, for that matter) locally and
transfer all my pack through ftp in one shot.

As Melvyn told us, "activate" a virtualenv means "put the path to your
libs first, in the PATH variable". But it can also be done inside a
Python program, too, manipulating `sys.path`.

You can see an example here:
http://blog.aprendapython.com.br/articles/setup-de-python-django-pyramid-dreamhost-1fr70/

In spite the blog post is in Brazilian Portuguese, Google Translator
is your friend and examples are in Python, afterall. ;-)

Cheers.



On 1 July 2018 at 09:38, Melvyn Sopacua  wrote:
> On donderdag 28 juni 2018 17:46:42 CEST Bruce Whealton wrote:
>
>> In all cases, a virtualenv is recommended for any Python
>> deployment.  In both cases, I have Apache as the web server with mod_wsgi.
>> Obviously, I need the server, Apache, to activate the
>> Django environment.  I can ssh to my VPS but what good is that.  I don't
>> need my username to be activating the Python isolated environment.  As soon
>> as I close the ssh session the activated environment
>> is no longer activated.  My best guess is that the Apache user must
>> activate the virtual environment and keep it activated as an isolated
>> virtual environment.
>
> Virtualenv "activation" is not magic. It simply adjusts PATH so that the
> virtualenv's bin directory is first. This means that whenever "python" or 
> "pip"
> is typed into the shell it will not execute `/usr/bin/python` but
> `your-virtualenv/bin/python`. Handing apache a sanitized PATH with the
> virtualenv bin dir as first directory, will effectively do the same as
> "activation".
>
> (To be complete: activate also alters your shell prompt, this has no effect in
> one-off application launches).
>
> --
> Melvyn Sopacua
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/2410185.edddNGrWiM%40fritzbook.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFmXjSAFWT2g8zmh2moxbnDog%2BjYf2gzsCXBd%3D7MCGbZ1S7JJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to Save form to mysql - How to save form field values to mysql database and get the value from database

2018-07-02 Thread Andréas Kühne
In your views file, you don't have any index method - that's what the error
is saying. So you need to solve the url mapping for your index method.

Regards,

Andréas

2018-07-02 5:55 GMT+02:00 Tamilvanan Anbalagan :

> Hi Team,
>
> I am very new to django framework, iI am trying to using simple forms to
> save into mysql database. also any samples pls send it to me, which will
> help to understand the connectivity.
>
> *see my sample code:*
>
>
> *views.py*
>
> from django.http import HttpResponseRedirect
> from django.views import View
> from django.shortcuts import render
>
> from .forms import NameForm
>
> def get_name(request):
> # if this is a POST request we need to process the form data
> if request.method == 'POST':
> # create a form instance and populate it with data from the request:
> form = NameForm(request.POST)
> # check whether it's valid:
> if form.is_valid():
> # process the data in form.cleaned_data as required
> # ...
> # redirect to a new URL:
> return HttpResponseRedirect('/thanks/')
>
> # if a GET (or any other method) we'll create a blank form
> else:
> form = NameForm()
>
> return render(request, 'portal/index.html', {'form': form})
>
>
> djangoproject/urls.py
>
> from django.contrib import admin
> from django.urls import path, include
> #from django.conf.urls import url, include
>
> urlpatterns = [
> path('admin/', admin.site.urls),
> path('portal/', include('portal.urls')),
> #url(r'^portal/', include('portal.urls'))
> ]
>
>
> *forms.py*
>
> from django import forms
>
> # class NameForm(forms.Form):
> # your_name = forms.CharField(label='Your name', max_length=100)
>
>
> *urls.py*
>
> from django.conf.urls import url
> from . import views
>
> urlpatterns = [
> url(r'^$', views.index, name='index')
> ]
>
> *Error message:*
>
>
>
> (py1) c:\TransportPortal\djangoproject>python manage.py runserver
> Performing system checks...
>
> Unhandled exception in thread started by  check_errors..wrappe
>  at 0x0355E4F8>
> Traceback (most recent call last):
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\
> utils\autoreload.py"
>  line 225, in wrapper
> fn(*args, **kwargs)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> management\comm
> nds\runserver.py", line 120, in inner_run
> self.check(display_num_errors=True)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> management\base
> py", line 364, in check
> include_deployment_checks=include_deployment_checks,
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> management\base
> py", line 351, in _run_checks
> return checks.run_checks(**kwargs)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> checks\registry
> py", line 73, in run_checks
> new_errors = check(app_configs=app_configs)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> checks\urls.py"
>  line 13, in check_url_config
> return check_resolver(resolver)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> checks\urls.py"
>  line 23, in check_resolver
> return check_method()
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\
> resolvers.py",
> ine 399, in check
> for pattern in self.url_patterns:
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\
> utils\functional.py"
>  line 36, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\
> resolvers.py",
> ine 540, in url_patterns
> patterns = getattr(self.urlconf_module, "urlpatterns",
> self.urlconf_module)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\
> utils\functional.py"
>  line 36, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\
> resolvers.py",
> ine 533, in urlconf_module
> return import_module(self.urlconf_name)
>   File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126,
> in impo
> t_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 "c:\TransportPortal\djangoproject\djangoproject\urls.py", line 22,
> in  dule>
> path('portal/', include('portal.urls')),
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\conf.py",
> line
> 4, in include
> urlconf_module = import_module(urlconf_module)
>   File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126,
> in impo
> t_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 "", 

Unable to Save form to mysql - How to save form field values to mysql database and get the value from database

2018-07-02 Thread Tamilvanan Anbalagan
Hi Team,

I am very new to django framework, iI am trying to using simple forms to 
save into mysql database. also any samples pls send it to me, which will 
help to understand the connectivity.

*see my sample code:*


*views.py*

from django.http import HttpResponseRedirect
from django.views import View
from django.shortcuts import render

from .forms import NameForm

def get_name(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = NameForm(request.POST)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
return HttpResponseRedirect('/thanks/')

# if a GET (or any other method) we'll create a blank form
else:
form = NameForm()

return render(request, 'portal/index.html', {'form': form})


djangoproject/urls.py

from django.contrib import admin
from django.urls import path, include
#from django.conf.urls import url, include

urlpatterns = [
path('admin/', admin.site.urls),
path('portal/', include('portal.urls')),
#url(r'^portal/', include('portal.urls'))
]


*forms.py*

from django import forms

# class NameForm(forms.Form):
# your_name = forms.CharField(label='Your name', max_length=100)


*urls.py*

from django.conf.urls import url
from . import views

urlpatterns = [
url(r'^$', views.index, name='index')
]

*Error message:*



(py1) c:\TransportPortal\djangoproject>python manage.py runserver
Performing system checks...

Unhandled exception in thread started by .wrappe
 at 0x0355E4F8>
Traceback (most recent call last):
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\utils\autoreload.py"
 line 225, in wrapper
fn(*args, **kwargs)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\management\comm
nds\runserver.py", line 120, in inner_run
self.check(display_num_errors=True)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\management\base
py", line 364, in check
include_deployment_checks=include_deployment_checks,
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\management\base
py", line 351, in _run_checks
return checks.run_checks(**kwargs)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\checks\registry
py", line 73, in run_checks
new_errors = check(app_configs=app_configs)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\checks\urls.py"
 line 13, in check_url_config
return check_resolver(resolver)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\checks\urls.py"
 line 23, in check_resolver
return check_method()
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\resolvers.py",
ine 399, in check
for pattern in self.url_patterns:
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\utils\functional.py"
 line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\resolvers.py",
ine 540, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", 
self.urlconf_module)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\utils\functional.py"
 line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\resolvers.py",
ine 533, in urlconf_module
return import_module(self.urlconf_name)
  File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126, in 
impo
t_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 "c:\TransportPortal\djangoproject\djangoproject\urls.py", line 22, 
in 
path('portal/', include('portal.urls')),
  File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\conf.py", 
line
4, in include
urlconf_module = import_module(urlconf_module)
  File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126, in 
impo
t_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 "c:\TransportPortal\djangoproject\portal\urls.py", line 6, in 

url(r'^$', views.index, name='index')
AttributeError: module 'portal.views' has no attribute 'index'

(py1) c:\TransportPortal\djangoproject>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 

Re: how to programmatically get the index name of a model field on a migration of django 1.8

2018-07-02 Thread Michal Petrucha
On Fri, Jun 29, 2018 at 11:25:16AM -0300, Fabio C. Barrionuevo da Luz wrote:
> Hello, I need to delete an index created automatically by Django, from a
> third-party application and my own django apps, for later I recreate the
> index optimized way.
> 
> this django application is used in several companies.
> so I need to distribute these improvements via django migration.
> 
> 
> I'm using raw sql in a RunPython migration, to delete and create the
> optimized index.
> 
> in django 1.8, there is a deterministic way to I previously know what the
> index name is generated for a given model field or django has a python
> function/method to get this information?

I'm not sure if the names are generated in a predictable way, but my
gut says they probably aren't – at least not in general, maybe for
certain specific DB backends, they will be. (As far as I can see, in
the base backend implementation, Django introspects existing indices
in the database, and finds the name that way.)

If the index is created with db_index=True, unique=true,
index_together, or unique_together, you might be able to get away with
a migration with two operations:
1. delete the index with an AlterField, AlterUniqueTogether, or
   AlterIndexTogether operation, and then
2. use SeparateDatabaseAndState, and in `state_operations`, you undo
   the effect of the previous operation, while in
   `database_operations`, you'd execute your custom SQL to create the
   optimized index.

Another option might be to use a RunPython operation, in which you use
the schema_editor passed in to drop the index with its alter_field,
alter_unique_together, or alter_index_together methods, and then run
your custom SQL. If changing the options of models or fields is not
enough, then you might have to get your hands dirty, and figure out
the name of the index with editor._constraint_names, but then you are
entering private API territory, and things might break on you after
upgrading Django.

Yet another alternative might be to upgrade to a version of Django
that's not past EOL, and use the more explicit support for indices
introduced in 1.11, but I have no idea how much easier it would make
to solve your problem. (You should consider upgrading regardless,
though.)

Good luck,

Michal

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20180702110845.GC1181%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Need your help to fix IntegrityError in my Django code.

2018-07-02 Thread prateek gupta
Hi All,

I have created a simple database admin panel 
(Django2..6+Python3.6+Mysql5.7) where admin can operate create/edit/delete 
operations of database.
I am facing following IntegrityError  error when I try to Merge two 
products and click on Preview from my Django admin panel-
2018-07-02 16:17:56,428 [ERROR] exception.py:118 
handle_uncaught_exception() : Internal Server Error: 
/where2buy/merchantproduct/
Traceback (most recent call last):
  File 
"C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\backends\utils.py",
 
line 85, in _execute
return self.cursor.execute(sql, params)
  File 
"C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\django\db\backends\mysql\base.py",
 
line 71, in execute
return self.cursor.execute(query, args)
  File 
"C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\MySQLdb\cursors.py",
 
line 250, in execute
self.errorhandler(self, exc, value)
  File 
"C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\MySQLdb\connections.py",
 
line 50, in defaulterrorhandler
raise errorvalue
  File 
"C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\MySQLdb\cursors.py",
 
line 247, in execute
res = self._query(query)
  File 
"C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\MySQLdb\cursors.py",
 
line 411, in _query
rowcount = self._do_query(q)
  File 
"C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\MySQLdb\cursors.py",
 
line 374, in _do_query
db.query(q)
  File 
"C:\Users\prateek1.gupta\AppData\Local\Continuum\anaconda3\lib\site-packages\MySQLdb\connections.py",
 
line 277, in query
_mysql.connection.query(self, query)
_mysql_exceptions.IntegrityError: (1451, 'Cannot delete or update a parent 
row: a foreign key constraint fails (`productsearchv2`.`feed`, CONSTRAINT 
`feed_mproduct_id_fk` FOREIGN KEY (`merchant_id`, `merchant_product_id`) 
REFERENCES `merchant_product` (`merchant_id`, `merchant_product_id`) ON 
DELETE NO )')

I think issue is may be wrong relationship settings in my model file but 
couldn't able to find exact issue.
Can anyone please help me to find the issue? My code is as below-

class MerchantProduct(models.Model):
merchant = models.ForeignKey(Merchant, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.SET_NULL, blank=True, 
null=True)
merchant_product_id = models.CharField(max_length=100)
gtin = models.CharField(max_length=15, blank=True, null=True)
merchant_group_id = models.CharField(max_length=100, blank=True, null=True)
name = models.CharField(max_length=300)
description = models.TextField(blank=True, null=True)
image_urls = models.TextField(blank=True, null=True)
image_phashes = models.TextField(blank=True, null=True)
web_url = models.URLField(blank=True, null=True)
brand = models.CharField(max_length=100, blank=True, null=True)
category = models.CharField(max_length=150, blank=True, null=True)
color = models.CharField(max_length=100, blank=True, null=True)
size = models.CharField(max_length=100, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True)

class Meta:
unique_together = (('merchant', 'merchant_product_id'),)
managed = False
db_table = 'merchant_product'

def __str__(self):
return self.name

class Product(models.Model):
merchants = models.ManyToManyField(Merchant, through='MerchantProduct')
brand = models.ForeignKey(Brand, related_name='brand', 
on_delete=models.SET_NULL, blank=True, null=True)
category = models.ForeignKey(Category, related_name='category', 
on_delete=models.SET_NULL, blank=True, null=True)
group = models.ForeignKey('self', related_name='ID', 
on_delete=models.SET_NULL, blank=True, null=True)
gtin = models.CharField(max_length=15, blank=True, null=True)
name = models.CharField(max_length=300)
description = models.TextField()
image_urls = models.TextField()
image_phashes = models.CharField(max_length=200, blank=True, null=True)
color = models.CharField(max_length=100, blank=True, null=True)
size = models.CharField(max_length=100, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True)

class Meta:
managed = False
db_table = 'product'

def __str__(self):
return self.name


class Merchant(models.Model):
DATA_QUALITY_CHOICES = (
('approx', 'Approximate'),
('exact', 'Exact'),
)
name = models.CharField(unique=True, max_length=45)
display_name = models.CharField(unique=True, max_length=255)
url_name = models.CharField(unique=True, max_length=255)
data_quality = models.CharField(default='approx', 

Re: Invalid HTTP_HOST header when website being accessed by public IP

2018-07-02 Thread Melvyn Sopacua
On zondag 1 juli 2018 19:10:15 CEST Tomasz Knapik wrote:

> Maybe you could restrict host headers at the nginx layer, but I don't
> think it's worth your effort... 

If you think of it like that it seems like a lot of work. But if you simply 
setup a default 
server that redirects to the actual Django server with correct hostname, then 
all you 
need is 2 server blocks: 1 default, 1 with correct `server_name`.

See Request Processing[1] for more background information and tricks.
-- 
Melvyn Sopacua


[1] http://nginx.org/en/docs/http/request_processing.html

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1649516.A6oeUnqeAf%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Django bugfix releases: 2.0.7 and 1.11.14

2018-07-02 Thread Carlton Gibson
Details are available on the Django project weblog:

https://www.djangoproject.com/weblog/2018/jul/02/bugfix-releases/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/BE021AC2-3BA7-4A58-9B00-076AF2828E0C%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Message signed with OpenPGP