Re: ModelForm changing default field for ForeingKey

2014-06-03 Thread Ymir Camilo Acosta Rodriguez
Thank you Daniel, it works for me. ;)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To 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/766439c2-f4af-4073-a992-ae68f3ad8b6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Reference to form cleaned data field throws TypeError: 'exceptions.AttributeError' object is not callable

2014-06-03 Thread Andromeda Yelton
clean_email needs to return the cleaned email regardless of whatever else
it does.  This clean_email returns email when it's valid but not when it
isn't.  This means that whatever Django internals are expecting, and trying
to operate upon, its return value are throwing exceptions instead.  This is
also why the behavior is intermittent - you only see it with invalid
emails. --ay


On Tue, Jun 3, 2014 at 8:24 PM, Gloria W  wrote:

> This is the strangest bug I've seen in Django. (1.6.4 on Ubuntu 14.04,
> Python 2.7.6)
>  It is sporadic, but once it starts happening, it is consistent until I
> restart the process.
> To try and debug it, I print the value of self.cleaned_data just before it
> occurs. The value prints fine.
>
>
> The code:
>
> def clean_email(self):
> logger.warn("Debugging Attribute error:%s" %
> pprint.pformat(self.cleaned_data))
> try:
> FytUser.objects.get(email=self.cleaned_data['email'])
> raise forms.ValidationError('A user with that email address
> already exists.')
> except FytUser.DoesNotExist:
> return self.cleaned_data['email']
>
>
> The traceback in the uwsgi logs:
>
> Debugging Attribute error:{'email': u't...@test.net'}
>
> Traceback (most recent call last):
>
>   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", 
> line 114, in get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>
>   File "./registration/views.py", line 54, in preregister_check
> if form.is_valid():
>
>   File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py", line 
> 129, in is_valid
> return self.is_bound and not bool(self.errors)
>
>   File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py", line 
> 121, in errors
> self.full_clean()
>
>   File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py", line 
> 273, in full_clean
> self._clean_fields()
>
>   File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py", line 
> 291, in _clean_fields
> value = getattr(self, 'clean_%s' % name)()
>
>   File "./fyt/forms.py", line 87, in clean_email
> FytUser.objects.get(email=self.cleaned_data['email'])
>
>   File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", 
> line 151, in get
> return self.get_queryset().get(*args, **kwargs)
>
>   File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", 
> line 307, in get
> self.model._meta.object_name)
>
> TypeError: 'exceptions.AttributeError' object is not callable
>
>
>  path:*/prereg_check/*,
> GET:,
> POST: u'last_name': [u'W'], u'is_member': [u'1'], u'gender': [u'2'], u'first_name': 
> [u'G'], u'birthday_day': [u'01'], u'birthday_month': [u'01'], 
> u'csrfmiddlewaretoken': [u'MYKnPppKtnKV4ybQ86rkYsv8Er2LIc1a'], u'password': 
> [u'x'], u'email': [u't...@test.net '], 
> u'discount_code': [u'']}>,
> COOKIES:{'_ga': 'xxx',
>  'csrftoken': 'x',
>  'sessionid': 'xx',
>  'signup_modal': 'true'},
> META:{'CONTENT_LENGTH': '221',
>  'CONTENT_TYPE': 'application/x-www-form-urlencoded; charset=UTF-8',
>  u'CSRF_COOKIE': u'xx',
>  'DOCUMENT_ROOT': '/home/xx',
>  'HTTP_ACCEPT': 'application/json, text/javascript, */*; q=0.01',
>  'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
>  'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.5',
>  'HTTP_CACHE_CONTROL': 'no-cache',
>  'HTTP_CONNECTION': 'keep-alive',
>  'HTTP_CONTENT_LENGTH': '221',
>  'HTTP_CONTENT_TYPE': 'application/x-www-form-urlencoded; charset=UTF-8',
>  'HTTP_COOKIE': 'csrftoken=xxx; sessionid=xx; _ga=xx; 
> signup_modal=true',
>  'HTTP_HOST': 'findyourtrainer.com',
>  'HTTP_PRAGMA': 'no-cache',
>  'HTTP_REFERER': 'https://x/register?next=/ 
> ',
>  'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 
> Firefox/29.0',
>  'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
>  'PATH_INFO': u'*/prereg_check/*',
>  'QUERY_STRING': '',
>  'REMOTE_ADDR': '',
>  'REMOTE_PORT': '37998',
>  'REQUEST_METHOD': 'POST',
>  'REQUEST_URI': '*/prereg_check/*',
>  u'SCRIPT_NAME': u'',
>  'SERVER_NAME': '.com',
>  'SERVER_PORT': '443',
>  'SERVER_PROTOCOL': 'HTTP/1.1',
>  'UWSGI_SCHEME': 'https',
>  'uwsgi.node': '.com',
>  'uwsgi.version': '2.0.4',
>  'wsgi.errors': ,
>  'wsgi.file_wrapper': ,
>  'wsgi.input': ,
>  'wsgi.multiprocess': True,
>  'wsgi.multithread': False,
>  'wsgi.run_once': False,
>  'wsgi.url_scheme': 'https',
>  'wsgi.version': (1, 0)}>
>
>
> This looks like a memory leak to me. Has anyone else seen this?
> Thanks in advance,
> ~G~
>
> --
> You received this message because you are subscribed to the Google Groups
> "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 

