Re: Django app and a submodule name conflict

2014-06-04 Thread Vahe Evoyan
It currently works as you describe: "from .B.models import BModel", but I 
need it to work like "from ...B.models import BModel" to import 
apps/B/models.py module. The problem with "..." is that apps directory is 
not a module (i.e. there is no __init__.py file). The app directory is the 
first one in the sys.path list, so the simple "from B.models import BModel" 
should look in apps/B/models.py file, but it looks into current directory 
earlier than app directory.

This structure perfectly works with a simple python scripts (without Django 
included), that's why I suspect that Django hooks something in the import 
procedure.

On Wednesday, June 4, 2014 11:19:50 PM UTC+4, Joseph Catrambone wrote:
>
> It may be worth trying a relative import, depending on which version of 
> Python you're using.  I believe you can do "from .B.models import BModel". 
>  Note the '.' full-stop/period before the module.  I can't promise that 
> will fix your problem, as the layout isn't entirely clear to me, but it 
> might get you on the right track.
>
> On Wednesday, June 4, 2014 3:51:28 AM UTC-4, Vahe Evoyan wrote:
>>
>> I have modules in the project with the same names, all placed in 
>> different applications.
>>
>> Particularly there are two apps that conflict and result an ImportError. 
>> The project structure approximately is as follows.
>>
>> project
>>  |_ project   
>>|_ settings.py
>>|_ ...
>>  |_ apps
>>|_ A
>>  |_ handlers
>>|_ B.py
>>|_ C.py
>>|_ B
>>  |_ models.py
>>
>> The settings file adds apps directory to the system path.
>>
>> BASE_DIR = os.path.dirname(os.path.dirname(__file__))
>> sys.path.insert(0, os.path.join(BASE_DIR, "apps"))
>>
>> This configuration assumes that when I import the B.models it will use 
>> apps/B/models.py. Although the following line in the C.py file raise an 
>> import error as it imports the A/handlers/B.pywhich does not have models
>>  module.
>>
>> A/handlers/C.py:
>> from B.models import BModel
>>
>> The sys.path variable has a correct items, i.e. the first one in the 
>> list is /path/to/project/appsand sys.modules['B.models'] is referenced 
>> to the correct file.
>>
>> BTW, when I use Django's import_by_path function, everything works fine.
>>
>> Any ideas how I can solve the problem without renaming the modules?
>>
>> Posted sample sources 
>>  on GitHub.
>>
>> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/192777eb-9476-4db4-9973-f7587eb003ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django app and a submodule name conflict

2014-06-04 Thread Joseph Catrambone
It may be worth trying a relative import, depending on which version of 
Python you're using.  I believe you can do "from .B.models import BModel". 
 Note the '.' full-stop/period before the module.  I can't promise that 
will fix your problem, as the layout isn't entirely clear to me, but it 
might get you on the right track.

On Wednesday, June 4, 2014 3:51:28 AM UTC-4, Vahe Evoyan wrote:
>
> I have modules in the project with the same names, all placed in different 
> applications.
>
> Particularly there are two apps that conflict and result an ImportError. 
> The project structure approximately is as follows.
>
> project
>  |_ project   
>|_ settings.py
>|_ ...
>  |_ apps
>|_ A
>  |_ handlers
>|_ B.py
>|_ C.py
>|_ B
>  |_ models.py
>
> The settings file adds apps directory to the system path.
>
> BASE_DIR = os.path.dirname(os.path.dirname(__file__))
> sys.path.insert(0, os.path.join(BASE_DIR, "apps"))
>
> This configuration assumes that when I import the B.models it will use 
> apps/B/models.py. Although the following line in the C.py file raise an 
> import error as it imports the A/handlers/B.pywhich does not have models
>  module.
>
> A/handlers/C.py:
> from B.models import BModel
>
> The sys.path variable has a correct items, i.e. the first one in the list 
> is /path/to/project/appsand sys.modules['B.models'] is referenced to the 
> correct file.
>
> BTW, when I use Django's import_by_path function, everything works fine.
>
> Any ideas how I can solve the problem without renaming the modules?
>
> Posted sample sources 
>  on GitHub.
>
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0e09ff68-d4a7-4353-afd3-0932205a7823%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Foreign key field with limit_choices_to

2014-06-04 Thread dmbarbour87


class ProductGroup(models.Model):
group_sku = models.CharField(unique=True, max_length=255)
brand = models.CharField(max_length=255)
...

class Product(models.Model):
product_sku = models.CharField(unique=True, max_length=255)
color = models.CharField(max_length=255)
size = models.CharField(max_length=255)
product = models.ForeignKey(Product, 
limit_choices_to=Q(group_sku__in=product_sku))
...

I'm importing my data to Django from an XML file via a python script.

group_sku comes in the format "GROUP123"

product_sku comes in the format "GROUP123-BLUE-M" (or similar) and there 
are multiple products in each group

How do I define the foreign key relationship so that each Product is linked 
to its respective ProductGroup? Or feel free to tell me if I'm going about 
this the complete wrong way.

Using Django 1.6.5, Python 2.7, and MySQL

-- 
You received this message because you are subscribed to the Google Groups 
"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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7b972d02-f9cf-4bd2-a453-43474bf920ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: How to install psycopg2 using Pip?

2014-06-04 Thread Ilya Kazakevich
Hello,

To be installed, psycopg2 needs to know where PostgreSQL headers (.h files)
and libraries (.a files) are situated. Header files are required by compiler
while libraries are required by linker.

PostgreSQL provides special tool named "pg_config" that tells everyone where
PostgreSQL is installed and where one should look for that files.
This tool is part of postgres installation.

