Multi-level list (another ... I think)

2012-09-20 Thread refreegrata
Hello list
I have a question. I need to build a multi-level MultipleChoiceField. 
Something like this:
---

  

  Heavy Rain
  KOF XIII


  Halo 3

  
  

  Watchmen
  Swamp thing


  Spiderman

  

---
With just one level (1 optgroup) is easy, but optgroups inside other 
optgroups ... I don't know how.

I'm trying this: 

--
myChoices= (
('Videogames', (
('PS3', (
 ('1', 'Heavy Rain'),
 ('2', 'KOF XIII')
)),
('XBox', (
  ('3', 'Halo 3')
))
   ),
),
('Comics', (
('DC', (
('4', 'Watchmen'),
('5', 'Swamp thing')
)),
('Marvel', (
('6', 'Spiderman')
))
   )
)
   )

..
self.fields['myList'].choices= self.myChoices
--

But don't works

Somebody have an idea?

That's all. Bye

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/oQ5CNP_841cJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



check if an user is authenticated from another app

2012-09-14 Thread refreegrata
Hello list.

Obviously, I come here with a question. I have a web application developed 
with Django. It's working Ok. The app is just for internal use and the 
access to every view is only avaliable for authenticated users with 
permissions over the section (except for the view  log-in)

Now other app written over other framework, running over his own web server 
and port (node.js)  (but related with the django app)must to access at the 
same database to return certain information but it must to check if the 
user is authenticated. Here is my doubt, because Django manage the 
authentification ¿How can I check this in django and advise to the node.js 
app? Are any token in the database to check when an user is authenticated? 
How can I extract the user information from the request/session, delegate 
this to a function in django-python and get this information in the 
node.js? Maybe I must to build some web service in Django or program the 
token saving?

I'm a little lost. Sorry for this. Any idea?

Bye

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/1zNHOC1u-VIJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



url tag: "'str' object has no attribute 'regex'"

2012-05-17 Thread refreegrata
Hello list

I know, this question has been posted and resolved before, but the 
solutions don't work in my situation. I don't know why.

When I try to use the "url" tag in any template an exception is raised:
"'str' object has no attribute 'regex'"

for example, with this I got the error:

urls.py (main)
-
from django.conf.urls import patterns, include, url

urlpatterns= patterns('',
(r'^registration/', include('apps.registration.urls')),
(r'', 'django.contrib.auth.views.login'),
)
-

urls.py (registration)
-
from django.conf.urls import patterns, include, url

urlpatterns= patterns('',
(r'^login/$', 'django.contrib.auth.views.login'),
)
-

login.html (in templates/registration)
-
{{ form }}
{% url "django.contrib.auth.views.login" %} <---here is the problem. It's 
just an stupid test for the problem
-

Fail with:
 - {% url django.contrib.auth.views.login %}
 - {% url 'django.contrib.auth.views.login' %}
 - {% url "django.contrib.auth.views.login" %}

I add this at the end of the file "settings.py":
--
import django.template
django.template.add_to_builtins('django.templatetags.future')
--
Including or excluding the last lines doesn't matter. The problem appear in 
the both cases.

I'm using Django 1.4, and Python 2.6 over Centos 6.2. Maybe I must to 
include something else in the settings?

Thanks for read and sorry for my bad english.












-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/JoW317aiojgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django and unicode

2011-10-12 Thread refreegrata
For example in PostgreSQL, at least from the 8.3 version, you can't
have, in the same server, databases with differents encoding. But can
be defined a client_encoding for any database. With this you can have
a database with encoding='latin1' and client_encoding='utf8'. In
postgresql the client_encoding is a connection property to solve this
problems and avoid complications with weird characters.

However for any encoding just some client_encodings are valid. To
latin1 is valid a client_encoding=utf8 but isn't valid a
client_encoding=EUC_TW (traditional Chinese, Taiwanese). For that is
important read the PostgreSQL documentation.

Well, I don't know if you're using PostgreSQL. If you use another
DBMS, this answer isn't very useful.

I sorry if my english is too rough, but isn't my mother language.
Cheers.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Log file with errors

2011-09-23 Thread refreegrata
Hello list. I have a question. To my could be really helpful write a
"log file" with the errors, to revise at the next day if something
happen. For the moment I have this, a middleware class:
--
from django.conf import settings
import traceback
import sys
import logging

class TestMiddleware:
def getUser(self, request):
...

def process_exception(self, request, exception):
try:
tb = sys.exc_info()[2]
ubication = traceback.extract_tb(tb).pop()
message = u'Type: %s\nValor: %s\nFile, line, function: %s,
%s, %s\nUser: %s' % (type(exception).__name__,
exception.__unicode__(), ubication[0], ubication[1], ubicacion[2],
self.getUser(request))

logging.basicConfig(filename = settings.LOG_FILE,
filemode = 'a', format='Nivel: %(levelname)s\nDate-hour: %(asctime)s\n
%(message)s\n', level=logging.ERROR)
logging.error(message)
except:
pass
return None

--
But something is missing. I only catch exceptions thrown from views. I
can't catch FATAL errors like problems in the connection with the
database. Errors like that don't go to this code.
Somebody have an idea to capture that exceptions, maybe in another
function?

Cheers , Thanks for read and sorry for my bad english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: apache+mod_wsgi, redirect to https

2011-05-31 Thread refreegrata
Thanks men, I did this:
--

  
   ...
   ...
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  
...


Works ok to me. Now I must to test the "Require Auth".
Bye.


On 31 mayo, 13:33, Michael Scovetta 
wrote:
> I usually set up two virtual hosts, one listening on port 80 and the other
> on 443. The virtual host listening on port 80 just redirects to the other
> one:
>
> 
>     ServerAdmin ad...@example.com
>     ServerName domain.com
>
>     HostnameLookups Off
>     UseCanonicalName On
>     ServerSignature Off
>
>     Redirect /https://domain.com/
> 
>
> 
>     SSLEngine on
>
>     ServerAdmin ad...@example.com
>     ServerName domain.com
>
>     HostnameLookups Off
>     UseCanonicalName On
>     ServerSignature Off
>
>     WSGIScriptAlias / /opt/apache/wsgi_start.py
>     WSGIPassAuthorization On
>     ...
> 
>
> I haven't tried it, but would think that you could use mod_rewrite along
> with mod_wsgi, but it's possible that WSGI gets called first automagically.
>
> Hope this helps!
>
> Mike

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



apache+mod_wsgi, redirect to https

2011-05-31 Thread refreegrata
Hello guys and girls. I have a question. In my apache configuration I
have this:

WSGIScriptAlias /misite "rute_to_file.wsgi"

The users can access from:

http://mysite/
and
https://mysite/

I need to enable the access only from "https://mysite/";. Every access
from "http://mysite/"; must to be redirected to "https://mysite/";. How
can i do this?

Normally I use mod_rewrite, and thats works fine for the static files,
php, etc, but I don't have idea how do this with mod_wsgi.

Additionaly, can be very helpful if somebody now how configure an
"Require Auth" with mod_wsgi.

Sometime ago somebody asked the same in stackoverflow, without get
answers.

Thanks for read, and sorry for my poor english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: create a database

2011-05-18 Thread refreegrata
ok, thanks i forget that the settings.py is just a python script.

On 18 mayo, 11:02, Shawn Milochik  wrote:
> Sure, you can do this.
>
> Just write a Python script that imports settings (it should be on your
> PYTHONPATH) and read the database config info, and do your thing. The
> Django settings file is just a Python script, and all the settings in it
> are just Python objects (dictionaries, tuples, etc.)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



create a database

2011-05-18 Thread refreegrata
hello list. I have a question. With "python manage.py syncdb" the
tables are created in a database. Is possible use the configuration
declarated in the settings.py to create the database if this not
exists and make a script with lines like :

#---SCRIPT--
if not exists database:
create database
python manage.py syncb
#-

???

thanks for read.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: framework web comparison

2011-04-08 Thread refreegrata
thanks for the answers.

On 8 abr, 03:52, Xavier Ordoquy  wrote:
>
> Isn't Ruby a language ?


Ok, my mistake, I want to say Ruby on Rails (typing error).

Bye.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



framework web comparison

2011-04-07 Thread refreegrata
Hello list. I must to do a document to compare the most populars web
frameworks (Django, Ruby, Zend, ...), in terms like performance,
utilities, documentation, etc. For this document, the opinions of this
list would be helpful.

for example, for you, Why I must to choose Django instead of Ruby or
Zend? or something like this.

Any opinion can be helpful.

Thanks for read, and sorry for my poor english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: unittest problems

2011-02-24 Thread refreegrata
I add this to my settings:
---
TEMPLATE_CONTEXT_PROCESSORS = (
   .
'django.contrib.messages.context_processors.messages',
<- new line
)

I don't know the utility of this but now I only have 3 errors

---
==
ERROR: test_password_change_fails_with_invalid_old_password
(django.contrib.auth.tests.views.ChangePasswordTest)
--
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
tests/views.py", line 147, in
test_password_change_fails_with_invalid_old_password
'new_password2': 'password1',
  File "/usr/local/lib/python2.6/dist-packages/django/test/client.py",
line 322, in post
response = self.request(**r)
  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/
base.py", line 100, in get_response
response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/
decorators.py", line 76, in _wrapped_view
response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
decorators.py", line 25, in _wrapped_view
return view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
views.py", line 187, in password_change
}, context_instance=RequestContext(request))
  File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/