Reference to form cleaned data field throws TypeError: 'exceptions.AttributeError' object is not callable

2014-06-03 Thread Gloria W
This is the strangest bug I've seen in Django. (1.6.4 on Ubuntu 14.04, 
Python 2.7.6)
 It is sporadic, but once it starts happening, it is consistent until I 
restart the process. 
To try and debug it, I print the value of self.cleaned_data just before it 
occurs. The value prints fine. 


The code:

def clean_email(self):
logger.warn("Debugging Attribute error:%s" % 
pprint.pformat(self.cleaned_data))
try:
FytUser.objects.get(email=self.cleaned_data['email'])
raise forms.ValidationError('A user with that email address 
already exists.')
except FytUser.DoesNotExist:
return self.cleaned_data['email']


The traceback in the uwsgi logs: 

Debugging Attribute error:{'email': u't...@test.net'}

Traceback (most recent call last):

  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", 
line 114, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)

  File "./registration/views.py", line 54, in preregister_check
if form.is_valid():

  File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py", line 
129, in is_valid
return self.is_bound and not bool(self.errors)

  File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py", line 
121, in errors
self.full_clean()

  File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py", line 
273, in full_clean
self._clean_fields()

  File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py", line 
291, in _clean_fields
value = getattr(self, 'clean_%s' % name)()

  File "./fyt/forms.py", line 87, in clean_email
FytUser.objects.get(email=self.cleaned_data['email'])

  File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", 
line 151, in get
return self.get_queryset().get(*args, **kwargs)

  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 
307, in get
self.model._meta.object_name)

TypeError: 'exceptions.AttributeError' object is not callable


,
POST:'], u'discount_code': 
[u'']}>,
COOKIES:{'_ga': 'xxx',
 'csrftoken': 'x',
 'sessionid': 'xx',
 'signup_modal': 'true'},
META:{'CONTENT_LENGTH': '221',
 'CONTENT_TYPE': 'application/x-www-form-urlencoded; charset=UTF-8',
 u'CSRF_COOKIE': u'xx',
 'DOCUMENT_ROOT': '/home/xx',
 'HTTP_ACCEPT': 'application/json, text/javascript, */*; q=0.01',
 'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.5',
 'HTTP_CACHE_CONTROL': 'no-cache',
 'HTTP_CONNECTION': 'keep-alive',
 'HTTP_CONTENT_LENGTH': '221',
 'HTTP_CONTENT_TYPE': 'application/x-www-form-urlencoded; charset=UTF-8',
 'HTTP_COOKIE': 'csrftoken=xxx; sessionid=xx; _ga=xx; 
signup_modal=true',
 'HTTP_HOST': 'findyourtrainer.com',
 'HTTP_PRAGMA': 'no-cache',
 'HTTP_REFERER': 'https://x/register?next=/ 
',
 'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 
Firefox/29.0',
 'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
 'PATH_INFO': u'*/prereg_check/*',
 'QUERY_STRING': '',
 'REMOTE_ADDR': '',
 'REMOTE_PORT': '37998',
 'REQUEST_METHOD': 'POST',
 'REQUEST_URI': '*/prereg_check/*',
 u'SCRIPT_NAME': u'',
 'SERVER_NAME': '.com',
 'SERVER_PORT': '443',
 'SERVER_PROTOCOL': 'HTTP/1.1',
 'UWSGI_SCHEME': 'https',
 'uwsgi.node': '.com',
 'uwsgi.version': '2.0.4',
 'wsgi.errors': ,
 'wsgi.file_wrapper': ,
 'wsgi.input': ,
 'wsgi.multiprocess': True,
 'wsgi.multithread': False,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'https',
 'wsgi.version': (1, 0)}>


This looks like a memory leak to me. Has anyone else seen this?
Thanks in advance,
~G~

-- 
You received this message because you are subscribed to the Google Groups 
"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/11ddf2f6-7a07-4c1e-86db-b7e0223546ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Instagram + Heroku + Django + HTTP headers