Check you can run this program from your terminal. If you can't -- you need
to find it and add it's folder to your PATH variable.

"pip install psycopg2" runs "pg_config" to find your postgres installation.

Ilya Kazakevich,
JetBrains PyCharm (Best Python/Django IDE)
http://www.jetbrains.com/pycharm/
"Develop with pleasure!"


>-Original Message-
>From: django-users@googlegroups.com
>[mailto:django-users@googlegroups.com] On Behalf Of Dow Street
>Sent: Wednesday, June 04, 2014 6:52 PM
>To: django-users@googlegroups.com
>Subject: Re: How to install psycopg2 using Pip?
>
>My understanding is that psycopg2 looks for some postgres files during the
install.
>If you have postgres already installed on the same box, you should be able
to
>resolve this problem by adding the postgres folder to your PATH environment
>variable before running 'pip install psycopg2'.  The syntax for modifying
the
>PATH might differ a little based on the operating system, but it would
normally be
>something like this:
>
>PATH=$PATH:/Library/PostgreSQL/9.1/bin
>
>Here postgres is installed at /Library/PostgreSQL/9.1/bin, but it might be
in a
>different location on your machine.  As Fabio mentioned, if you do not have
>postgres installed on the same machine you may be able to add the
development
>libraries for your OS and get it to work.
>
>One note about modifying the PATH - due to the way virtualenv can adjust
PATH
>contents you may need to add the postgres folder to the PATH after the
>virtualenv is activated.  (not sure about this ...)
>
>Hope that helps!
>
>
>
>On Jun 4, 2014, at 6:33 AM, Fabio Caritas Barrionuevo da Luz
> wrote:
>
>>
>> If Ubuntu 12.04 or higher
>>
>> do:
>>
>> sudo apt-get install libpq-dev
>>
>>
>>
>>
>> Em quinta-feira, 24 de março de 2011 12h01min43s UTC-3, Andre Lopes
>escreveu:
>> Hi,
>> This question is not directly related with Django, but with Python.
>>
>> I have installed "virtualenv" to have a virtual environment. Now I
>> need to instal "psycopg2" in my virtual environment, but I have not
>> successfully installed.
>>
>> My steps:
>>
>> [quote]
>> pip install
>> http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz#
>> md5=24f4368e2cfdc1a2b03282ddda814160
>> [/quote]
>>
>> And I got this message with an error:
>>
>> [quote]
>> Downloading/unpacking
>> http://pypi.python.org/packages/source/p/psycopg2/psycopg2
>> -2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
>>   Downloading psycopg2-2.4.tar.gz (607Kb): 607Kb downloaded
>>   Running setup.py egg_info for package from
>> http://pypi.python.org/packages/sou
>>
>rce/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda81416
>0
>> Error: pg_config executable not found.
>>
>> Please add the directory containing pg_config to the PATH
>> or specify the full executable path with the option:
>>
>> python setup.py build_ext --pg-config
>/path/to/pg_config build ...
>>
>> or with the pg_config option in 'setup.cfg'.
>> Complete output from command python setup.py
>egg_info:
>> running egg_info
>>
>> creating pip-egg-info\psycopg2.egg-info
>>
>> writing pip-egg-info\psycopg2.egg-info\PKG-INFO
>>
>> writing top-level names to
>> pip-egg-info\psycopg2.egg-info\top_level.txt
>>
>> writing dependency_links to
>> pip-egg-info\psycopg2.egg-info\dependency_links.txt
>>
>> writing manifest file
'pip-egg-info\psycopg2.egg-info\SOURCES.txt'
>>
>> warning: manifest_maker: standard file '-c' not found
>>
>> Error: pg_config executable not found.
>>
>>
>> Please add the directory containing pg_config to the PATH
>>
>> or specify the full executable path with the option:
>>
>>
>> python setup.py build_ext --pg-config /path/to/pg_config
>build ...
>>
>>
>> or with the pg_config option in 'setup.cfg'.
>>
>> 
>> Command python setup.py egg_info failed with error code 1
>> Storing complete log in C:\Documents and
>> Settings\anlopes\Application Data\pip\p
>> ip.log
>> [/quote]
>>
>> My question:
>>
>> How can I tell to "pip" where is my pg_config?
>>
>> Best Regards,
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>"Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

Re: URLs: mymodel_id vs object_id vs pk ....

2014-06-04 Thread Sergiy Khohlov
Jnt of the best way is a slug.
 I nether do use id or object_id by security reason (hacker can try to
access another object or  count on objects in your application, such as
administrator usually  has id as 0 or small number. It is good target for
attack). Keep in mind that id is mutable after moving to the new database
(ex: you can not use direct link to the product in your webshop).

Many thanks,

Serge


+380 636150445
skype: skhohlov


On Wed, Jun 4, 2014 at 4:49 PM, monoBOT  wrote:

> Thats a matter of taste ... i use model_id
>
>
> 2014-06-04 14:07 GMT+01:00 Thomas Güttler :
>
> What is the best practice for named URL parameter which refer to a primary
>> key of a model?
>>
>> I have seen many ways:
>>
>>  - object_id
>>  - mymodel_id
>>  - pk
>>  - id
>>  - .
>>
>> example:
>>
>> urlpatterns = [
>> url(r'^article/(?P\d+)/$', 'article.view'),
>> ...
>> ]
>>
>> Up to now we used "mymodel_id" but it gets boring to type in "mymodel".
>>
>> This is a question about best practice:
>>
>> Which do you use (and why)?
>>
>>
>> Related: https://docs.djangoproject.com/en/dev/topics/http/urls/#
>> named-groups
>>
>>   Thomas
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/538F19FF.1090209%40tbz-pariv.de.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *monoBOT*
> Visite mi sitio(Visit my site): monobotblog.alvarezalonso.es
>
> --
> You received this message because you are subscribed to the Google Groups
> "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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BxOsGD3ePtXWNd-D9AmZ_4mr_%3D3cS_uTi61i5Aou6n7SmZ9QA%40mail.gmail.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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADTRxJM00kN%3D9sDez34shxpBbweC8CSofbryy%2Bc_cCtQAS8KLg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems connecting to an oracle legacy db