__init__.py", line 20, in render_to_response
return HttpResponse(loader.render_to_string(*args, **kwargs),
**httpresponse_kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py", line 181, in render_to_string
t = get_template(template_name)
  File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py", line 157, in get_template
template, origin = find_template(template_name)
  File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py", line 138, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist: registration/password_change_form.html

==
ERROR: test_password_change_fails_with_mismatched_passwords
(django.contrib.auth.tests.views.ChangePasswordTest)
--
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
tests/views.py", line 158, in
test_password_change_fails_with_mismatched_passwords
'new_password2': 'donuts',
  File "/usr/local/lib/python2.6/dist-packages/django/test/client.py",
line 322, in post
response = self.request(**r)
  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/
base.py", line 100, in get_response
response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/
decorators.py", line 76, in _wrapped_view
response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
decorators.py", line 25, in _wrapped_view
return view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
views.py", line 187, in password_change
}, context_instance=RequestContext(request))
  File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/
__init__.py", line 20, in render_to_response
return HttpResponse(loader.render_to_string(*args, **kwargs),
**httpresponse_kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py", line 181, in render_to_string
t = get_template(template_name)
  File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py", line 157, in get_template
template, origin = find_template(template_name)
  File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py", line 138, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist: registration/password_change_form.html

==
ERROR: Logout without next_page option renders the default template
--
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
tests/views.py", line 247, in test_logout_default
response = self.client.get('/logout/')
  File "/usr/local/lib/python2.6/dist-packages/django/test/client.py",
line 290, in get
response = self.request(**r)
  File "/usr/local/lib/python2.6/dist-packages/django/test/client.py",
line 230, in request
response = self.handler(environ)
  File "/us

Re: unittest problems

2011-02-23 Thread refreegrata
Yeahh , I already try this. The number of errors decreases, but I
still have some errors (15)
-
==
ERROR: test_password_change_fails_with_invalid_old_password
(django.contrib.auth.tests.views.ChangePasswordTest)
--
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
tests/views.py", line 147, in
test_password_change_fails_with_invalid_old_password
'new_password2': 'password1',
  File "/usr/local/lib/python2.6/dist-packages/django/test/client.py",
line 322, in post
response = self.request(**r)
  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/
base.py", line 100, in get_response
response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/
decorators.py", line 76, in _wrapped_view
response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
decorators.py", line 25, in _wrapped_view
return view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
views.py", line 187, in password_change
}, context_instance=RequestContext(request))
  File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/
__init__.py", line 20, in render_to_response
return HttpResponse(loader.render_to_string(*args, **kwargs),
**httpresponse_kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py", line 181, in render_to_string
t = get_template(template_name)
  File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py", line 157, in get_template
template, origin = find_template(template_name)
  File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py", line 138, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist: registration/password_change_form.html

==
ERROR: test_password_change_fails_with_mismatched_passwords
(django.contrib.auth.tests.views.ChangePasswordTest)
--
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
tests/views.py", line 158, in
test_password_change_fails_with_mismatched_passwords
'new_password2': 'donuts',
  File "/usr/local/lib/python2.6/dist-packages/django/test/client.py",
line 322, in post
response = self.request(**r)
  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/
base.py", line 100, in get_response
response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/
decorators.py", line 76, in _wrapped_view
response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
decorators.py", line 25, in _wrapped_view
return view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
views.py", line 187, in password_change
}, context_instance=RequestContext(request))
  File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/