2014-06-03 Thread Dr Shauny
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.

-- 
You received this message because you are subscribed to the Google Groups 
"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/d1af5890-29d5-4657-9bc1-219dcdeae473%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


safari ios 7 and django app - function not being called to serve video

2014-06-03 Thread Adam Teale
Hi Guys,

I am in the process of building a web app with django.
The app is running on apache and files/videos are served with the xsendfile 
apache module.
The app is working fine on iphones, ipads and macs on the local network - 
when I access the site via a url like https://myapp.local

When I visit the app through it's real world domain (https://myapp.com) via 
a computer everything is ok too.
But when on the iPhone/ipad the videos do not get loaded. The custom url I 
have made for serving the videos isn't even called.

I am embedding the videos like this:


So the url is called to grab that asset and return the file response with 
the path.
This 'serveAsset' doesn't get called from the iPhone/iPad.
When I hit that url directly the video doesn't load either.
(But it does from a mac and safari - including using the "Safari iOS7 - 
iPhone" User agent.

Does Safari iOS7 not work with urls that serve material for the page?

Any ideas what might be going on?

Any help would be very much appreciated!

Cheers

Adam

-- 
You received this message because you are subscribed to the Google Groups 
"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/62927890-40aa-47d6-84cb-0c26bd5285f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: newbie with models - user-defined function raised exception

2014-06-03 Thread Ilya Kazakevich
You probably should not use this book for Django 1.5.

It says: 
" While the book mentions Django version 1.4 in places, the vast majority of 
the book is for Django version 1.0"
And
" we ask that, at this time, djangobook.com not be used for educational 
purposes. "

Actually, you should start with Django 1.6 or even 1.7 (1.5 is outdated!) and 
use official Django tutorial 
(https://docs.djangoproject.com/en/dev/intro/tutorial01/) instead of this book.


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 Sami Razi
>Sent: Tuesday, June 03, 2014 11:12 PM
>To: django-users@googlegroups.com
>Subject: newbie with models - user-defined function raised exception
>
>hi,
>i'm using djangobook   to learn django,
>
>when i go to localhost:8000/admin
>
>there's no problem, also no problem with these two:
>
>http://localhost:8000/admin/books/
>http://localhost:8000/admin/books/publisher/
>
>but going to:
>http://localhost:8000/admin/books/book
>gives this error:
>
>
>
>DatabaseError at /admin/books/book/
>
>user-defined function raised exception
>Request Method: GET
>Request URL:http://localhost:8000/admin/books/book/
>Django Version: 1.5.5
>Exception Type: DatabaseError
>Exception Value:user-defined function raised exception
>Exception Location:
>/usr/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py in execute,
>line 362
>Python Executable:  /usr/bin/python
>Python Version: 2.7.5
>Python Path:['/home/asedsami/djcode/mysite',
> '/usr/lib64/python27.zip',
> '/usr/lib64/python2.7',
> '/usr/lib64/python2.7/plat-linux2',
> '/usr/lib64/python2.7/lib-tk',
> '/usr/lib64/python2.7/lib-old',
> '/usr/lib64/python2.7/lib-dynload',
> '/usr/lib64/python2.7/site-packages',
> '/usr/lib64/python2.7/site-packages/gtk-2.0',
> '/usr/lib/python2.7/site-packages']
>Server time:Wed, 4 Jun 2014 13:33:43 -0500
>-
>--
>
>
>
>
>
>
>
>Error during template rendering
>
>
>In template
>/usr/lib/python2.7/site-packages/django/contrib/admin/templates/admin/chang
>e_list.html, error at line 73
>
>
>user-defined function raised exception
>
>63 {% endif %}
>64 {% endblock %}
>65 {% if cl.formset.errors %}
>66 
>67 {% blocktrans count cl.formset.errors|length as counter %}Please
>correct the error below.{% plural %}Please correct the errors below.{%
>endblocktrans %}
>68 
>69 {{ cl.formset.non_form_errors }}
>70 {% endif %}
>71 id="changelist">
>72 {% block search %}{% search_form cl %}{% endblock %}
>73 {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
>74
>
>75 {% block filters %}
>76 {% if cl.has_filters %}
>77 
>78 {% trans 'Filter' %}
>79 {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{%
>endfor %}
>80 
>81 {% endif %}
>82 {% endblock %}
>83
>
>
>should i ask this in stackoverflow instead of here?
>i don't think i never even touched the above file and i don't know what causes 
>this
>error, so, thank you for you help.
>
>
>--
>You received this message because you are subscribed to the Google Groups
>"Django users" group.
>To unsubscribe from this group and stop receiving emails from it, send an 
>email to
>django-users+unsubscr...@googlegroups.com.
>To 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/3eb82801-caec-4b5b-b608-0e
>7f38752885%40googlegroups.com
>e7f38752885%40googlegroups.com?utm_medium=email_source=footer> .
>For more options, visit https://groups.google.com/d/optout.


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


newbie with models - user-defined function raised exception

2014-06-03 Thread Sami Razi
hi,
i'm using djangobook  to learn django, 

when i go to localhost:8000/admin 

there's no problem, also no problem with these two:

http://localhost:8000/admin/books/
http://localhost:8000/admin/books/publisher/

but going to:
http://localhost:8000/admin/books/book
gives this error:

DatabaseError at /admin/books/book/ 

user-defined function raised exception

 Request Method: GET  Request URL: http://localhost:8000/admin/books/book/  
Django 
Version: 1.5.5  Exception Type: DatabaseError  Exception Value: 

user-defined function raised exception

 Exception Location: 
/usr/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py 
in execute, line 362  Python Executable: /usr/bin/python  Python Version: 
2.7.5  Python Path: 

['/home/asedsami/djcode/mysite',
 '/usr/lib64/python27.zip',
 '/usr/lib64/python2.7',
 '/usr/lib64/python2.7/plat-linux2',
 '/usr/lib64/python2.7/lib-tk',
 '/usr/lib64/python2.7/lib-old',
 '/usr/lib64/python2.7/lib-dynload',
 '/usr/lib64/python2.7/site-packages',
 '/usr/lib64/python2.7/site-packages/gtk-2.0',
 '/usr/lib/python2.7/site-packages']

 Server time: Wed, 4 Jun 2014 13:33:43 -0500
---





Error during template rendering 

In template 
/usr/lib/python2.7/site-packages/django/contrib/admin/templates/admin/change_list.html,
 
error at line *73*
user-defined function raised exception 63{% endif %} 64{% endblock 
%} 65{% if cl.formset.errors %} 66 67{% 
blocktrans count cl.formset.errors|length as counter %}Please correct the 
error below.{% plural %}Please correct the errors below.{% endblocktrans %} 
68 69{{ cl.formset.non_form_errors }} 70{% endif %} 71
 72{% block search %}{% search_form cl %}{% endblock %} 
73{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %} 74 
75{% block filters %} 76{% if cl.has_filters %} 77 78{% trans 'Filter' %} 79{% for 
spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %} 80
 81{% endif %} 82{% endblock %} 83 

should i ask this in stackoverflow instead of here?
i don't think i never even touched the above file and i don't know what 
causes this error, so, thank you for you help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To 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/3eb82801-caec-4b5b-b608-0e7f38752885%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to install psycopg2 using Pip?

2014-06-03 Thread Adrian Miguel
Where can I find the setup.cfg file on a mac?

On Monday, July 23, 2012 3:18:02 PM UTC-4, Mehrdad Majzoobi wrote:
>
> Ok, I realized what the issue was. In the setup.cfg file, the pg_config 
> path had to include the pg_config executable name as well:
>
> pg_config = /usr/pgsql-9.1/bin/pg_config
>
> On Monday, July 23, 2012 2:01:29 PM UTC-5, Mehrdad Majzoobi wrote:
>>
>> Guys, I have a similar problem but the difference is pg_config is 
>> actually in my PATH:
>>
>> $ which pg_config
>> /usr/pgsql-9.1/bin/pg_config
>>
>> I get the following error when I try to pip install psychopg2
>>
>> ###
>> 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 in 
>> /tmp/pip-build/psycopg2
>>
>> ###
>>
>> I tried adding pg_config path to the setup.cfg file and build it using 
>> the source files I downloaded from their website and I get the following 
>> error message!
>>
>> Error: Unable to find 'pg_config' file in '/usr/pgsql-9.1/bin/'
>>
>>
>> But it is actually THERE!!!
>>
>> I am baffled by these errors. Can anyone help please?
>>
>> By the way, I sudo all the commands. Also I am RHEL 5.5.
>>
>>
>>
>> On Thursday, March 24, 2011 11:18:23 AM UTC-5, Shawn Milochik wrote:
>>>
>>> On Thu, Mar 24, 2011 at 12:03 PM, Andre Lopes >> > wrote:
>>> > I have solved.
>>> >
>>> > I just edited "setup.cfg" on the psycopg2 and added:
>>> >
>>> > pg_config=C:\Program Files\PostgreSQL\8.4\bin\pg_config.exe
>>>
>>>
>>> Yeah, that's the easiest method, but you specifically wanted to know
>>> how to install it with pip. That way you have to install the module
>>> manually. But it works. ;o)
>>>
>>> Shawn
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"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/705681fa-fb8a-498c-9699-31d523de6698%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: DB Router not working on production machine, works on dev.

2014-06-03 Thread Doug Ballance
The problem turned out to be an bug with an custom manager class based on 
djorm_pgfulltext search mixin.  I'd found an issue with it last week, and 
patched in the development environment but forgotten to patch the other 
machine.  

-- 
You received this message because you are subscribed to the Google Groups 
"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/f9a2cd3c-2ac2-4ebb-8873-85f1eb298d19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2014-06-03 Thread Alexandr Shurigin
Check stackoverflow. Answered there for your question.

On Tuesday, June 3, 2014 7:28:52 PM UTC+7, Juergen Schackmann wrote:
>
> 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/b1b8e438-70c0-4ee8-b1ac-60e35134504b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2014-06-03 Thread Erik Cederstrand
Den 03/06/2014 kl. 15.57 skrev Thomas Güttler :

> 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".

Are you *really* sure you want to do this? Monkey-patching running code, adding 
class attributes and inserting database columns on the fly to a production 
system isn't something recommended in textbooks. Try describing your situation 
a bit. Maybe you could use a key-value approach and m2m relations instead?

If you *really* want to do it, and you want to edit models.py, then you should 
schedule an external task that appends the column to models.py (and commits the 
change to your VCS, adds tests, ...) and deploys the new code on your server.

Another possibility is that you avoid editing models.py by creating the new 
database column manually using raw SQL, so Django doesn't know about it. Then 
override __getattr__ on the model so my_obj.extra_col_123 circumvents the ORM 
and fetches data by other means, or simply issue raw SQL when you need to 
access 'extra_col_123' in your code.

Erik

-- 
You received this message because you are subscribed to the Google Groups 
"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/BD86175C-64BB-4258-8296-52D021529D39%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


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

2014-06-03 Thread Thomas Güttler



Am 03.06.2014 16:27, schrieb Erik Cederstrand:

Den 03/06/2014 kl. 15.57 skrev Thomas Güttler :


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".


Are you *really* sure you want to do this? Monkey-patching running code, adding 
class attributes and inserting database columns on the fly to a production 
system isn't something recommended in textbooks. Try describing your situation 
a bit. Maybe you could use a key-value approach and m2m relations instead?


I am sure: I don't want it. I guess you have read my post too fast.


Another possibility is that you avoid editing models.py by creating the new 
database column manually using raw SQL, so Django doesn't know about it. Then 
override __getattr__ on the model so my_obj.extra_col_123 circumvents the ORM 
and fetches data by other means, or simply issue raw SQL when you need to 
access 'extra_col_123' in your code.


Yes, this would be a solution.

Thank you for your feedback.

--
You received this message because you are subscribed to the Google Groups "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/538DDCE5.2000108%40tbz-pariv.de.
For more options, visit https://groups.google.com/d/optout.


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

2014-06-03 Thread 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/538DD465.3060300%40tbz-pariv.de.
For more options, visit https://groups.google.com/d/optout.


Re: Django Macros Url. Routing must be simple!

2014-06-03 Thread Alexandr Shurigin
I make mistake. I have context of course :)

Added support for include() in view parameter. Now it build (normalize) 
right patterns without endng dollar sign if include view was passed.

All works automatically and like default django url function.

Version bumped to 0.1.1.

On Tuesday, June 3, 2014 1:49:37 AM UTC+7, Alexandr Shurigin wrote:
>
> Hi all!
>
> Yestarday i released beta version of new django routing helper component.
>
> Routing must be simple. Now we talking with django core team about making 
> django routing simpler by default.
>
> If anybody is interested about it, you can use right now my component to 
> make your routes simple, clean and readable in future instead of native 
> regular expressions.
>
> http://phpdude.github.io/django-macros-url/
>

-- 
You received this message because you are subscribed to the Google Groups 
"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/34c75300-8e04-40da-b704-e0a500fe5518%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Macros Url. Routing must be simple!

2014-06-03 Thread Alexandr Shurigin
Sorry for my english. Not my primary language :(

I trying to learn it :-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To 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/d6122aae-42e1-439a-a4b4-53fd20587681%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Macros Url. Routing must be simple!

2014-06-03 Thread Alexandr Shurigin
Just readed about "POSIX style regular expression named character sets". 
Good idea too. But for now this is utility application with simple syntax, 
i hope soon django core team think about implementing this as core part and 
they will choose best naming style i hope :)

I just used ROR naming standart. This looks simple and very clean.

On Tuesday, June 3, 2014 1:49:37 AM UTC+7, Alexandr Shurigin wrote:
>
> Hi all!
>
> Yestarday i released beta version of new django routing helper component.
>
> Routing must be simple. Now we talking with django core team about making 
> django routing simpler by default.
>
> If anybody is interested about it, you can use right now my component to 
> make your routes simple, clean and readable in future instead of native 
> regular expressions.
>
> http://phpdude.github.io/django-macros-url/
>

-- 
You received this message because you are subscribed to the Google Groups 
"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/4ff4820e-1491-4ce2-954c-57ec291c46fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Macros Url. Routing must be simple!

2014-06-03 Thread Alexandr Shurigin
Hi, thank you for review :)

Yes this s just thing to make groups more clean and simple.

used :name as pattern from Ruby On Rails naming. Looks simple and avoid 
errors.

You can combine base macro types with your names by underscope. For example

/:book_id/:product_id/:id

You will have 3 different matches in your kwargs of course.

Works with any masks and any 'deep'.

/:main_product_id/:main_news_category_id/

Try it!

This component make me happy and i would share it to everyone until 
django-core team doesn't make ame way out of the box by default.

One small thing - url normalization add $ to end of patterns, this can make 
problem if you make "include('project.app.urls')" via Macros Url. I know 
about this, but i just propose use default django url for this. If core 
team implement this as part of core, they will have context of added 
view(or include) and can make choose about ending $. Macros url build like 
a regex preprocessor and have not this context. Anyway includes 99% cases 
are simple plain text paths and not need macro embedding into it, there can 
be used django url function without any problems. For me more important to 
add $ to end of real pattern url because sometimes this can be forgotten :)