2014-06-04 Thread Ian
On Wednesday, June 4, 2014 2:38:34 AM UTC-6, Vittorio wrote:
>
> #models.py 
> ... 
> class magazzino_vista_lista(models.Model): 
> id_ordine = models.IntegerField(null=False, blank=False, 
> db_column='ID_ORDINE') 
> cod_magazzino_galileo = models.CharField(max_length=48, 
> db_column='COD_MAGAZZINO_GALILEO') 
> cod_magazzino_ext = models.CharField(max_length=48, 
> db_column='COD_MAGAZZINO_EXT') 
> qta = models.IntegerField(null=False, blank=False, db_column='QTA') 
> class Meta: 
> managed = False 
> db_table = u'noema.magazzino_vista_lista' 
> verbose_name_plural = "CC specifica ordini vista" 
>
> * See the real oracle table is named 'noema.magazzino_vista_lista' as 
> in the sql I called before under python * 
>
>
Django currently doesn't understand schemas, and it quotes and treats the 
"noema." as being part of the table name rather than a schema. There's a 
hacky way (which basically amounts to SQL injection by the developer) to 
make it quote the schema and table separately, but I recommend creating 
synonyms to your tables in the schema that Django actually connects to.

-- 
You received this message because you are subscribed to the Google Groups 
"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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e8e7b975-60a9-4e7b-84ce-5f78412fd08b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


postgres json or hstore

2014-06-04 Thread Eddilbert Macharia
Hi All, 

Using postgres json and hstore fields to store alot of data. 

How would i go about create a C.R.U.D using this field types, 
java,c/c++,php or python would make it easier for me understand. 

Regards 

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


Re: How to install psycopg2 using Pip?

2014-06-04 Thread Dow Street
My understanding is that psycopg2 looks for some postgres files during the 
install.  If you have postgres already installed on the same box, you should be 
able to resolve this problem by adding the postgres folder to your PATH 
environment variable before running 'pip install psycopg2'.  The syntax for 
modifying the PATH might differ a little based on the operating system, but it 
would normally be something like this:

PATH=$PATH:/Library/PostgreSQL/9.1/bin

Here postgres is installed at /Library/PostgreSQL/9.1/bin, but it might be in a 
different location on your machine.  As Fabio mentioned, if you do not have 
postgres installed on the same machine you may be able to add the development 
libraries for your OS and get it to work.

One note about modifying the PATH - due to the way virtualenv can adjust PATH 
contents you may need to add the postgres folder to the PATH after the 
virtualenv is activated.  (not sure about this ...)

Hope that helps!



On Jun 4, 2014, at 6:33 AM, Fabio Caritas Barrionuevo da Luz  
wrote:

> 
> If Ubuntu 12.04 or higher
> 
> do:
> 
> sudo apt-get install libpq-dev
> 
> 
> 
> 
> Em quinta-feira, 24 de março de 2011 12h01min43s UTC-3, Andre Lopes escreveu:
> Hi,
> This question is not directly related with Django, but with Python.
> 
> I have installed "virtualenv" to have a virtual environment. Now I
> need to instal "psycopg2" in my virtual environment, but I have not
> successfully installed.
> 
> My steps:
> 
> [quote]
> pip install
> http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
> [/quote]
> 
> And I got this message with an error:
> 
> [quote]
> Downloading/unpacking
> http://pypi.python.org/packages/source/p/psycopg2/psycopg2
> -2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
>   Downloading psycopg2-2.4.tar.gz (607Kb): 607Kb downloaded
>   Running setup.py egg_info for package from
> http://pypi.python.org/packages/sou
> 
> rce/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
> Error: pg_config executable not found.
> 
> Please add the directory containing pg_config to the PATH
> or specify the full executable path with the option:
> 
> python setup.py build_ext --pg-config 
> /path/to/pg_config build ...
> 
> or with the pg_config option in 'setup.cfg'.
> Complete output from command python setup.py egg_info:
> running egg_info
> 
> creating pip-egg-info\psycopg2.egg-info
> 
> writing pip-egg-info\psycopg2.egg-info\PKG-INFO
> 
> writing top-level names to 
> pip-egg-info\psycopg2.egg-info\top_level.txt
> 
> writing dependency_links to 
> pip-egg-info\psycopg2.egg-info\dependency_links.txt
> 
> writing manifest file 'pip-egg-info\psycopg2.egg-info\SOURCES.txt'
> 
> warning: manifest_maker: standard file '-c' not found
> 
> Error: pg_config executable not found.
> 
> 
> Please add the directory containing pg_config to the PATH
> 
> or specify the full executable path with the option:
> 
> 
> python setup.py build_ext --pg-config /path/to/pg_config 
> build ...
> 
> 
> or with the pg_config option in 'setup.cfg'.
> 
> 
> Command python setup.py egg_info failed with error code 1
> Storing complete log in C:\Documents and Settings\anlopes\Application
> Data\pip\p
> ip.log
> [/quote]
> 
> My question:
> 
> How can I tell to "pip" where is my pg_config?
> 
> Best Regards,
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/772ac1dc-e7c2-415c-bc6e-21a1e5b0ec4c%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/44FC535C-1446-4673-8662-906D54E3C247%40prodigy.net.
For more options, visit https://groups.google.com/d/optout.