__init__.py", line 20, in render_to_response
return HttpResponse(loader.render_to_string(*args, **kwargs),
**httpresponse_kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py", line 181, in render_to_string
t = get_template(template_name)
  File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py", line 157, in get_template
template, origin = find_template(template_name)
  File "/usr/local/lib/python2.6/dist-packages/django/template/
loader.py", line 138, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist: registration/password_change_form.html

==
ERROR: Logout without next_page option renders the default template
--
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
tests/views.py", line 247, in test_logout_default
response = self.client.get('/logout/')
  File "/usr/local/lib/python2.6/dist-packages/django/test/client.py",
line 290, in get
response = self.request(**r)
  File "/usr/local/lib/python2.6/dist-packages/django/test/client.py",
line 230, in request
response = self.handler(environ)
  File "/usr/local/lib/python2.6/dist-packages/django/test/client.py",
line 74, in __call__
response = self.get_response(request)
  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/
base.py", line 142, in get_response
return self.handle_uncaught_exception(request, resolver, exc_info)
  File "/usr/local/lib

Re: unittest problems

2011-02-23 Thread refreegrata
I don't know but maybe the problem is related with this:

I use Middleware class provided by Ryan Witt. Whit this class the user
must to be authenticated to view any page other than LOGIN_URL

Can be this a problem to run the tests?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



unittest problems

2011-02-23 Thread refreegrata
Hello list. I have a question. I've never done unit testing with
Django before. I still don't write any unittest but when I do this:

sudo. / manage.py test

Many errors appears. Errors related with the authentication. Errors
like:
==
FAIL: test_confirm_invalid
(django.contrib.auth.tests.views.PasswordResetTest)
--
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
tests/views.py", line 76, in test_confirm_invalid
url, path = self._test_confirm_start()
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
tests/views.py", line 60, in _test_confirm_start
self.assertEquals(len(mail.outbox), 1)
AssertionError: 0 != 1

==
FAIL: test_confirm_invalid_post
(django.contrib.auth.tests.views.PasswordResetTest)
--
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
tests/views.py", line 88, in test_confirm_invalid_post
url, path = self._test_confirm_start()
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
tests/views.py", line 60, in _test_confirm_start
self.assertEquals(len(mail.outbox), 1)
AssertionError: 0 != 1

==
FAIL: test_confirm_valid
(django.contrib.auth.tests.views.PasswordResetTest)
--
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
tests/views.py", line 69, in test_confirm_valid
url, path = self._test_confirm_start()
  File "/usr/local/lib/python2.6/dist-packages/djan

..


==
ERROR: test_last_login
(django.contrib.auth.tests.remote_user.RemoteUserNoCreateTest)
--
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
tests/remote_user.py", line 87, in test_last_login
self.assertNotEqual(default_login,
response.context['user'].last_login)
TypeError: 'NoneType' object is unsubscriptable

==

Some idea?. Another question. My database use something of sql .
Normally when I build the empty database, I insert this query :
'Create language plpgsql'. After  I do :python manage.py syncdb.

But in a test a new database is automatically created. How can I run a
test over an empty database but already created.

Thanks for read and sorry for my poor english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



gantt charts or timeline graphics

2011-02-15 Thread refreegrata
Hello list, I have a question. I need to generate some gantt chart or
time line image to represent every step of an element in a process. I
already have saved the history, but I need represent this in a
graphic. Somebody know some library to do something like this? The
idea is build the graphic in the server side, because I need display
the image in the html template and also must to be exportable to a
report PDF(reportlab).

Any suggestion be grateful.

Thanks for read, and sorry for my poor english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: filesizeformat in a view

2011-02-10 Thread refreegrata
thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



filesizeformat in a view

2011-02-10 Thread refreegrata
Hello list, I have a question. I want to assign the size of a file to
a var in the view, but the value must to be formated in a human-
readable file size. This is for a PDF report. In a template I can be
used the filter "filesizeformat", but Are some way to use that filter
in a view?

Thanks for read, and sorry for my poor english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



size of an image

2011-01-24 Thread refreegrata
hello list, I have a question. How can I get the width and the size of
an image previously saved?. This is , because I need to generate a
report with reportlab, and I must to resize the image, but I need the
original size to keep the scale.

Thanks and sorry for my bad english

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how can i define a decimal_separator and a thousand_separator

2010-12-29 Thread refreegrata
I still have the doubt.Does anyone know?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: manytomany and form

2010-12-24 Thread refreegrata
finally I do this

--
class form(forms.ModelForm):
fk_dcto = forms.ModelMultipleChoiceField(queryset= ,
required=False, widget=forms.CheckboxSelectMultiple)
--
with this I can save with checkboxselectmultiple.

To define a correctly order to the many to manyfields in the form
declaration I do this.

def clean_fk_dcto(self):
self.fk_dcto_copy = self.cleaned_data.get('fk_dcto')
return []

def save(self, *args, **kwargs):
newRow = super(Myform, self).save(*args, **kwargs)

for item in self.fk_dcto_copy:
item.fk_dcto.add(newRow)
item.save()
return oti



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: manytomany and form

2010-12-24 Thread refreegrata
to the first question, symmetrical=False, with this generate an
inverted information.
I want this.

id  | from_dcto_id | to_dcto_id
x   |old_dcto 1 |  new_dcto
x   |old_dcto 2 |  new_dcto

but I get this

id  | from_dcto_id | to_dcto_id
x   |new_dcto 1 |  old_dcto 1
x   |new_dcto 2 |  old_dcto 2


I need that every new dcto select his parents, to delimite the actions
over himself, not a parent defining his childs.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



manytomany and form

2010-12-24 Thread refreegrata
hello list. I have a model like this


class Dcto(models.Model):
..
fk_dcto = models.ManyToManyField('self', blank=True, null=True)

this create a this internal table with this fields

id
from_dcto_id
to_dcto_id


My problem appear when I save the formmodel. I want something like
this saved.

id  | from_dcto_id | to_dcto_id
x   |old_dcto 1 |  new_dcto
x   |old_dcto 2 |  new_dcto


but I get this


id  |  from_dcto_id  | to_dcto_id
x   | old_dcto 1  |  new_dcto
x   | old_dcto 2  |  new_dcto
x   | new_dcto   |  old_dcto 1
x   | new_dcto   |  old_dcto 2


Somebody know how can i solve this problem?
Another question. I prefer a CheckboxSelectMultiple(), no a
selectMultiple(), I can define this in the widget meta,

widgets = {
   'fk_dcto':forms.widgets.CheckboxSelectMultiple(),

but the user selection isn't saved.

Thanks for read, and sorry for my poor english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



template filter by foreignkey

2010-12-15 Thread refreegrata
Hello list. I have a question. Whit a model like this
--
class Ghi(models.model):
   dat = models.IntegerField(unique =True)

class Def(models.Model):
ghis = models.ForeignKeyField(Ghi)

class Abc(models.Model):
defs = models.ManyToManyField(Def)
--
And from my view I return something like
Abc.objects.all()

Are some way to ask in the template something like:
exists in Abc.defs.ghis.dat == 1?

thanks for read.
P.D.: Django 1.2.1

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Paginator and foreign key

2010-12-13 Thread refreegrata
thanks for the answer, but the solution don't show anything. I must be
doing something wrong.
if now I have
---
class Myline(models.mode):
   fk_myDoc = models.ForeignKey(MyDoc, related_name="")
---

How Can I use {% for line doc.X_set.all %} in the template?
I'm sorry for this asking, but I can't find the _set.all option in the
Django documentation.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Paginator and foreign key

2010-12-13 Thread refreegrata
if I return another list:
---
for i in range(len(paginatorDocs.object_list)):
resultados = {'myDoc': paginatorDocs.object_list[i],
  'myLines':
Myline.objects.filter(fk_myDoc=paginatorDocs.object_list[i].id),}

---
With this I can get the values, but I'm not sure if this is the best
way to solve the problem

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Paginator and foreign key

2010-12-13 Thread refreegrata
Hello list, I have a question. Take a look to the next models.

class MyDoc(models.Model):
code = models.BigIntegerField()

class Myline(models.mode):
   fk_myDoc = models.ForeignKey(MyDoc)
---

In my view I do something like

myPaginator = Paginator(MyDoc.objects.filter(codigo=1), 10)
myDocs = myPaginator.page(page_number)

This return all the Docs with a code=1, but I too want to return all
the objects with the type "MyLine" associated to the results of this
query.

I try to do something like

for i in range(len(myDocs.object_list))
myDocs.object_list[i].append(Myline.objects.filter(fk_myDoc=myDocs.object_list[i].id))
-
but don't work

I know that I can do 2 queries and return two list, one with the myDoc
list and other with the myLine list, but in that case in my template I
must to do something like

{% for myDoc im MyDocs.object.list %}
{% for myline in Mylines %}
   {%if myDoc.id == myline.fk_myDoc %}
   ..
   {% endif %}
{% endfor %}
{% endfor %}

I don't want to do this, because I think a big "for" inside a big
"for" is innecessary.

Somebody have an idea??
Thanks for read, and sorry for my bad english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how can I clean a form field before the clean method?

2010-12-04 Thread refreegrata
ok, thanks for the answer. I have a final question. The other way is
in the __init__ set initial values in hidden fields, but if the user
(malicious) edit the value in some of this fields the form is invalid,
and the form comeback, but with the values edited for the user and the
error messages. Can I reset the initial values for the hidden fields
before of return the form?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how can I clean a form field before the clean method?

2010-12-04 Thread refreegrata
Yes, you have reason. I prefer use something like an "exclude" or
"fields" tuple in the form meta, and set default values in the model
to the fields that I need, but some of the default values are foreign
keys.
I want to do something like:

.default = MyModel.objects.get(field=True)

and raise an exception if don't find in the table a row with a field =
True, but I don't have idea if something like this can be done.

Thanks for read and sorry for my newbies questions.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how can I clean a form field before the clean method?

2010-12-03 Thread refreegrata
Ok, with hidden fields. But if the user manually, with some tool,
change the value, thats will be a problem. For my safety I must to use
the hidden fields and still keep the clean methods to overwrite any
possible editing over the fields value. Originally the idea of this
post was search a way to prevent the double assign(in the init and the
clean methods), but apparently isn't possible.

Thanks for the answer.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



how can I clean a form field before the clean method?

2010-12-03 Thread refreegrata
Hello list, I want to do something like my_field = 1000(this value can
change depending of some situations, but the idea is a value injected
with Django, not with some data entered by the user in the HTML form.

I already try this:
-
def clean(self):
cleaned_data = self.cleaned_data
cleaned_data['my_field'] = 44
return cleaned_data
-
and this

def clean_my_field(self):
 return 44


but don't work, I think that the exception is launched before of the
summoning to any of this functions. How can I solve this situation?
The idea isn't do an edition in the view of the request.POST

Thanks for read, and sorry for my poor english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



how can i define a decimal_separator and a thousand_separator

2010-11-15 Thread refreegrata
Hello list, I have a question. How can i define a custom
decimal_separator and a custom thousand_separator independently of the
locale?. I don't want redefine this values to every "locale". To my
problem, in every the template must to display the same thousand
separator  and the decimal separator.

Thanks for read and sorry for my poor english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: clean method in a model

2010-11-09 Thread refreegrata
Thanks for answer. You have reason, I don't need do that. With a clean
method in the modelform is enough. This question appear, because
initialy I just wanted add a validator to the field of the model, but
for the validation the  parameter  "self" was necessary and I could
not find a way to pass this parameter. However I don't need this, with
a clean method in the form, I can solve this quickly.

On 9 nov, 13:44, cootetom  wrote:
> You say you want to do the clean in the model but then say you want
> the error to be associated with the field in the ModelForm? If you
> need that clean functionality to exist for both a model and a form of
> that model then you could shift the checks into a function of it's own
> out side of the class's then have a clean in both the model and the
> form which calls the function to do the checks before deciding how to
> raise the error.
>
> The issue is that a form and a model use validation errors in
> different ways. A form will send errors back to the templating layer
> to show to a user but a model doesn't work like that as it would only
> be manipulated directly in python code.
>
> Does that make sense?
>
> On Nov 9, 2:39 pm, refreegrata  wrote:
>
> > ok, thanks for the answer, but I want use the clean method in a model,
> > not in a form. For that in the clean method I throw a ValidationError,
> > but the error message isn't associated to the field form of the
> > modelform.
>
> > On 8 nov, 19:17, cootetom  wrote:
>
> > > If you want to associate an error to a specific field in a model form
> > > then you need to populate self._errors with the error you find. Have a
> > > read about this on the Django docs to see how it is done.
>
> > >http://docs.djangoproject.com/en/1.1/ref/forms/validation/#ref-forms-...
>
> > > The last example shows how to associate a error with a specific field
> > > in a form class.
>
> > > On Nov 8, 8:40 pm, refreegrata  wrote:
>
> > > > Hello list. I want to use the clean method in a model.
> > > > --
> > > > class myModel(models.Model):
> > > >     fields 
>
> > > >     def clean(self):
> > > >             raise ValidationError('The Error.')
> > > > ---
>
> > > > Thats works fine. My question  is, how can I associate this error to
> > > > the field in the modelform?. With this method the form validation can
> > > > be controlled, but I can't pick the error dynamically to show at the
> > > > user.
>
> > > > Thanks for read.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: clean method in a model

2010-11-09 Thread refreegrata
ok, thanks for the answer, but I want use the clean method in a model,
not in a form. For that in the clean method I throw a ValidationError,
but the error message isn't associated to the field form of the
modelform.

On 8 nov, 19:17, cootetom  wrote:
> If you want to associate an error to a specific field in a model form
> then you need to populate self._errors with the error you find. Have a
> read about this on the Django docs to see how it is done.
>
> http://docs.djangoproject.com/en/1.1/ref/forms/validation/#ref-forms-...
>
> The last example shows how to associate a error with a specific field
> in a form class.
>
> On Nov 8, 8:40 pm, refreegrata  wrote:
>
> > Hello list. I want to use the clean method in a model.
> > --
> > class myModel(models.Model):
> >     fields 
>
> >     def clean(self):
> >             raise ValidationError('The Error.')
> > ---
>
> > Thats works fine. My question  is, how can I associate this error to
> > the field in the modelform?. With this method the form validation can
> > be controlled, but I can't pick the error dynamically to show at the
> > user.
>
> > Thanks for read.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



clean method in a model

2010-11-08 Thread refreegrata
Hello list. I want to use the clean method in a model.
--
class myModel(models.Model):
fields 

def clean(self):
raise ValidationError('The Error.')
---

Thats works fine. My question  is, how can I associate this error to
the field in the modelform?. With this method the form validation can
be controlled, but I can't pick the error dynamically to show at the
user.

Thanks for read.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Change the initial data to a modelForm

2010-11-02 Thread refreegrata
This don't work to me. Now I must to use the "." like a thousand
separator and the "," like decimal separator (x.xxx,xx) (requirement
of the boss). I try to follow the guide to "custom format fields" in
the Django documentation, but I can't get formatted numbers.

I have this:

mysite/
formats/
__init__.py
es/
__init__.py
formats.py
--
And in my settings.py

USE_I18N = True
USE_L10N = True
FORMAT_MODULE_PATH = 'formats.es.formats'

Nothing more. Where is my error? The FORMAT_MODULE_PATH must to be
other? I must to declare the FORMAT_MODULE_PATH in other side? I must
to include some library in the view? This is the first time when I
work with localization.

Thanks for read.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Change the initial data to a modelForm

2010-11-02 Thread refreegrata
Thanks, you are the best

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Change the initial data to a modelForm

2010-11-02 Thread refreegrata
Hello list. I have a model "PP" with a "float" field "val" and a
modelform for this model

For update the data of a existent "PP" I use a form like this

Form_for_PP(request,POST, instance=instance)

Now my question is, Can I change the initial data  for the field
"val"?

I want to do this:

If the value in "val" is 12345.6, the resulting form must to have the
value "12.345,6" (the same value, but formatted)

I can't find the way to do this when I use an instance. Set an
"initial" don't  work, the returning value is always the existing in
the DB.

Somebody can help me?

Thanks for read, and sorry for my poor english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: change the default widget to a field in a modelform

2010-10-27 Thread refreegrata
If somebody know some way to save a Manytomany field (the
departments)  manually in the view and not with form.save() would be
helpful.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: change the default widget to a field in a modelform

2010-10-27 Thread refreegrata
Yes, I know that, this is strange. My models.
--
Table 1: Enterprise
Table 2: Department with : fk_enterprise =
models.ForeignKey(Enterprise)
Table 3: Item with: fk_departament =
models.ManyToManyField(Departament) 

Re: change the default widget to a field in a modelform

2010-10-26 Thread refreegrata
maybe I not explain correctly. For any modelForm the forms for a field
"ManytoMany"  are "select multiple". If I want to change this I must
to redefine the widget for that field in the declaration of the
"modelForm". This works correctly, I can transform the field from
"select multiple" to any "form" that I want. The problem appear when I
want to save the "form". Always the "form" is invalid because the
field type isn't a "select multiple". With a "select multiple" the
form can be saved, with other field types fail. Somebody have an idea?
Something that i can do in the view? Any opinion  can be helpful.

Thank for read

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: nl2br or equivalent to django

2010-10-26 Thread refreegrata
Thanks, is clearly explained in the documentation. I feel embarrassed
for do a post for something like this.

On 26 oct, 13:25, Daniel Roseman  wrote:
> On Oct 26, 5:02 pm, refreegrata  wrote:
>
> > Hello list, I have a newie question, are in django some function like
> > nl2br in the template to print data saved previously from a
> > "textarea"? because in my template all the lines are printed in the
> > same line.
>
> > P.D.: nl2br is PHP function to do this:
>
> > "a
> > b
> > c"
>
> > is tranformed in
> > "abc"
>
> > Thanks for read, and sorry for my poor english
>
> http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#linebreaks
> andhttp://docs.djangoproject.com/en/1.2/ref/templates/builtins/#linebrea...
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



nl2br or equivalent to django

2010-10-26 Thread refreegrata
Hello list, I have a newie question, are in django some function like
nl2br in the template to print data saved previously from a
"textarea"? because in my template all the lines are printed in the
same line.

P.D.: nl2br is PHP function to do this:

"a
b
c"

is tranformed in
"abc"

Thanks for read, and sorry for my poor english

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



change the default widget to a field in a modelform

2010-10-19 Thread refreegrata
Hello list. I have a model with a ManyToMany field.

For example:

--
class Table(models.Model):
   myField = models.ManyToManyField(OtherTable)
--

The modelForm returns a "selectMulttiple" for the field "myField", but
I need a normal "select". Finally the modelForm is something like
this:
--
class MyForm(forms.ModelForm):
class Meta:
model = Table
widgets = {
'myField': forms.Select()
}
--
This return a form with the normal "select" field.

The problem appear when a want to save the model. I can't save because
the form is invalid. Django say " Introduce a value list". Somebody
have an idea to solve this problem?

If I use a selectMultiple the form is valid and I can save the data.

Thanks for read and sorry for my poor english.

Thanks for read and sorry for my poor english.

P.D. I use Django 1.2.1

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: MaxValueValidator to validate a model

2010-10-15 Thread refreegrata
Now works.
validators=[MaxValueValidator(Decimal('14.5'))

But I must to do an explicit declaration Decimal('14.5').

Somebody knows why?


On 15 oct, 18:13, refreegrata  wrote:
> Hello list. I want to validate the data in a field of a model.
>
> with this
> validators=[MaxValueValidator(14)]
> the field is correctly validated
>
> but with this
> validators=[MaxValueValidator(14.5)]
> always is invalid
>
> Somebody know how use the "MaxValueValidator" when the "max_value" is
> a decimal?
>
> thanks for read.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



MaxValueValidator to validate a model

2010-10-15 Thread refreegrata
Hello list. I want to validate the data in a field of a model.

with this
validators=[MaxValueValidator(14)]
the field is correctly validated

but with this
validators=[MaxValueValidator(14.5)]
always is invalid

Somebody know how use the "MaxValueValidator" when the "max_value" is
a decimal?

thanks for read.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: fields in inner join

2010-10-15 Thread refreegrata
ok, thank for reply.

I think that with this query:

" AA.object.filter(...).select_related( field related in BB ) "

The impact in the performance is minimun

But with this query

" AA.object.filter(...).select_related() "

the impact is higher, because the first query do an unique "join", but
the second "join" can do multiple "join"s and I just need the AA
fields and the BB fields.

Is this idea correct?

On 15 oct, 12:27, Daniel Roseman  wrote:
> On Oct 15, 4:19 pm, refreegrata  wrote:
>
>
>
> > Hello, how can i get fields from different tables related for a
> > foreign key?
>
> > When I do a inner join like
>
> > AA.objects.filter(bb__field = ...) ...
>
> > I just can access to the AA fields, and not to fields in the other
> > table
>
> > in a normal query i can do something like "select AA.*, BB.* FROM. AA
> > inner join BB..."
> > but in django the resultant query is "select AA.* FROM. AA inner join
> > BB..."
>
> > Now i use select_related for solve this problem isn't recommended ,
> > because this query has an impact in the server performance. How i can
> > solve this?
>
> > Thanks for read, and sorry for my poor english.
>
> select_related *is* the answer to this question. Of cours all joins
> have an impact on server performance, because you're asking the
> database to do more work, but this is likely to be very very small,
> and there isn't a way of doing what you want without some form of
> join.
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



fields in inner join

2010-10-15 Thread refreegrata
Hello, how can i get fields from different tables related for a
foreign key?

When I do a inner join like

AA.objects.filter(bb__field = ...) ...

I just can access to the AA fields, and not to fields in the other
table

in a normal query i can do something like "select AA.*, BB.* FROM. AA
inner join BB..."
but in django the resultant query is "select AA.* FROM. AA inner join
BB..."

Now i use select_related for solve this problem isn't recommended ,
because this query has an impact in the server performance. How i can
solve this?

Thanks for read, and sorry for my poor english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: mtv pattern(diagram)

2010-10-13 Thread refreegrata
Or:

request
 |
 |
V
internal controller(urls.py)
|
|
   V

||
|   views |<-->model
|___|<--->template
   |
   |
  V
response

is this diagram most specific? have any error?(this post is only
because i need put a diagram in a document

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: mtv pattern(diagram)

2010-10-13 Thread refreegrata
I have some questions.

difference between : views in mtv and controllers in mvc,
difference between : templates in mtv and views in mvc,

I read the documentation for Django, but still not clear to me.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



mtv pattern(diagram)

2010-10-13 Thread refreegrata
Hello i want to do a diagram to explain de mtv pattern. Any idea?

for explain the mvc I can do something like:


request--->controller->model->view->response
   | ^
   |-|

but  i don't know how draw the mtv pattern in a diagram. I need the
diagram for a document,

Thanks for read and sorry for my bad english

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: inner join and only method

2010-10-06 Thread refreegrata
starting from Abc works with "select_related"

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: inner join and only method

2010-10-06 Thread refreegrata
that don't work. The query can find the "User" fields.

On 6 oct, 05:43, Daniel Roseman  wrote:
> On Oct 6, 2:44 am, refreegrata  wrote:
>
>
>
> > Hello list. I'm have a questio. if I have an "inner join" query an use
> > an "only" restriction, how can i put a field of the second table in
> > the "only" tuple?
>
> > Example:
>
> > Model
> > -
> > class Abc(models.Model):
> >     fk_user = models.ForeignKey(User, related_name='user_pp')
> >     fk_ee = models.ForeignKey(Dd, related_name='dd_dd')
> >     ccc = models.BooleanField(default=False)
>
> > And my query
>
> > User.objects.filter(user_pp__fk_departamento='aa'].id).only('username')
>
> > But i want to do something like
>
> > User.objects.filter(user_pp__fk_departamento='aa'].id).only('username',
> > 'ccc')
> > or
> > User.objects.filter(user_pp__fk_departamento='aa'].id).only('username',
> > 'user_pp__ccc')
> > but that's don't work. How i can put the ccc field inside the 'only'
> > tuple.
>
> > Thanks for read,a and sorry for my poor english.
>
> Try it the other way round - starting from Abc.
>
>     Abc.objects.filter(fk_departamento='aa').only('fk_user__username',
> 'ccc')
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



inner join and only method

2010-10-05 Thread refreegrata
Hello list. I'm have a questio. if I have an "inner join" query an use
an "only" restriction, how can i put a field of the second table in
the "only" tuple?

Example:

Model
-
class Abc(models.Model):
fk_user = models.ForeignKey(User, related_name='user_pp')
fk_ee = models.ForeignKey(Dd, related_name='dd_dd')
ccc = models.BooleanField(default=False)

And my query

User.objects.filter(user_pp__fk_departamento='aa'].id).only('username')

But i want to do something like

User.objects.filter(user_pp__fk_departamento='aa'].id).only('username',
'ccc')
or
User.objects.filter(user_pp__fk_departamento='aa'].id).only('username',
'user_pp__ccc')
but that's don't work. How i can put the ccc field inside the 'only'
tuple.