Alexandr.

On Tuesday, June 3, 2014 1:49:37 AM UTC+7, Alexandr Shurigin wrote:
>
> Hi all!
>
> Yestarday i released beta version of new django routing helper component.
>
> Routing must be simple. Now we talking with django core team about making 
> django routing simpler by default.
>
> If anybody is interested about it, you can use right now my component to 
> make your routes simple, clean and readable in future instead of native 
> regular expressions.
>
> http://phpdude.github.io/django-macros-url/
>

-- 
You received this message because you are subscribed to the Google Groups 
"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/13839769-4cfe-438b-9c5a-68b309040c54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Change help_text of a field in a derived model

2014-06-03 Thread Vladimir Chukharev
Hm... I fought with indentations in Opera in vain. Everything is lost, 
though at the time of sending it it looked fine. Try again, with FF.

#models.py:
from django.utils.html import format_html
import django.db.models.options as options

options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('help_texts',)

class Fact(models.Model):
"Model with plain text"
name = models.TextField(help_text="Simple text, it will be escaped in 
html")

def __unicode__(self):
return self.name

class ReST(Fact):
"""Derived model with ReStructured Text
This model needs different self.name.help_text, but assigning to it in 
__init__ is not possible (self.name is None when __init__ is running)
"""

def __unicode__(self):
return format_html(rest_to_html(self.name))

class Meta:
help_texts = {'name': 'You can use ReST formating here.'}

#views.py:
class BaseCreateView(CreateView):
def get_form_class(self):
model = class_by_name(self.kwargs['fmname'])
opts = model._meta
if hasattr(opts, 'help_texts'):
for fl in opts.concrete_fields:
if fl.name in opts.help_txt:
fl.help_text = opts.help_txt[fl.name]
form = model_forms.modelform_factory(model)
return form

-- 
You received this message because you are subscribed to the Google Groups 
"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/ae04dd92-3e76-49cd-a7d7-562753835a42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django-loses-currently-logged-in-user

2014-06-03 Thread 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/387973ea-a654-42e5-bf23-7d492332c129%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Startproject opens django-admin.py

2014-06-03 Thread Guðmundur H . Bjarnason
I forgot - One also needs to delete the path in django-admin.py, since you 
automatically provide that when you cd into your desired startproject 
directory.

-- 
You received this message because you are subscribed to the Google Groups 
"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/b2e53fa3-ff74-4277-8961-8c7d22e2e279%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Startproject opens django-admin.py

2014-06-03 Thread Guðmundur H . Bjarnason
Thanks for the reply Ilya. The problem was that the old, default Python 
directory was still the default, so django searched there for 
django-admin.py. Doing this manually by moving django-admin.py into the 
desired startproject folder and adding "python" in front of django-admin.py 
startproject mysite solved the problem. It's just that both django-admin.py 
and django-admin.pyc need to be in the startproject parent folder.

-- 
You received this message because you are subscribed to the Google Groups 
"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/c344044a-5d72-4696-9973-6f8aaab7d280%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Startproject opens django-admin.py

2014-06-03 Thread Ilya Kazakevich
Hello,

Shebangs are not supported by windows command processor (cmd).

Try: 
C:\Python27\python.exe django-admin.py


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 Gu?mundur H. Bjarnason
>Sent: Tuesday, June 03, 2014 3:34 PM
>To: django-users@googlegroups.com
>Subject: Startproject opens django-admin.py
>
>And something's fishy. No project directory is created. The command I use is
>
>django-admin.py startproject mysite
>
>Instead, it just opens django-admin.py! Which contains the following:
>
>#!C:\Python27\python.exe
>from django.core import management
>
>if __name__ == "__main__":
>management.execute_from_command_line()
>
>I have no idea what's wrong. Please help.
>
>
>--
>You received this message because you are subscribed to the Google Groups
>"Django users" group.
>To unsubscribe from this group and stop receiving emails from it, send an 
>email to
>django-users+unsubscr...@googlegroups.com.
>To 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/94673e5b-7b51-41f7-bbf1-385
>08ec1b1ae%40googlegroups.com
>508ec1b1ae%40googlegroups.com?utm_medium=email_source=footer> .
>For more options, visit https://groups.google.com/d/optout.


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


Re: Startproject opens django-admin.py

2014-06-03 Thread Guðmundur H . Bjarnason
I should note that Python is not installed as default in C:. It is in the 
user directory under Anaconda.

-- 
You received this message because you are subscribed to the Google Groups 
"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/9048e15a-b179-4b30-a076-7268b4effcb1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Startproject opens django-admin.py

2014-06-03 Thread Guðmundur H . Bjarnason
And something's fishy. No project directory is created. The command I use is

django-admin.py startproject mysite

Instead, it just opens django-admin.py! Which contains the following:

#!C:\Python27\python.exe
from django.core import management

if __name__ == "__main__":
management.execute_from_command_line()

I have no idea what's wrong. Please help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To 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/94673e5b-7b51-41f7-bbf1-38508ec1b1ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: InlineFormSet validation

2014-06-03 Thread César García Tapia
Ok, thanks to Russell's help in IRC I managed to solve this. Thank you so 
much!!




El lunes, 2 de junio de 2014 09:47:17 UTC+2, César García Tapia escribió:
>
> Hi, Russell, thanks for answering :-)
>
> Your answer helps me, but not completely. I can add the error with this:
>
> self._errors.append({'formula': self.error_class([msg])})  # 
> self._errors in a BaseInlineFormSet is a list of dictionaries, not a 
> dictionary, like you say.
>
> But I don't know how to reach the cleaned_data of the parent form. If I do 
> this:
>
> del self.cleaned_data['formula']
>
> It says that the parent form doesn't have a 'cleaned_data' attribute.
>
> So I can make the InlineFormSet validation fail, but I can't show the 
> error in my template.
>
> Any suggestion?
>
> Thank you!!
>
>
>
>
>
>
> El lunes, 2 de junio de 2014 02:26:56 UTC+2, Russell Keith-Magee escribió:
>>
>> Hi Cesar,
>>
>> It's all the documentation:
>>
>>
>> https://docs.djangoproject.com/en/dev/topics/forms/formsets/#custom-formset-validation
>>
>> You just have to raise a ValidationError(); Django will then add an error 
>> that spans the entire formset. 
>>
>> If you want to evaluate errors in clean(), but force the actual error to 
>> appear against a specific field, that's possible too - you just need to 
>> emulate what Django is doing behind the scenes. That means inserting the 
>> error into the error dictionary, and removing the error value from 
>> cleaned_data:
>>
>> self._errors['field name'] = self.error_class(['This field has a 
>> problems'])
>> del cleaned_data['field_name']
>>
>> You might need to do this if you won't know if a specific value is valid 
>> until you've checked all the individual values (e.g., A must be greater 
>> than B - you can't check that until you know both A and B exist, which 
>> won't be the case in the clean_A and clean_B methods)
>>
>> I hope that helps!
>>
>> Yours,
>> Russ Magee %-)
>>
>>
>>
>> On Sun, Jun 1, 2014 at 11:52 PM, César García Tapia  
>> wrote:
>>
>>> Hi. I already asked this question in StackOverflow, but I didn't get any 
>>> useful answer. Let's try here :-)
>>>
>>> I have a BaseInlineFormSet, and I'd like to validate a field in the 
>>> parent form based on the values on the fields of the children. As seen in 
>>> the docs, the only method to make a custom validation is clean(), but I 
>>> can't find a way to add errors to the parent form, only for the children.
>>>
>>> In the following code I build a formula. Each variable comes from a 
>>> inner form, and if the global formula don't validate, I'd like to add an 
>>> error to the parent's form field formula
>>>
>>> class CustomInlineFormSet(BaseInlineFormSet):
>>> def clean(self):
>>> formula = self.instance.formula
>>> variables = []
>>> for form in self.forms:
>>> if 'formula_variable' in form.cleaned_data:
>>> variables.append(form.cleaned_data['formula_variable'])
>>>
>>> valid, msg = validate_formula(formula, variables)
>>> if not valid:
>>> WHAT HERE???
>>>
>>> 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/87ce32a8-782e-4248-8b8c-046b6eef0904%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/d1150e33-20ca-4b83-863a-03730b24f961%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Change help_text of a field in a derived model

2014-06-03 Thread Vladimir Chukharev
Hi,
I a have a question about changing help_text in a model derived from 
another model. In my case, all of the models use the same form, generated 
from model.

Few classes share the same TextField. But the meaning of the field is 
different in different models. The following is a simplified version to 
illustrate the question, errors are probably added ;-).