Re: How to remove Group field from Email Form

2014-06-04 Thread Sergiy Khohlov
Could you please send your view.py form.py and template ...

Many thanks,

Serge


+380 636150445
skype: skhohlov


On Sat, Apr 19, 2014 at 3:39 AM, nobody  wrote:

> Thanks Serge, please see following embedded comments.
>
>
> On Friday, April 18, 2014 11:27:01 PM UTC+10, Sergiy Khohlov wrote:
>>
>> add exlude=  ['Group'] to the form.py
>> Many thanks,
>>
>>
> Hmm, I tried following at my forms.py:
>
> from andsome.forms import EmailForm
> class EmailForm(EmailForm):
>  exclude = ['Group']
>  def get_emails()
>  .
>
> But no luck, it did not work, the Group still displayed.
>
> Serge
>>
>>
>> +380 636150445
>> skype: skhohlov
>>
>>
>> On Fri, Apr 18, 2014 at 4:21 PM, nobody  wrote:
>> > Hi,
>> >
>> > In an email form template file, the following tag displays tree input
>> > fields, Subject, Body and Group, but I only need Subject and Body
>> field, not
>> > the Group, how can I remove the Group field?
>> >
>> > {% form_as_div form %}
>> >
>> > 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...@googlegroups.com.
>> > To post to this group, send email to django...@googlegroups.com.
>> > Visit this group at http://groups.google.com/group/django-users.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msgid/django-users/01227cd2-
>> 4cd5-4e3a-b73e-95590f4a61d1%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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d25fae7f-4ada-4724-baa7-d0a66c35238c%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADTRxJOeqcb4aPSPr%3DC%2B_z3utjG6beD2mDtNRfBN_ok10xEcEQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Transaction failure for nested atomic blocks and concurrent processes on MySQL

2014-06-04 Thread Bluemaro
Hi all,

I have an issue with nested transaction atomic block and concurrent 
processes on MySQL.

Please find details here: 
http://stackoverflow.com/questions/24039678/django-transaction-failure-for-nested-atomic-blocks-and-concurrent-processes-on
 


Thanks for any suggestions.

Regards,
Marek

-- 
You received this message because you are subscribed to the Google Groups 
"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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f4e05525-12b9-4706-b66d-35c89438e34d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: URLs: mymodel_id vs object_id vs pk ....

2014-06-04 Thread monoBOT
Thats a matter of taste ... i use model_id


2014-06-04 14:07 GMT+01:00 Thomas Güttler :

> What is the best practice for named URL parameter which refer to a primary
> key of a model?
>
> I have seen many ways:
>
>  - object_id
>  - mymodel_id
>  - pk
>  - id
>  - .
>
> example:
>
> urlpatterns = [
> url(r'^article/(?P\d+)/$', 'article.view'),
> ...
> ]
>
> Up to now we used "mymodel_id" but it gets boring to type in "mymodel".
>
> This is a question about best practice:
>
> Which do you use (and why)?
>
>
> Related: https://docs.djangoproject.com/en/dev/topics/http/urls/#
> named-groups
>
>   Thomas
>
> --
> You received this message because you are subscribed to the Google Groups
> "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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/538F19FF.1090209%40tbz-pariv.de.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*monoBOT*
Visite mi sitio(Visit my site): monobotblog.alvarezalonso.es

-- 
You received this message because you are subscribed to the Google Groups 
"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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BxOsGD3ePtXWNd-D9AmZ_4mr_%3D3cS_uTi61i5Aou6n7SmZ9QA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: InterfaceError: connection already closed

2014-06-04 Thread Tim Zenderman
I have avoided the issue in the short term by not using ATOMIC_REQUESTS and 
going back to the 1.5 transaction middleware. What could possibly be in my 
code or project that does not sit well with ATOMIC_REQUESTS?

-Tim

On Monday, June 2, 2014 1:50:40 PM UTC-7, Tim Zenderman wrote:
>
> It seems that after updating to 1.6, we are running into an InterfaceError 
> on different views at random times. I found the some older tickets below 
> where the issues is apparently resolved, but it's not in my case. Could 
> this be related to the ATOMIC setting for postgres? What could I be doing 
> in my code that is screwing with the DB connection?
>
> The full stack trace is below. It seems to be happening while the request 
> is starting that the DB connection has already been closed?
>
> We are running this on:
> Ubuntu 12.04
>
> Django 1.6.5
> Psycopg 2.5.3
>
>
>   File "django/core/handlers/base.py", line 88, in get_response
> response = middleware_method(request)
>   File "django/middleware/locale.py", line 32, in process_request
> request, check_path=check_path)
>   File "django/utils/translation/__init__.py", line 166, in 
> get_language_from_request
> return _trans.get_language_from_request(request, check_path)
>   File "django/utils/translation/trans_real.py", line 430, in 
> get_language_from_request
> lang_code = request.session.get('django_language', None)
>   File "django/contrib/sessions/backends/base.py", line 58, in get
> return self._session.get(key, default)
>   File "django/contrib/sessions/backends/base.py", line 173, in 
> _get_session
> self._session_cache = self.load()
>   File "django/contrib/sessions/backends/db.py", line 20, in load
> expire_date__gt=timezone.now()
>   File "django/db/models/manager.py", line 151, in get
> return self.get_queryset().get(*args, **kwargs)
>   File "django/db/models/query.py", line 304, in get
> num = len(clone)
>   File "django/db/models/query.py", line 77, in __len__
> self._fetch_all()
>   File "django/db/models/query.py", line 857, in _fetch_all
> self._result_cache = list(self.iterator())
>   File "django/db/models/query.py", line 220, in iterator
> for row in compiler.results_iter():
>   File "django/db/models/sql/compiler.py", line 713, in results_iter
> for rows in self.execute_sql(MULTI):
>   File "django/db/models/sql/compiler.py", line 785, in execute_sql
> cursor = self.connection.cursor()
>   File "django/db/backends/__init__.py", line 162, in cursor
> cursor = util.CursorWrapper(self._cursor(), self)
>   File "django/db/backends/__init__.py", line 134, in _cursor
> return self.create_cursor()
>   File "django/db/utils.py", line 99, in __exit__
> six.reraise(dj_exc_type, dj_exc_value, traceback)
>   File "django/db/backends/__init__.py", line 134, in _cursor
> return self.create_cursor()
>   File "django/db/backends/postgresql_psycopg2/base.py", line 137, in 
> create_cursor
> cursor = self.connection.cursor()
>
>
> Thanks!
> Tim
>

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