Thanks for read,a and sorry for my poor english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: query with "join"

2010-09-08 Thread refreegrata
> EE.filter(dd__ppdd__user=2).distinct()

it work. The problem was mine. I must to put in the query the
"related_name" not the model name.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: query with "join"

2010-09-08 Thread refreegrata
with something like this:

my_query = PPDD.objects.select_related('dd__ee').filter(user=2)

can works,but i need do a distinct clause over the rows of "ee" , How
can I do that?
DD.objects.select_related('dd__ee').filter(user=2).distinct() don't
works, because this query pick all the columns,if i can get only the
columns of EE , the distinct clause can works, but I don't know how i
can a do this.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: query with "join"

2010-09-08 Thread refreegrata
with that query I got an error: "Cannot resolve keyword 'dd' into
field. Choices (the EE model fields)", because "EE" don't have a
foreign key to "DD", DD have an foreign key to "EE".
With "PPDD.objects.select_related().filter(user=2)" works, but that's
not the idea, because the query can grow up and  in production can be
slow.

My idea is do a subquery like
"DD.objects.filter(id__in=(PPDD.objects.filter(user=2)))" but that's
not works because this is transformed in a query like this:

SELECT ... FROM "DD" WHERE "DD"."id" IN (SELECT U0."id" FROM "PPDD" U0
WHERE U0."user_id" = 2)
and i new something like this:
SELECT ... FROM "DD" WHERE "DD"."id" IN (SELECT U0."departamento_id"
FROM "PPDD" U0 WHERE U0."user_id" = 2)