#models.py:
from django.utils.html import format_html
import django.db.models.options as options

options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('help_texts',)

class Fact(models.Model):
"Model with plain text"
name = models.TextField(help_text="Simple text, it will be escaped in html")

def __unicode__(self):
return self.name

class ReST(Fact):
"""Derived model with ReStructured Text, it will be converted to html and 
marked safe.
This model needs a different self.name.help_text, but assigning to it in 
__init__ is not possible (self.name is None when __init__ is running)
"""
def __unicode__(self):
return format_html(rest_to_html(self.name))

class Meta:
help_texts = {'name': 'You can use ReST formating here.'}

#views.py:
class BaseCreateView(CreateView):
def get_form_class(self):
model = class_by_name(self.kwargs['fmname'])
opts = model._meta
if hasattr(opts, 'help_texts'):
for fl in opts.concrete_fields:
if fl.name in opts.help_txt:
fl.help_text = opts.help_txt[fl.name]
form = model_forms.modelform_factory(model)
return form


The above use of Meta results in a situation, that with one class more 
(derived from ReST), its help_text value depends on history of using forms 
for ReST and Fact...

My question: is there a way to change help_text of a model field defined in 
a parent class from within a derived model class?

-- 
You received this message because you are subscribed to the Google Groups 
"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/4e5607dc-d44c-4fe9-a450-fa3b738b3600%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