Re: How to install psycopg2 using Pip?

2014-06-04 Thread Fabio Caritas Barrionuevo da Luz

If Ubuntu 12.04 or higher

do:

sudo apt-get install libpq-dev




Em quinta-feira, 24 de março de 2011 12h01min43s UTC-3, Andre Lopes 
escreveu:
>
> Hi,
>
> This question is not directly related with Django, but with Python.
>
> I have installed "virtualenv" to have a virtual environment. Now I
> need to instal "psycopg2" in my virtual environment, but I have not
> successfully installed.
>
> My steps:
>
> [quote]
> pip install
>
> http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
> [/quote]
>
> And I got this message with an error:
>
> [quote]
> Downloading/unpacking
> http://pypi.python.org/packages/source/p/psycopg2/psycopg2
> -2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
>   Downloading psycopg2-2.4.tar.gz (607Kb): 607Kb downloaded
>   Running setup.py egg_info for package from
> http://pypi.python.org/packages/sou
>
> 
> rce/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
> Error: pg_config executable not found.
>
> Please add the directory containing pg_config to the PATH
> or specify the full executable path with the option:
>
> python setup.py build_ext --pg-config 
> /path/to/pg_config build ...
>
> or with the pg_config option in 'setup.cfg'.
> Complete output from command python setup.py egg_info:
> running egg_info
>
> creating pip-egg-info\psycopg2.egg-info
>
> writing pip-egg-info\psycopg2.egg-info\PKG-INFO
>
> writing top-level names to 
> pip-egg-info\psycopg2.egg-info\top_level.txt
>
> writing dependency_links to 
> pip-egg-info\psycopg2.egg-info\dependency_links.txt
>
> writing manifest file 'pip-egg-info\psycopg2.egg-info\SOURCES.txt'
>
> warning: manifest_maker: standard file '-c' not found
>
> Error: pg_config executable not found.
>
> Please add the directory containing pg_config to the PATH
>
> or specify the full executable path with the option:
>
> python setup.py build_ext --pg-config /path/to/pg_config 
> build ...
>
> or with the pg_config option in 'setup.cfg'.
>
> 
> Command python setup.py egg_info failed with error code 1
> Storing complete log in C:\Documents and 
> Settings\anlopes\Application
> Data\pip\p
> ip.log
> [/quote]
>
> My question:
>
> How can I tell to "pip" where is my pg_config?
>
> Best Regards,
>
>

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


RE: URLs: mymodel_id vs object_id vs pk ....

2014-06-04 Thread Ilya Kazakevich
If you use "DetailView"
(https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-display
/#django.views.generic.detail.DetailView) you may call this field "slug" (it
is default). But you can overwrite it.

But in your case custom function is used, so you may call this field
whatever you want. 
I believe "id" is nice.

I use DetailView unless I need really custom logic, so I use "slug" almost
always.

Ilya Kazakevich,
JetBrains PyCharm (Best Python/Django IDE)
http://www.jetbrains.com/pycharm/
"Develop with pleasure!"


>-Original Message-
>From: django-users@googlegroups.com
>[mailto:django-users@googlegroups.com] On Behalf Of Thomas Guttler
>Sent: Wednesday, June 04, 2014 5:07 PM
>To: django-users@googlegroups.com
>Subject: URLs: mymodel_id vs object_id vs pk 
>
>What is the best practice for named URL parameter which refer to a primary
key
>of a model?
>
>I have seen many ways:
>
>  - object_id
>  - mymodel_id
>  - pk
>  - id
>  - .
>
>example:
>
>urlpatterns = [
> url(r'^article/(?P\d+)/$', 'article.view'),
> ...
> ]
>
>Up to now we used "mymodel_id" but it gets boring to type in "mymodel".
>
>This is a question about best practice:
>
>Which do you use (and why)?
>
>
>Related:
>https://docs.djangoproject.com/en/dev/topics/http/urls/#named-groups
>
>   Thomas
>
>--
>You received this message because you are subscribed to the Google Groups
>"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 http://groups.google.com/group/django-users.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/django-users/538F19FF.1090209%40tbz-pari
>v.de.
>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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/03fe01cf7ff8%24c969ba00%245c3d2e00%24%40JetBrains.com.
For more options, visit https://groups.google.com/d/optout.


Re: URLs: mymodel_id vs object_id vs pk ....

2014-06-04 Thread Juergen Schackmann
I am not aware of any best practices for wording here, though my general 
recommendaton would the wording should be identical to the attribute name 
of the model, e.d. 'id', 'slug' or whatever. I would not add the "mymodel" 
prefix as long as it becomes clear from the context to which model it 
belongs to. 