the problem is SELECT U0."id". For my requeriments must to be SELECT
U0."departamento_id"

And other question. In this query
"EE.objects.filter(dd__ppdd__user=2)"  how can I put the
"related_name" when in a model are more than 1 foreign key to the same
model?

On 8 sep, 11:00, Daniel Roseman  wrote:
> On Sep 8, 3:25 pm, refreegrata  wrote:
>
>
>
> > Hello list, I have question. With this model:
> > -
> > 1) class EE(Persona):
> >     .
> > 2) class DD(models.Model):
> >     ee_id = models.ForeignKey(EE)
>
> > 3) The User table
>
> > 4) class PPDD(models.Model):
> >       user_id = models.ForeignKey(User)
> >       dd_id = models.ForeignKey(DD)
> >       .
> > 
>
> > How can I do (without RawSQL) a query like this?:
>
> > select distinct EE.* from EE inner join
> > (
> >       select DD.* from DD inner join PPDD on (DD.id=PPDD.dd_id and
> > PPDD.user_id=2)
> >  ) as my_filter
> >  on (EE.id=my_filter.ee_id)
>
> > I want to get the data in the table EE that's associated to PPDD
> > through DD. I read the django documentation, but I can't understand
> > how do the query.
>
> > Thanks for read, and sorry for my poor english.
>
> Firstly, don't call your foreignkey fields "foo_id". Django
> automatically creates an underlying database field with the "_id"
> suffix, but the ForeignKey field on the model refers to the linked
> model instance itself, not the id.
>
> Anyway, assuming you've changed those names, the query is:
>
>   EE.objects.filter(dd__ppdd__user=2)
>
> The double-underscore syntax is used for crossing joins.
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