DB Router not working on production machine, works on dev.

2014-06-03 Thread Doug Ballance
I've got a weird one I just can't figure out.  I'd love some help while I'm 
still sane.   

On my development machine all is well.  On the other machine the database 
router seems to be getting the parent class (which is an abstract model in 
another app).  I determined this with some print statements on the 
router(s):

def db_for_read(self,model,**hints):
print model
print "router checked geo %s" % model._meta.app_label
if model._meta.app_label in self.GEOAPPS:
 print "routed geo"
 return 'geo'
return None


machine 1 (working):
In [1]: from glvar import models as gm
In [2]: gm.Listing.objects.count()

router checked geo glvar

router checked glvar glvar
routed glvar
Out[2]: 17373


Machine 2 (not working):
In [1]: from glvar import models as gm
In [2]: gm.Listing.objects.count()

router checked geo feedbase

router checked glvar feedbase
Out[2]: 0

The database is there and fine if I specify via using on machine2:
In [3]: gm.Listing.objects.using('glvar').count()
Out[3]: 25171

feedbase.models.Listing is the abstract base for glvar.models.Listing

The code is identical on both machines except for the settings.py file, 
confirmed by diff -qr on their respective directories.  I deleted all pyc 
files to make sure nothing funny was going on there.  The only differences 
there are in the name of the postgres user, and the library path for 
geos/gdal.  I updated both django versions to 1.6.5, so those are the same 
as well.  I'm not sure where I should begin tracking this down - 
suggestions?


(venv)[uidx@dev v3]$ diff app/app/settings.py prod/app/settings.py
49,50c49,50
< GEOS_LIBRARY_PATH = '/usr/lib/libgeos_c.so'
< GDAL_LIBRARY_PATH = '/usr/lib/libgdal.so'
---
> GEOS_LIBRARY_PATH = '/usr/lib64/libgeos_c.so'
> GDAL_LIBRARY_PATH = '/usr/lib64/libgdal.so'
142,143c142,143
< 'NAME': 'glvar',
< 'USER': 'uidx',
---
> 'NAME': 'glvar',
>   'USER': 'glvar',
148,150c148,150
< 'NAME': 'glvar_data',
< 'USER': 'uidx',
< 'PASSWORD': '',
---
> 'NAME': 'glvar_data',
> 'USER': 'glvar',
>   'PASSWORD': '',
239a240
>
243a245
>


-- 
You received this message because you are subscribed to the Google Groups 
"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/56dffe09-d271-42a9-82fe-0ade0afbbd04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.