-- 
You received this message because you are subscribed to the Google Groups 
"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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/27c1ef21-12a1-4ad7-8552-ce9747e9b819%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Best option for using json fields with django and postgres

2014-06-04 Thread Marcela Campo
Hi guys,
  I need to use Postgres Json fields in a Django project. I looked around 
and I see many projects that implement json fields and/or queries to json 
fields, I am not sure which is the most widely used. Does someone have any 
recommendations?

Thanks
Marcela

-- 
You received this message because you are subscribed to the Google Groups 
"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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/35e80d2b-ac27-41ae-9cb7-a3e1287f7f31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


URLs: mymodel_id vs object_id vs pk ....

2014-06-04 Thread Thomas Güttler

What is the best practice for named URL parameter which refer to a primary key 
of a model?

I have seen many ways:

 - object_id
 - mymodel_id
 - pk
 - id
 - .

example:

urlpatterns = [
url(r'^article/(?P\d+)/$', 'article.view'),
...
]

Up to now we used "mymodel_id" but it gets boring to type in "mymodel".

This is a question about best practice:

Which do you use (and why)?


Related: https://docs.djangoproject.com/en/dev/topics/http/urls/#named-groups

  Thomas

--
You received this message because you are subscribed to the Google Groups "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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/538F19FF.1090209%40tbz-pariv.de.
For more options, visit https://groups.google.com/d/optout.


Re: django-loses-currently-logged-in-user

2014-06-04 Thread Juergen Schackmann
I have opend another question for this issue:
https://groups.google.com/forum/#!topic/django-users/MBcu77WFCMw

Am Dienstag, 3. Juni 2014 14:28:52 UTC+2 schrieb Juergen Schackmann:
>
> Hi all,
>
> I have a issue, with users not being able to log into my site anymore 
> (after it worked fine for months).
>
> Please find details here: 
> https://stackoverflow.com/questions/24015143/django-loses-currently-logged-in-user
>
> Any help is highly appreciated.
>
> Regards,
> Juergen
>

-- 
You received this message because you are subscribed to the Google Groups 
"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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/24cc19fd-8102-4ca3-b04f-f050e262aa1d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Login/Session Not Sticking

2014-06-04 Thread Juergen Schackmann
Hi all, 
this question refers to this previous 
question: https://groups.google.com/forum/#!topic/django-users/8IXEvfU72S4. 
However, it seems like the problem is slightly different, I decided to open 
a new question:

After my site has been up and running for a while in production, I suddenly 
have a problem with my users loging into it.

   1. I have protected certain views/pages with the login_required 
   decorator and I am also using the django admin.
   2. When an anonymous user hits any of these pages, he is redirected to 
   the login page.
   3. When this anonymous user adds its credentials, the POST request is 
   successful and he is redirected to the inital page. At the same time, the 
   user gets a new sessionid (as expected)
   4. However, now the results get very unreliable. When pressing reload or 
   when navigating to other pages (that require a login), either of the 2 
   outcomes might happen:


   - a) The user is identified and the page is displayed correctly
   - b) The user is redirect to the login page.

I have checked the content of the session via the shell, and nothing is 
changing there.

The production site is served via a load balancer and 8 application 
servers. Even stranger: if I test the same code (with the same settings) on 
a test server, that is not load balanced and basically has not traffic, 
everything is working fine.

I am running Django 1.6 on Ubuntu with Apache and mod_wsgi in daemon mode 
behind SSL and I am using the Session database backend. I am using 
django-allauth.account for account management/login. My Session settings 
are like this:

SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_AGE = 60*60*24
SESSION_COOKIE_SECURE = True

So I have the following questions/ideas?

1. Can this be related to loadbalancing in anyway? My understanding was 
that Django does not need sticky sessions, when the DB session backend is 
used.

2. Can this be related to a threading issue?

3. Can this be related to high load?

4. Can this be related to a decoding issue: 
https://github.com/django/django/blob/master/django/contrib/sessions/backends/base.py#L83.
 
However, I have not found any log entries that refer to "Session data 
corrupted".

Any other hints are welcome.


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


Re: editable models (db schema) for admin (no developer)

2014-06-04 Thread Thomas Güttler

I found several solution here: http://stackoverflow.com/a/7934577/633961

Am 03.06.2014 15:57, schrieb Thomas Güttler:

Hi,

I am a software developer and like the way django ORM defines the database (via 
models.py) very much.

Unfortunately for a new project, we have the constraint, that the admin must be 
able
to add some columns. The admin is not a developer, and he only uses a web 
interface.

I don't want to make model.py files editable via an admin interface, since 
running migrations and all
that does not fit into "web editable".

Any hints how to solve this?

   Thomas





--
You received this message because you are subscribed to the Google Groups "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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/538EF626.5010709%40tbz-pariv.de.
For more options, visit https://groups.google.com/d/optout.


Tango with Django - Populated Script

2014-06-04 Thread Srinivasulu Reddy
Hello Folks,
   I am learning tangowithdjango book . In chapter 5 while dealing 
the Populated Script i am getting this error . Please any one can help me 
on this

(mysite)seenu@acer:~/django_projects/seenu/tango_django$ python 
populate_rango.py 

 Starting Rango population script...
Traceback (most recent call last):
  File "populate_rango.py", line 60, in 
populate()
  File "populate_rango.py", line 4, in populate
python_cat = add_cat('Python', views=128, likes=64)
  File "populate_rango.py", line 52, in add_cat
c = Category.objects.get_or_create(name=name,views=views,likes=likes)[0]
  File 
"/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/manager.py",
 
line 134, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
  File 