query with "join"

2010-09-08 Thread refreegrata
Hello list, I have question. With this model:
-
1) class EE(Persona):
.
2) class DD(models.Model):
ee_id = models.ForeignKey(EE)

3) The User table

4) class PPDD(models.Model):
  user_id = models.ForeignKey(User)
  dd_id = models.ForeignKey(DD)
  .


How can I do (without RawSQL) a query like this?:

select distinct EE.* from EE inner join
(
  select DD.* from DD inner join PPDD on (DD.id=PPDD.dd_id and
PPDD.user_id=2)
 ) as my_filter
 on (EE.id=my_filter.ee_id)

I want to get the data in the table EE that's associated to PPDD
through DD. I read the django documentation, but I can't understand
how do the query.

Thanks for read, and sorry for my poor english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: urlencode in Django

2010-09-01 Thread refreegrata
just a few moments ago i saw this in the django documentation. Now
works fine. Thanks.

On 1 sep, 12:10, Tom Evans  wrote:
> On Mon, Aug 30, 2010 at 10:45 PM, refreegrata  wrote:
> > now works for all characters. I don't  know why, but now finally
> > works. ñ is converted to "%C3%B1", ó is converted to "%C3%B3", + to
> > "%2B", ...
>
> > thanks.
>
> > P.D.: I hate use special characters in an url, generaly is a bad idea,
> > but is necessary in my application.
> > The client want to filter registers according the  name, and the name
> > can have special characters, and i must to paginate the results. The
> > other option is use a ghost form and javascript.
>
> > Thanks.
>
> The url resolver takes care of all of this magic for you. If you find
> it isn't, then you aren't using it right. For instance:
>
> link
>
> This is clearly an incorrect use of a url pattern. Instead, the var
> argument should be included as part of the urlpattern, and var given
> as an argument to the url template tag.
>
> link
>
> Do it like this, and you won't have problems. If you need to generate
> a query string, use the pattern as described by Alexandre González in
> the first reply.
>
> Cheers
>
> Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django 1.2 modelformset_factory fails with meta: widgets

2010-09-01 Thread refreegrata
rewrite the __init__., redefining the form element in this place. The
error must to dissapear.

class FormMyForm(ModelForm):
def __init__(self, *args, **kwargs):
super(FormMyForm, self).__init__(*args, **kwargs)
self.fields[''] =
forms.CharField(widget=forms.TextInput(attrs={.}))

class Meta:
model = Model
fields = ['']