"/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/query.py",
 
line 445, in get_or_create
return self.get(**lookup), False
  File 
"/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/query.py",
 
line 361, in get
num = len(clone)
  File 
"/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/query.py",
 
line 85, in __len__
self._result_cache = list(self.iterator())
  File 
"/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/query.py",
 
line 291, in iterator
for row in compiler.results_iter():
  File 
"/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
 
line 763, in results_iter
for rows in self.execute_sql(MULTI):
  File 
"/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
 
line 818, in execute_sql
cursor.execute(sql, params)
  File 
"/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/backends/util.py",
 
line 40, in execute
return self.cursor.execute(sql, params)
  File 
"/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py",
 
line 114, in execute
return self.cursor.execute(query, args)
  File 
"/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/MySQLdb/cursors.py",
 
line 205, in execute
self.errorhandler(self, exc, value)
  File 
"/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/MySQLdb/connections.py",
 
line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.DatabaseError: (1054, "Unknown column 
'rango_category.views' in 'field list'")

-- 
You received this message because you are subscribed to the Google Groups 
"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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/88302aea-1e23-4c40-9459-05ea25c959c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2014-06-04 Thread ngangsia akumbo
Thanks for this reply , am not using anybody's code. I am still studying 
django and was wondering where those fields where from. Thanks for the 
clarification. With time i will write my own field since am from Cameroon.

On Tuesday, June 3, 2014 2:16:37 AM UTC+1, Andrew Farrell wrote:
>
> Hi Mr. Akumbo,
>
> The options for Model Fields that come with django in the django.db 
> library and are listed and explained here: 
> https://docs.djangoproject.com/en/dev/ref/models/fields/#model-field-types
>
>
> Each corresponds to a different type of data. For example
>
> name = models.CharField(max_length=60)
>
> just means that the the database will store a 60-character text string 
> (VARCHAR).
>
> Other libraries can define other field types. For example, the 
> https://pypi.python.org/pypi/django-localflavor package has Model fields 
> specific to different nations such as localflavor.za.forms.ZAPostCodeField 
> for South African postal codes. If you really need to, you can look at the 
> source 
> code 
> 
>  
> of that project for an example of defining your own.
>
> It sounds like you are working through someone else's django project but 
> would find some broader context useful. If you haven't already, I would 
> recommend working through the tutorial, starting here:
> https://docs.djangoproject.com/en/dev/intro/tutorial01/
>
> best regards,
> Andrew Farrell
>
>
> On Mon, Jun 2, 2014 at 8:51 PM, ngangsia akumbo  > wrote:
>
>>
>>
>> On Sunday, June 1, 2014 7:42:13 PM UTC+1, Thomas wrote:
>>
>>>
>>> On 2014-05-31, at 4:41 AM, ngangsia akumbo  wrote:
>>>
>>> please i need some legit answer please
>>>
>>>
>>> Please give one or two specific examples of functionality you need. 
>>> There are parameters for fields which can help specialize some behaviours 
>>> without needing a new model. And there are hooks to allow specialization of 
>>> behaviours in interpretation or handling when reading or saving values 
>>> which you may find useful.
>>>
>>> afaik there is no large library of model specializations for Django, but 
>>> that may be because there is no clear large set of specializations that 
>>> would be useful.
>>>
>>> So give an example please. Is it the book name, the book author, or 
>>> something else which needs extra or restricted behaviours?
>>>
>>> - Tom
>>>
>>>
>> This is an example. Where did the get all these parameter like CharField, 
>> DateTimeField etc.
>>  
>>
>>> class Item(models.Model):
>>> name = models.CharField(max_length=60)
>>> created = models.DateTimeField(auto_now_add=True)
>>> priority = models.IntegerField(default=0)
>>> difficulty = models.IntegerField(default=0)
>>> done = models.BooleanField(default=False)
>>> class ItemAdmin(admin.ModelAdmin):
>>> list_display = ["name", "priority", "difficulty", "created", "done"]
>>> search_fields = ["name"]
>>> admin.site.register(Item, ItemAdmin)
>>>
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/44996582-811d-4731-a8d6-7133a02459b4%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d7781eac-d29e-43f9-b524-ecbe84ff8c49%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django app and a submodule name conflict

2014-06-04 Thread Vahe Evoyan


I have modules in the project with the same names, all placed in different 
applications.

Particularly there are two apps that conflict and result an ImportError. 
The project structure approximately is as follows.

project
 |_ project   
   |_ settings.py
   |_ ...
 |_ apps
   |_ A
 |_ handlers
   |_ B.py
   |_ C.py
   |_ B
 |_ models.py

The settings file adds apps directory to the system path.

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(BASE_DIR, "apps"))

This configuration assumes that when I import the B.models it will use 
apps/B/models.py. Although the following line in the C.py file raise an 
import error as it imports the A/handlers/B.pywhich does not have models
 module.

A/handlers/C.py:
from B.models import BModel

The sys.path variable has a correct items, i.e. the first one in the list 
is /path/to/project/appsand sys.modules['B.models'] is referenced to the 
correct file.

BTW, when I use Django's import_by_path function, everything works fine.

Any ideas how I can solve the problem without renaming the modules?

Posted sample sources 
 on GitHub.

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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2409cb23-6924-4da1-9f68-245e49bd4c3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problems connecting to an oracle legacy db

2014-06-04 Thread Vittorio
I have an Ubuntu linux  server on which I installed the oracle instanclient 
stuff to run a client of a remote legacy oracle database.

It works great!

#TNSNAMES.ORA
my_db=
(DESCRIPTION =
  (ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 46.128.3.178)(PORT = 1521))
  )
  (CONNECT_DATA =
(SID = DANT)
  )
)

Trying with SQLPlus

victor@ubuntu:~$ sqlplus my_user/my_passw@my_db
SQL*Plus: Release 12.1.0.1.0 Production on Wed Jun 4 09:57:04 2014
Copyright (c) 1982, 2013, Oracle.  All rights reserved

Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
SQL> 

... and with Python

>>> import cx_Oracle
>>> con = cx_Oracle.connect('my_user', 'my_passw', '46.128.3.178:/DANT')
>>> cur = con.cursor()
>>> cur.execute('select * from noema.magazzino_vista_lista')
>
>>> 
>>> for result in cur:
... print result
... 
(12, 'MAG0005240', '0005240', 1)
(12, 'MAG946', '946', 2)
(12, 'MAG0001930', '0001930', 3)
(17, 'MAGCARPIE008', 'CARPIE008', 1)
(17, 'MAGLETTEL0002', 'LETTEL0002', 1)
>>> 

That's all ok!

Now, on the same server,  I have a  django 1.6.2 project named 'myorac' and an 
application called 'noematica'

#settings.py 
..
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle', 
'NAME': 'my_db',  
'USER': 'my_user',  
'PASSWORD': 'my_passw',  
'HOST': '46.128.3.178',  
'PORT': '1521',  
},
}

#models.py
...
class magazzino_vista_lista(models.Model):
id_ordine = models.IntegerField(null=False, blank=False, 
db_column='ID_ORDINE')
cod_magazzino_galileo = models.CharField(max_length=48, 
db_column='COD_MAGAZZINO_GALILEO')
cod_magazzino_ext = models.CharField(max_length=48, 
db_column='COD_MAGAZZINO_EXT')
qta = models.IntegerField(null=False, blank=False, db_column='QTA')
class Meta:
managed = False
db_table = u'noema.magazzino_vista_lista'
verbose_name_plural = "CC specifica ordini vista"

* See the real oracle table is named 'noema.magazzino_vista_lista' as in 
the sql I called before under python *

#admin.py
.
admin.site.register(magazzino_vista_lista)


When I start my application via python manage.py runserver I get the following 
error in the browser at the very beginning

DatabaseError at /noematica/
ORA-00942: table or view does not exist
Request Method: GET
Request URL:http://10.20.0.1:7600/noematica/
Django Version: 1.6.2
Exception Type: DatabaseError
Exception Value:
ORA-00942: table or view does not exist
Exception Location: 
/usr/local/lib/python2.7/dist-packages/django/db/backends/oracle/base.py in 
execute, line 815


Why is that? I can't figure out what I made it wrong in the  definition of the 
database in settings.py or in the db_table definition in models.py
Please help
Vittorio

-- 
You received this message because you are subscribed to the Google Groups 
"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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4E45C150-CF81-4927-B304-13D446260EDE%40de-martino.it.
For more options, visit https://groups.google.com/d/optout.


Re: Instagram + Heroku + Django + HTTP headers

2014-06-04 Thread Daniel Roseman
On Tuesday, 3 June 2014 22:35:07 UTC+1, Dr Shauny wrote:
>
> Hi,
>
> I have a Django/Python app that is hosted on Heroku. The app uses the 
> Instagram API.
>
> I am trying to secure the app by enforcing signed HTTP headers using 
> X-Insta-Forwarded-For.
>
> The actual header value is constructed as - "The expected value is a 
> combination of the client's IP address and a HMAC signed using the SHA256 
> hash algorithm with your client's IP address and Client Secret"
>
> Does anyone know what IP information should be used for a Heroku hosted 
> app? - the app IP is dynamic and unpredictable but the Instagram devs have 
> told me that just an approximate IP is required, possibly only a Heroku 
> gateway IP. How do I find out what is a suitable IP? (I dont want to use a 
> proxy to fix the IP).
>
> Also how do I actually add this header information to http headers? 
> Middleware has been mentioned but I dont know where to start with coding a 
> middleware solution. Is it possible to do this at the web server level on 
> Heroku - would this be easier than middleware?
>
> Anyone had experience of a similar setup that could give me some pointers 
> here. All info much appreciated.
>
> Thanks,
>
> S.
>

Interesting question. I also happen to be creating an app on Heroku using 
Instagram, and I hadn't come across the signed header option before, so 
thanks. (Interestingly it doesn't seem to be easily googleable - the only 
reference appears to be your question, and something in Russian. I wonder 
if it's very new?)

Looking at the docs, it seems that it doesn't want the IP of your app 
itself, but the value of the *client*, which you can access in the 
X-Forwarded-For header. The StackOverflow question at [1] quotes Heroku's 
director of security (who also, not coincidentally, happens to be Django's 
very own Jacob Kaplan-Moss) as stating that Heroku preserves the original 
client IP and prepends any other values, so it looks as if you can pass in 
the string available from `request.META['X-FORWARDED-FOR']` directly.

If I've misunderstood that and you do need the IP of the server, it looks 
like the only way to do that would be to use one of the Heroku add-ons that 
routes outgoing data through a static proxy. Proximo and QuotaGuard seem to 
be the options - only QuotaGuard offers a free development option, though.

As regards how to get the value into the request, middleware wouldn't be an 
appropriate solution here at all. However looking at the repo for the 
Python instagram client, just yesterday a pull request ([2]) was merged 
that added in support for exactly this - so you can pass in the IP and your 
client secret when instantiating the API object.

  [1]: 
http://stackoverflow.com/questions/18264304/get-clients-real-ip-address-on-heroku
  [2]: https://github.com/Instagram/python-instagram/pull/76
--
DR.

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