On 1 sep, 12:01, Jason  wrote:
> Thanks! I'll give that a try.
>
> On Aug 13, 8:55 am, Matthew R  wrote:
>
> > I got hit by this same bug and here's the workaround I used, for
> > future reference. Basically you need to specify a formfield_callback
> > kwarg to modelformset_factory that just passes along any kwargs it
> > receives (namely, in this case, the 'widget' argument) to
> > Field.formfield():
>
> > def create_formfield(f, **kwargs):
> >     return f.formfield(**kwargs)
>
> > ArticleFormSet = modelformset_factory(Article,
> >   form = ArticleForm,
> >   formfield_callback=create_formfield,
> >   extra=0)
>
> > On Jul 29, 11:33 am, Jason  wrote:
>
> > > Can anyone confirm that passing in a form withMeta.widgets set to
> > > modelformset_factory() does in fact work?
>
> > > I've tried stripping my code down to the basics and still get the same
> > > exception. Debugging Django code doesn't help me because it fails
> > > during a lamda function that I don't quite understand.
>
> > > If anyone else has this problem I'll go ahead and submit a bug report.
>
> > > On Jul 28, 12:50 pm, Jason  wrote:
>
> > > > Traceback:
> > > > File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
> > > > get_response
> > > >   100.                     response = callback(request,
> > > > *callback_args, **callback_kwargs)
> > > > File "C:\Documents and Settings\goodrich\PycharmProjects\CCC\Aggregator
> > > > \newsmail\views.py" in manage_articles
> > > >   174.                                           form = ArticleForm)
> > > > File "C:\Python25\lib\site-packages\django\forms\models.py" in
> > > > modelformset_factory
> > > >   669.
> > > > formfield_callback=formfield_callback)
> > > > File "C:\Python25\lib\site-packages\django\forms\models.py" in
> > > > modelform_factory
> > > >   407.     return ModelFormMetaclass(class_name, (form,),
> > > > form_class_attrs)
> > > > File "C:\Python25\lib\site-packages\django\forms\models.py" in __new__
> > > >   220.                                       opts.exclude,
> > > > opts.widgets, formfield_callback)
> > > > File "C:\Python25\lib\site-packages\django\forms\models.py" in
> > > > fields_for_model
> > > >   178.         formfield = formfield_callback(f, **kwargs)
>
> > > > Exception Type: TypeError at /newsmail/manage/
> > > > Exception Value: () got an unexpected keyword argument
> > > > 'widget'
>
> > > > On Jul 28, 12:00 pm, Daniel Roseman  wrote:
>
> > > > > On Jul 28, 7:08 pm, Jason  wrote:
>
> > > > > > For example:
>
> > > > > > class ArticleForm(ModelForm):
> > > > > >     classMeta:
> > > > > >         model = Article
> > > > > >         widgets = {
> > > > > >              'pub_date': SplitSelectDateTimeWidget(),
> > > > > >              'expire_date': CalendarWidget(attrs={'class':'date-
> > > > > > pick'})
> > > > > >         }
>
> > > > > > And in a view function:
> > > > > > ...
> > > > > >     ArticleFormSet = modelformset_factory(Article,
> > > > > >                                           form = ArticleForm,
> > > > > >                                           extra=0)
> > > > > > ...
>
> > > > > > Removing 'widgets' from theMetain ArticleForm fixes the error.
>
> > > > > > The new widgets convention here is really handy. I don't want to 
> > > > > > lose
> > > > > > it!
>
> > > > > > Any tips?
>
> > > > > How does it fail? What error do you get? If there's a traceback,
> > > > > please post it here.
> > > > > --
> > > > > DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: urlencode in Django

2010-08-30 Thread refreegrata
now works for all characters. I don't  know why, but now finally
works. ñ is converted to "%C3%B1", ó is converted to "%C3%B3", + to
"%2B", ...

thanks.

P.D.: I hate use special characters in an url, generaly is a bad idea,
but is necessary in my application.
The client want to filter registers according the  name, and the name
can have special characters, and i must to paginate the results. The
other option is use a ghost form and javascript.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: urlencode in Django

2010-08-30 Thread refreegrata
i know how configure my urls.py is ok, with regular expression. but i
must do something like

link

Now works. In the browser url the character "ñ" is not converted to
"%C3%B1", but the character "+" is converted to "%2B". maybe i have
some problems with the theory. Maybe the character "ñ" isn't a
problem, and for this reason is not converted.

Thanks for read.

On 30 ago, 17:13, Alexandre González  wrote:
> With django you can define you url in urls.py as:
>
> url(r'^sample$', sample, name='the_name'),
>
> and then in your template use: {% url the_name %}
>
> If it need a id or similar you can provide it with {% url the_name ID %}
>
>
>
> On Mon, Aug 30, 2010 at 23:08, refreegrata  wrote:
> > for the moment i don´t have a problem, the section of my site work's
> > fine. Maybe is just a PHP habit.
>
> > In php when a wont to build an url in the template  i do somethin like
> > 
> > 
> > echo 'http://mysite.php?aaa='.urlencode($aaa).'>link';
> > --
> > because $aaa can have some special characters.
>
> > I thought that the urlencode filter do this in django. I must to build
> > an url in the template with parameters for a filtered pagination.
>
> > On 30 ago, 16:44, Alexandre González  wrote:
> > > Why do you like to do it?
>
> > > I think that your problem is with codification, and not with
> > urlenconde...
> > > try to search about utf8 and html
>
> > > On Mon, Aug 30, 2010 at 22:09, refreegrata 
> > wrote:
> > > > i'm sorry in my last time  accidentally send the post before of
> > > > finish.
> > > > I try to do in the template something like
> > > > {{ my_var|urlencode }}
> > > > but  don't work. Can i do something like an urlencode in the template?
>
> > > > P.D.: I'm from Chile.
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Django users" group.
> > > > To post to this group, send email to django-us...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > django-users+unsubscr...@googlegroups.com
> > 
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/django-users?hl=en.
>
> > > --
> > > Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx,
> > .ppt
> > > and/or .pptx
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
> and/or .pptx

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: urlencode in Django

2010-08-30 Thread refreegrata
for the moment i don´t have a problem, the section of my site work's
fine. Maybe is just a PHP habit.

In php when a wont to build an url in the template  i do somethin like


echo 'http://mysite.php?aaa='.urlencode($aaa).'>link';
--
because $aaa can have some special characters.

I thought that the urlencode filter do this in django. I must to build
an url in the template with parameters for a filtered pagination.

On 30 ago, 16:44, Alexandre González  wrote:
> Why do you like to do it?
>
> I think that your problem is with codification, and not with urlenconde...
> try to search about utf8 and html
>
>
>
> On Mon, Aug 30, 2010 at 22:09, refreegrata  wrote:
> > i'm sorry in my last time  accidentally send the post before of
> > finish.
> > I try to do in the template something like
> > {{ my_var|urlencode }}
> > but  don't work. Can i do something like an urlencode in the template?
>
> > P.D.: I'm from Chile.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
> and/or .pptx

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: urlencode in Django

2010-08-30 Thread refreegrata
i'm sorry in my last time  accidentally send the post before of
finish.
I try to do in the template something like
{{ my_var|urlencode }}
but  don't work. Can i do something like an urlencode in the template?

P.D.: I'm from Chile.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



urlencode in Django

2010-08-30 Thread refreegrata
Hello lista, I'm a newbie in django. In php i have the  urlencode
function for encoding an url with characters "+","ñ","ó",  Has
Django an urlencode or similar function?

Thanks for read, and sorry my bad english

P.D.: django 1,2.1

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: convert textinput in label or text for a modelform and modelformset_factory

2010-08-16 Thread refreegrata
{{ form.instance.field of the model }}

is a way to access.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: convert textinput in label or text for a modelform and modelformset_factory

2010-08-16 Thread refreegrata
somebody have an idea ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: convert textinput in label or text for a modelform and modelformset_factory

2010-08-13 Thread refreegrata
the idea isn't depend of javascript.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: convert textinput in label or text for a modelform and modelformset_factory

2010-08-13 Thread refreegrata
i'm sorry,but i don't understand the question.
the model is only an example. My idea is a model like this:

--
class Format(models.Model):
code = models.CharField(max_length=10)
name = models.CharField(max_length=30)
weight = models.PositiveSmallIntegerField()
..
--

the field code can only be edited when a new row is inserted. After
that the code must be displayed like a label or information,to inform
at the user the row that is editing.
--
formset

  Code 1 


  Code 2

.
--
I want to know if i can get the code list in the same instance where
the form is filled, or how i can do something like {{ fieldcode|id }}
or {{ fieldcode.id }} in the template?

Best regards

On 13 ago, 02:16, Boguslaw Faja  wrote:
> Hi,
>
> fast question: why fields = ['nombre'] instead of fields = ['name2'] ?
>
> Best regards
>
>
>
> On Wed, Aug 11, 2010 at 3:59 PM, refreegrata  wrote:
> > with a model like this:
> > --
> > class Format(models.Model):
> >    name1 = models.CharField(max_length=5)
> >    name2 = models.CharField(max_length=5)
> > --
>
> > and a modelform like this:
> > -
> > MyForm(forms.ModelForm)
> >   class Meta:
> >        model = Format
> >        fields = ['nombre']
> > -
>
> > this code will generate 2 "input text", the "input text" name1 and the
> > "input text" name2. But for an unique modelform from the model
> > "format" i want an "input text"(name2)  and a "label" or
> > "text"(name1), because the field "name1" can only be edited in the
> > first time.  In any other occasion the field "name1" most be displayed
> > like an info about de field "name2"
>
> > I do not know if you understand my question. basically is ¿ how i can
> > supply info about a row of mi table for a specific form of my formset?
>
> > example
> > normaly my html page is
> > ---
> > formset
> > 
> >   > value="Oscar" name="name2..."/>
> > 
> > 
> >   > value="Jack" name="name2..."/>
> > 
> > .
> > ---
> > but i want something like this
> > ---
> > formset
> > 
> >  "Alex" 
> > 
> > 
> >  "John"
> > 
> > .
> > ---
>
> > Thanks for read
>
> > P.D.: sorry for mi poor english
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> Bogusław Faja
> tel. (+48) 691544955

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



overwrite the save method

2010-08-11 Thread refreegrata
Hello list, i have a newbie question

My code
--
class Format(models.Model):
name = models.CharField(max_length=5, unique=True)
myBoolean = models.BooleanField(default=False)

class FormFormat(forms.ModelForm):
boolean1 = forms.BooleanField(required=False)
boolean2 = forms.BooleanField(required=False)

class Meta:
model = Format
fields = ['name']

FormsetFormFormat = forms.models.modelformset_factory(Format,
max_num=0,form=FormFormat)
--
The idea is this:

if boolean1=True and boolean2=True the field myBoolean must to be True
if boolean1=True and boolean2=False the field myBoolean must to be
False
...
My question is, how i can do this?
overwriting the save method?

I don't have idea, because boolean1 and boolean2 are form fields not
model fields. Can i pass custom parameters to the save method?

Thanks for read

P.D.:sorry for my poor english

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: add attributes to a field without widgets

2010-08-11 Thread refreegrata
Opps, I forgot to mention that I work with "Django 1.2.1". Apparently
is a Django bug.
Other persons has the same question "http://groups.google.com/group/
django-users/browse_thread/thread/c4899b0806e67ee7/d938f33a5f100af8?
show_docid=d938f33a5f100af8&fwc=1"

I will try to implement the solution you mention.

thanks for answer.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



convert textinput in label or text for a modelform and modelformset_factory

2010-08-11 Thread refreegrata
with a model like this:
--
class Format(models.Model):
name1 = models.CharField(max_length=5)
name2 = models.CharField(max_length=5)
--

and a modelform like this:
-
MyForm(forms.ModelForm)
   class Meta:
model = Format
fields = ['nombre']
-

this code will generate 2 "input text", the "input text" name1 and the
"input text" name2. But for an unique modelform from the model
"format" i want an "input text"(name2)  and a "label" or
"text"(name1), because the field "name1" can only be edited in the
first time.  In any other occasion the field "name1" most be displayed
like an info about de field "name2"

I do not know if you understand my question. basically is ¿ how i can
supply info about a row of mi table for a specific form of my formset?


example
normaly my html page is
---
formset

  


  

.
---
but i want something like this
---
formset

  "Alex" 


  "John"

.
---

Thanks for read

P.D.: sorry for mi poor english

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



add attributes to a field without widgets

2010-08-11 Thread refreegrata
Hello list. I'm a newbie in django and now i am working with
"modelformset_factory".

I have something like this
--
class MyForm(forms.ModelForm):
myField = forms.BooleanField()

class Meta:
model = Format
fields = ['name']
widgets = {'name' : forms.TextInput(attrs={ something }),}

FormsetMyForm= forms.models.modelformset_factory(Format, max_num=0,
form=MyForm)
--
With that code, django throw an error "Exception Value: () got
an unexpected keyword argument
'widget'", but i solve the problem deleting the "widget" declaration.

Now my question is: Can i add attributes in other side with Django ? a
Template for example, something like "{% field class="myclass" %}".

thanks for read.

P.D.: sorry for my poor english

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: problem with a formset from model

2010-08-11 Thread refreegrata
ok, i understand.

On 11 ago, 08:00, Nuno Maltez  wrote:
> This happens to me as well (also with 1.2.1). Seems like a bug with
> _queryset vs queryset on BaseModelFormSet.
>
> Maybe you could submit a ticket tohttp://code.djangoproject.com/query
>
> Nuno
>
> On Tue, Aug 10, 2010 at 9:21 PM, refreegrata  wrote:
> > Hello list. I have a problem. I'm a newbie in Django using his first
> > formset.
>
> > I have this:
> > 
> > class BaseFormFormato_habilitar(BaseModelFormSet):
> >    def __init__(self, *args, **kwargs):
> >        super(BaseFormFormato_habilitar, self).__init__(*args,
> > **kwargs)
> >        self.queryset = Formato.objects.filter(actividad=True)
>
> > FormFormato_habilitar = modelformset_factory(Formato, max_num=0,
> > formset=BaseFormFormato_habilitar)
> > 
>
> > I want a formset with forms filtered for
> > "Formato.objects.filter(actividad=True)", however, the formset always
> > returns all the rows in the table. My alternatively subclass
> > "BaseFormFormato_habilitar" don't works. What am I doing wrong?
> > the problem is solved if i do "FormFormato_habilitar(queryset =
> > Formato.objects.filter(actividad=True))" in a view, but i prefer solve
> > the problem with a subclass in the "forms.py".
>
> > thanks for read, and sorry for my poor english
>
> > P.D.: I use Django 1.2.1
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



problem with a formset from model

2010-08-10 Thread refreegrata
Hello list. I have a problem. I'm a newbie in Django using his first
formset.

I have this:

class BaseFormFormato_habilitar(BaseModelFormSet):
def __init__(self, *args, **kwargs):
super(BaseFormFormato_habilitar, self).__init__(*args,
**kwargs)
self.queryset = Formato.objects.filter(actividad=True)

FormFormato_habilitar = modelformset_factory(Formato, max_num=0,
formset=BaseFormFormato_habilitar)


I want a formset with forms filtered for
"Formato.objects.filter(actividad=True)", however, the formset always
returns all the rows in the table. My alternatively subclass
"BaseFormFormato_habilitar" don't works. What am I doing wrong?
the problem is solved if i do "FormFormato_habilitar(queryset =
Formato.objects.filter(actividad=True))" in a view, but i prefer solve
the problem with a subclass in the "forms.py".

thanks for read, and sorry for my poor english

P.D.: I use Django 1.2.1

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: custom form field validation

2010-07-15 Thread refreegrata
ok, for my problem that don't works because when i set required=False
the field isn't evaluated when it is in blank. I want an evaluation
for my function in every situation. With required=True and a custom
error message an evaluation can be simulated but if i do a code inside
the function in that case(blank) is never be evaluated.

On 15 jul, 11:26, Oleg Lomaka  wrote:
> http://docs.djangoproject.com/en/1.2/ref/forms/fields/#required
>
> usu = forms.CharField(required=False, ...)
>
> On Jul 15, 2010, at 5:25 PM, refreegrata wrote:
>
> > Hello list. I'm a newie in django with many questions. I want to do
> > something like this:
> > 
> > def (valor):
> >    raise ValidationError("A")
>
> > class M(forms.Form):
> >    usu =
> > forms.CharField(widget=forms.TextInput(attrs={'id':'txtUsu','maxlength':
> > '15','size':'20'}),
> >                              validators=[])
> > 
>
> > The code create a form with an input text. My question is. When i do a
> > submit with the field in blank django show an error_ "This field is
> > required." and when i write some string in te field django throw an
> > error "A". I only want the error message "A", and replace the
> > default validator with my custom validator. how i do that? the only
> > way is do a new field type with a herence from CharField?
>
> > That's my question, thanks for read, and sorry my poor english
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



custom form field validation

2010-07-15 Thread refreegrata
Hello list. I'm a newie in django with many questions. I want to do
something like this:

def (valor):
raise ValidationError("A")

class M(forms.Form):
usu =
forms.CharField(widget=forms.TextInput(attrs={'id':'txtUsu','maxlength':
'15','size':'20'}),
  validators=[])


The code create a form with an input text. My question is. When i do a
submit with the field in blank django show an error_ "This field is
required." and when i write some string in te field django throw an
error "A". I only want the error message "A", and replace the
default validator with my custom validator. how i do that? the only
way is do a new field type with a herence from CharField?

That's my question, thanks for read, and sorry my poor english

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



problem with encoding "utf-8", postgresql 8.3

2010-06-09 Thread refreegrata
Hello list. I'm a newbie with django and have a problem with the
encoding. I use postgreSQL 8.3 with psycopg2. My database is in latin1
and i can't change this to utf-8(i don't have the permission), however
the database have a client-encoding in utf-8. I think this solves the
problem.

Now my problem:

I have this code:
---
# -*- coding: utf-8 -*-
from django.db.models import Q
from django.shortcuts import render_to_response
from models import Book,Publisher
from forms import ContactForm
def search(request):
query = request.GET.get('q', '')
if query:
qset = (
Q(title__icontains=query) |
Q(authors__first_name__icontains=query) |
Q(authors__last_name__icontains=query)
)
results = Book.objects.filter(qset).distinct()
else:
results = []
return render_to_response("search.html", {
"results": results,
"query": type(query),
#"aaa":results.query,
})

and his template
---




Search{ % if query %} Results{ % endif %}


  Search
  
 Search: 
 
 
  
  {{ query|escape }}
  {% if query %}
 Results for "{{ query|escape }}":
 {% if results %}
{{ results|escape }}

{% for book in results %}
   {{ book|escape }}
{% endfor %}

 {% else %}
No books found
 {% endif %}
  {% endif %}


---

is a simple page to search coincidences

When i type "ó" in the input box all works fine, and returns all
coincidences and the url says "http://localhost/prueba_1/search/?q=ó";
However when i type directly in the url "http://localhost/prueba_1/
search/?q=ó" and press enter Django throw an error
"Caught DatabaseError while rendering: carácter 0xefbfbd de
codificación «UTF8» no tiene equivalente en «LATIN1»"
and the url in the browser change to "http://localhost/prueba_1/
search/?q=%F3". Why happens that?, I'm really confused with the themes
about the encoding.

That's is my question, thanks for read, and sorry for my poor english

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: i can't import newforms(newbie)

2010-06-08 Thread refreegrata
ok, thanks. Now I feel more relaxed.

On 8 jun, 15:50, Michael  wrote:
> On Tue, Jun 8, 2010 at 3:46 PM, refreegrata  wrote:
> > hello list
> > i'm a newbie with django trying to learn
> > Now i have a question
> > when i do
> > ---
> > from django import newforms as forms
> > 
> > django throw an exception : "Error was: cannot import name newforms"
>
> > But when i do
> > ---
> > from django import forms
> > ---
> > all works fine
>
> > Mi question is, in all tutorial that i read, the writter say something
> > like "the recommended way to import is 'from django import newforms as
> > forms'".
>
> > Why this way don't work now?.In the last version of Django newforms
> > was replaced for form?. I can't find nothing in the official
> > documention.
>
> > Mi PC have Django 1.2.1(the latest stable version)
>
> > That's my question. Thank's all. And sorry for my poor english, the
> > english isn't my mother language.
>
> The tutorial you read was for a django before 1.0. django.newforms was moved
> to django.forms for that release. If you see newforms in a tutorial, you can
> assume those are just forms now.
>
> Hope that helps,
>
> Michael

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



i can't import newforms(newbie)

2010-06-08 Thread refreegrata
hello list
i'm a newbie with django trying to learn
Now i have a question
when i do
---
from django import newforms as forms

django throw an exception : "Error was: cannot import name newforms"

But when i do
---
from django import forms
---
all works fine

Mi question is, in all tutorial that i read, the writter say something
like "the recommended way to import is 'from django import newforms as
forms'".

Why this way don't work now?.In the last version of Django newforms
was replaced for form?. I can't find nothing in the official
documention.

Mi PC have Django 1.2.1(the latest stable version)

That's my question. Thank's all. And sorry for my poor english, the
english isn't my mother language.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.