Re: XML serialization and Unicode

2009-07-29 Thread l5x

Hello,

On 29 Lip, 15:56, cootetom  wrote:
> To add, something just popped into my head. Have you got
> DEFAULT_CHARSET = 'utf-8' in your settings.py fiile

It didn't help.

> On Jul 29, 2:51 pm, cootetom  wrote:
>
> > I would imagine that the deserialize function tries to encode the
> > input down to ascii. My suggestion would be to find the XML serializer
> > code and see what it is doing with the input string you pass to it.

Thanks for inspiration, although smart_unicode() and encode('utf-8')
in save() is not helping much, after changing /usr/lib/python2.5/xml/
sax/expatreader.py, line 207:

--BEFORE --

   try:
# The isFinal parameter is internal to the expat reader.
# If it is set to true, expat will check validity of the
entire
# document. When feeding chunks, they are not normally
final -
# except when invoked from close.
self._parser.Parse(data, isFinal)
except expat.error, e:
exc = SAXParseException(expat.ErrorString(e.code), e,
self)
# FIXME: when to invoke error()?
self._err_handler.fatalError(exc)

-- AFTER --

   try:
# The isFinal parameter is internal to the expat reader.
# If it is set to true, expat will check validity of the
entire
# document. When feeding chunks, they are not normally
final -
# except when invoked from close.

data = data.encode('utf-8') # this makes difference

self._parser.Parse(data, isFinal)
except expat.error, e:
exc = SAXParseException(expat.ErrorString(e.code), e,
self)
# FIXME: when to invoke error()?
self._err_handler.fatalError(exc)

It works. Thank you!

Best regards,
Luke
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



XML serialization and Unicode

2009-07-29 Thread l5x

Hello,

first of all, congratulations!

I have a problem. When trying to open template I get following error:

Original Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/django/template/debug.py",
line 71, in render_node
result = node.render(context)
  File "/usr/lib/python2.5/site-packages/django/template/
defaulttags.py", line 206, in render
val1 = self.var1.resolve(context, True)
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py",
line 546, in resolve
obj = self.var.resolve(context)
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py",
line 687, in resolve
value = self._resolve_lookup(context)
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py",
line 722, in _resolve_lookup
current = current()
  File "/home/user/django_projects/bis/bis/../bis/Log/models.py", line
124, in deserialized_object
for obj in serializers.deserialize("xml", self.data):
  File "/usr/lib/python2.5/site-packages/django/core/serializers/
xml_serializer.py", line 128, in next
for event, node in self.event_stream:
  File "/usr/lib/python2.5/xml/dom/pulldom.py", line 232, in next
rc = self.getEvent()
  File "/usr/lib/python2.5/xml/dom/pulldom.py", line 265, in getEvent
self.parser.feed(buf)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 207, in feed
self._parser.Parse(data, isFinal)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0142' in
position 154: ordinal not in range(128)

I use latest SVN version (1.1) revision 11367. I have # -*- coding:
utf-8 -*-  line at the beginning of the file, and __unicode__ method
is set on the model, which I serialize and on Log model as well.

My serialization:

[ some model ... ]

def save(self, force_insert=False, force_update=False):
super(Record,self).save(force_insert, force_update)
data_xml = serializers.serialize("xml", Record.objects.filter
(id=self.id))
Log.objects.create(user=user, action="zapis", type="Record",
  object=self.id, data=data_xml)

Deserialization:

[ my model: Log ... ]

def deserialized_object(self):
for obj in serializers.deserialize("xml", self.data):
return obj.object   [1]

[1] There is only one object so I use return on the first try.

My template:

{% ifnotequal log.deserialized_object.value
log.previous.deserialized_object.value %}
something
 {% endifnotequal %}

It doesn't matter how do I put data to database: manually using create
() or via form.save(), and it is in UTF-8. In addition I don't have
any problems with database and unicode in other parts of my project,
only during this deserialization.

I tried to pass data to deserializer after using force_unicode, but
the result is the same.

I would appreciate any help.

Best regards,
Luke
--~--~-~--~~~---~--~~
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: Connection.has no attribute ping -- after recompiling modpython

2008-06-19 Thread l5x

On Jun 19, 8:22 pm, l5x <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Request Method:         GET
> Request URL:    https://age86.internetdsl.tpnet.pl/
> Exception Type:         AttributeError
> Exception Value:        'Connection' object has no attribute 'ping'
> Exception Location:     /usr/django/django/db/backends/mysql/base.py in
> _valid_connection, line 162
> Python Executable:      /usr/bin/python
> Python Version:         2.5.0
>
> Traceback:
> File "/usr/django/django/core/handlers/base.py" in get_response
>   82.                 response = callback(request, *callback_args,
> **callback_kwargs)
> File "/usr/django/django/contrib/auth/decorators.py" in __call__
>   66.         if self.test_func(request.user):
> File "/usr/django/django/contrib/auth/middleware.py" in __get__
>   5.             request._cached_user = get_user(request)
> File "/usr/django/django/contrib/auth/__init__.py" in get_user
>   83.         user = backend.get_user(user_id) or AnonymousUser()
> File "/usr/django/django/contrib/auth/backends.py" in get_user
>   68.             return User.objects.get(pk=user_id)
> File "/usr/django/django/db/models/manager.py" in get
>   82.         return self.get_query_set().get(*args, **kwargs)
> File "/usr/django/django/db/models/query.py" in get
>   192.         num = len(clone)
> File "/usr/django/django/db/models/query.py" in __len__
>   53.                 self._result_cache = list(self.iterator())
> File "/usr/django/django/db/models/query.py" in iterator
>   162.         for row in self.query.results_iter():
> File "/usr/django/django/db/models/sql/query.py" in results_iter
>   200.         for rows in self.execute_sql(MULTI):
> File "/usr/django/django/db/models/sql/query.py" in execute_sql
>   1473.         cursor = self.connection.cursor()
> File "/usr/django/django/db/backends/__init__.py" in cursor
>   33.         cursor = self._cursor(settings)
> File "/usr/django/django/db/backends/mysql/base.py" in _cursor
>   170.         if not self._valid_connection():
> File "/usr/django/django/db/backends/mysql/base.py" in
> _valid_connection
>   162.                 self.connection.ping()
>
> It occured after I had recompiled mod_python 3.3.1 on Apache2.2.3 with
> Python2.5 instead of Python2.4.
>
> I can import MySQLdb using both Python2.5 and Python2.4.
>
> With Python2.4 I could perform 'syncdb' but now it is: Connection
> object has no attribute 'get_server_info'.
>
> My distro is Debian Etch 4.0 Stable. Django is the newest SVN.
>
> Does anybody know how to fix it?

If anybody is interested - it works fine with PostgreSQL (psycopg2)
and SQLite3. No luck with MySQL 5 (MySQLdb).
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Connection.has no attribute ping -- after recompiling modpython

2008-06-19 Thread l5x

Hello,

Request Method: GET
Request URL:https://age86.internetdsl.tpnet.pl/
Exception Type: AttributeError
Exception Value:'Connection' object has no attribute 'ping'
Exception Location: /usr/django/django/db/backends/mysql/base.py in
_valid_connection, line 162
Python Executable:  /usr/bin/python
Python Version: 2.5.0

Traceback:
File "/usr/django/django/core/handlers/base.py" in get_response
  82. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/django/django/contrib/auth/decorators.py" in __call__
  66. if self.test_func(request.user):
File "/usr/django/django/contrib/auth/middleware.py" in __get__
  5. request._cached_user = get_user(request)
File "/usr/django/django/contrib/auth/__init__.py" in get_user
  83. user = backend.get_user(user_id) or AnonymousUser()
File "/usr/django/django/contrib/auth/backends.py" in get_user
  68. return User.objects.get(pk=user_id)
File "/usr/django/django/db/models/manager.py" in get
  82. return self.get_query_set().get(*args, **kwargs)
File "/usr/django/django/db/models/query.py" in get
  192. num = len(clone)
File "/usr/django/django/db/models/query.py" in __len__
  53. self._result_cache = list(self.iterator())
File "/usr/django/django/db/models/query.py" in iterator
  162. for row in self.query.results_iter():
File "/usr/django/django/db/models/sql/query.py" in results_iter
  200. for rows in self.execute_sql(MULTI):
File "/usr/django/django/db/models/sql/query.py" in execute_sql
  1473. cursor = self.connection.cursor()
File "/usr/django/django/db/backends/__init__.py" in cursor
  33. cursor = self._cursor(settings)
File "/usr/django/django/db/backends/mysql/base.py" in _cursor
  170. if not self._valid_connection():
File "/usr/django/django/db/backends/mysql/base.py" in
_valid_connection
  162. self.connection.ping()

It occured after I had recompiled mod_python 3.3.1 on Apache2.2.3 with
Python2.5 instead of Python2.4.

I can import MySQLdb using both Python2.5 and Python2.4.

With Python2.4 I could perform 'syncdb' but now it is: Connection
object has no attribute 'get_server_info'.

My distro is Debian Etch 4.0 Stable. Django is the newest SVN.

Does anybody know how to fix it?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Inserting a date into DateField

2008-01-12 Thread l5x

On Jan 12, 1:49 pm, Darthmahon <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm trying to insert a simple date (2002-01-12) from a form I have
> created into a DateField but I keep getting this error:
>
> 'str' object has no attribute 'strftime'
>
> This is how the DateField is setup in my models.py file:
>
> birthday = models.DateField(blank=True)
>
> This is how I am trying to write to this field:
>
> _dob = request.POST['dob']
> user_profile =
> UserProfile(user_id=user.id,gender=_gender,birthday=_dob,living=_location)
> user_profile.save()
>

Try this:

user_profile = UserProfile(request.POST)
if user_profile.is_valid():
user_profile.save()
else:
   ...

Best regards,
l.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Adding a request.user to a ModelForm instance

2008-01-08 Thread l5x

On Jan 8, 3:03 am, Car <[EMAIL PROTECTED]> wrote:
> Hello
>
> I have following code;
>
> class PlaceForm(ModelForm):
> class Meta:
> model = Place
> exclude = ('useradd',) #excluded, because form shouldn't give
> a way to set user manually
>
> Model Place has one foreign key to django User model (useradd)
>
> Is it possible to add field formerly excluded in ModelForm in view
> like in this example below:
>
> newplace = form.save(commit="False")
> newplace.useradd = request.user   #excluded in PlaceForm
> newplace.save()
>
> Exeption after executing this lines:
>
> Exception Value:(1048, "Column 'useradd_id' cannot be null")

This should help you:
http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser

Best regards,
l.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: passing data to view using httpresponseredirect

2008-01-03 Thread l5x

Why don't you use sessions?
http://www.djangoproject.com/documentation/sessions/

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Syntax Error (line out of range), get_callable, urlresolvers

2007-12-30 Thread l5x

On Dec 31, 12:19 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote:

> Is 534 one past the last line of views.py?

Yes.

> I expect you have a syntax error
> such as a missing closing paren or bracket in your views.py file, which is
> causing the parser to keep scanning until it reaches the end of the file and
> then report the error on one line past the end of the file.  The error is
> probably near the end of the file.  For syntax errors you often have to look
> a little above where the error is reported to see what is really causing the
> problem.
>

Yes, I know about it, but I deleted my new parts of code and it is
still the same result. My Eclipse+PyDev doesn't show any mistakes as
well. If there is no other suggestions - I will just check my code
line by line to check what it may be.

Thank you.

Best regards,
l.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Syntax Error (line out of range), get_callable, urlresolvers

2007-12-30 Thread l5x

Hello,

I get the following error:

Django Version: 0.97-pre-SVN-6976
Python Version: 2.5.1
Exception Type: SyntaxError
Exception Value:invalid syntax (views.py, line 534)
Exception Location: /home/user/django_src/django/core/urlresolvers.py
in get_callable, line 47

Traceback:
File "/home/user/django_src/django/core/handlers/base.py" in
get_response
  73. callback, callback_args, callback_kwargs =
resolver.resolve(request.path)
File "/home/user/django_src/django/core/urlresolvers.py" in resolve
  233. sub_match = pattern.resolve(new_path)
File "/home/user/django_src/django/core/urlresolvers.py" in resolve
  172. return self.callback, args, kwargs
File "/home/user/django_src/django/core/urlresolvers.py" in
_get_callback
  178. self._callback = get_callable(self._callback_str)
File "/home/user/django_src/django/utils/functional.py" in wrapper
  18. result = func(*args)
File "/home/user/django_src/django/core/urlresolvers.py" in
get_callable
  47. lookup_view = getattr(__import__(mod_name, {},
{}, ['']), func_name)

Exception Type: SyntaxError at /
Exception Value: invalid syntax (views.py, line 534)

Interesting thing is that line (534) is out of range...

When I'm trying to visit admin page, I get Syntax Error with the same
line and:

Traceback:
File "/home/user/django_src/django/core/handlers/base.py" in
get_response
  82. response = callback(request, *callback_args,
**callback_kwargs)
File "/home/user/django_src/django/contrib/admin/views/decorators.py"
in _checklogin
  66. return _display_login_form(request, message)
File "/home/user/django_src/django/contrib/admin/views/decorators.py"
in _display_login_form
  29. }, context_instance=template.RequestContext(request))
File "/home/user/django_src/django/template/context.py" in __init__
  102. for processor in get_standard_processors() +
processors:
File "/home/user/django_src/django/template/context.py" in
get_standard_processors
  78. mod = __import__(module, {}, {}, [attr])

What do you think about it?

Best regards,
l.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: hide fields using newforms

2007-12-30 Thread l5x

On Dec 30, 5:04 pm, Florian Lindner <[EMAIL PROTECTED]> wrote:
> Hello,
> using newforms how can I set fields to be hidden (the hidden="hidden"
> attribute)?

Did you mean type="hidden" ?
http://www.djangoproject.com/documentation/newforms/#widgets

You can create your own widget if you need to.

l.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ModelForm, ImageField and User

2007-12-28 Thread l5x

On Dec 27, 8:22 am, Muchanic <[EMAIL PROTECTED]> wrote:

> Just FYI and for anyone else who comes across this thread - I had the
> same problem, trying to pass a ForeignKey via HiddenInput in an app
> I'm working on. If you need to/want to do it this way, the trick is
> that you have to use a ModelChoiceField and not an IntegerField for
> Django to be able to do it's magic.
>
> e.g. in my case I had something like
>
> class CourseAddForm(forms.ModelForm):
> institution = forms.ModelChoiceField(Institution.objects.all(),
> widget=forms.HiddenInput())

You are right. When I load the page I can see the proper value in the
source - it's working. But when I submit the data I get: "(Hidden
field user) Select a valid choice. That choice is not one of the
available choices."

How can I fix it?

Best regards
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Customizing date field of form

2007-12-25 Thread l5x

Maybe you should take a look at render():

http://code.djangoproject.com/browser/django/trunk/django/newforms/widgets.py#L44
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Page not showing correct data

2007-12-25 Thread l5x

After reloading the page (f5) browser shows new data?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: editing an image with ModelForm

2007-12-25 Thread l5x

Hm, I didn't have this error with my PhotoForm. You can look at it
here: 
http://groups.google.com/group/django-users/browse_thread/thread/6693f3294e710eab
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ModelForm, ImageField and User

2007-12-25 Thread l5x

Thank you, I will check that. I wasn't aware of that possibility.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using extjs with ModelForms

2007-12-24 Thread l5x

Do you want to change the HTML output of the form?

Then you should take a look at render()
http://code.djangoproject.com/browser/django/trunk/django/newforms/widgets.py

or

_html_output() with as_*
http://code.djangoproject.com/browser/django/trunk/django/newforms/forms.py

Best regards,
l.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ModelForm, ImageField and User

2007-12-23 Thread l5x

class Photo(models.Model):
user = models.ForeignKey(User)
main = models.BooleanField(_('Is main?'))
icon = models.ImageField(_('Icon'), upload_to='photo', null=True,
blank=True,
 help_text=_('Don\'t touch! It will be
generated automatically'))
medium = models.ImageField(_('Medium'), upload_to='photo',
null=True, blank=True,
   help_text=_('Don\'t touch! It will be
generated automatically'))
big = models.ImageField(_('Photo'), upload_to='photo', null=True,
blank=True)

description = models.TextField(_('Description'))

class Admin:
list_display = ('user', 'description')

def _save_FIELD_file(self, field, filename, raw_contents,
save=False):
import sha
import random
import Image
ext = filename[-3:]
if ext == 'JPG' or ext == 'jpg':
ext = 'JPEG'
filename = sha.new(filename+str(random.random())).hexdigest()
filename = "%s_%s.%s" % (self.user_id, filename, ext)
super(Photo, self)._save_FIELD_file(field, filename,
raw_contents, save=False)
im = Image.open(u'/home/project/site_media/'+self.big)
im.thumbnail((300, 400), Image.ANTIALIAS)
im.save('/home/project/site_media/photo/'+filename, ext)

med = Image.open(u'/home/project/site_media/'+self.big)
med.thumbnail((120, 160), Image.ANTIALIAS)
filename = sha.new(str(random.random())).hexdigest()
filename = "%s_%s.%s" % (self.user_id, filename, ext)
med.save('/home/project/site_media/photo/'+filename, ext)
self.medium = 'photo/%s' % filename

icon = Image.open(u'/home/project/site_media/'+self.big)
icon.thumbnail((60, 80), Image.ANTIALIAS)
filename = sha.new(str(random.random())).hexdigest()
filename = "%s_%s.%s" % (self.user_id, filename, ext)
icon.save('/home/project/site_media/photo/'+filename, ext)
self.icon = 'photo/%s' % filename


class PhotoForm(ModelForm):
user = forms.IntegerField(widget=forms.HiddenInput)
class Meta:
model = Photo
fields = ('user', 'big', 'main', 'description')
==

def gallery(request):
data = request.POST.copy()
try:
a = data['main']
other = Photo.objects.filter(user=request.user)
for o in other:
o.main = False
print "main? ", o.main
o.save()

except KeyError:
print "key error"
photos = Photo.objects.filter(user=request.user).count()
print photos
if photos == 0:
data['main'] = 'on'


if request.POST:
photo_form = PhotoForm(request.POST, request.FILES)
if photo_form.is_valid():
   photo_form.save()
else:
pre_data = {'user': request.user.id }
photo_form = PhotoForm(pre_data)

gallery = Photo.objects.filter(user=request.user)

return render_to_response('Member/gallery.html', {'gallery':
gallery, 'photo_form': photo_form},
 
context_instance=RequestContext(request))

I have two issues:

1) When I use photo_form.save() I get: (1048, "Column 'user_id' cannot
be null"), despite the fact that the user is in the POST data:
description:u'my desc'
user:   u'2'
2) I wrote:

pre_data = {'user': request.user.id }
photo_form = PhotoForm(pre_data)

And there is a HiddenInput for User ForeignKey in the PhotoForm

But is there any other way to pass the information about User?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'User' object has no attribute 'get'

2007-12-23 Thread l5x

I think I missed: 
http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges#ModelFormsconstructornowmatchesForms
That should be the solution!
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



'User' object has no attribute 'get'

2007-12-23 Thread l5x

Traceback:
File "/home/user/django_src/django/template/debug.py" in render_node
  71. result = node.render(context)
File "/home/user/django_src/django/template/debug.py" in render
  87. output =
force_unicode(self.filter_expression.resolve(context))
File "/home/user/django_src/django/utils/encoding.py" in force_unicode
  51. s = unicode(s)
File "/home/user/django_src/django/newforms/forms.py" in __unicode__
  69. return self.as_table()
File "/home/user/django_src/django/newforms/forms.py" in as_table
  152. return self._html_output(u'%(label)s%
(errors)s%(field)s%(help_text)s', u'%s', '', u'%s', False)
File "/home/user/django_src/django/newforms/forms.py" in _html_output
  108. top_errors = self.non_field_errors() # Errors that
should be displayed above all fields.
File "/home/user/django_src/django/newforms/forms.py" in
non_field_errors
  168. return self.errors.get(NON_FIELD_ERRORS,
self.error_class())
File "/home/user/django_src/django/newforms/forms.py" in _get_errors
  86. self.full_clean()
File "/home/user/django_src/django/newforms/forms.py" in full_clean
  183. value = field.widget.value_from_datadict(self.data,
self.files, self.add_prefix(name))
File "/home/user/django_src/django/newforms/widgets.py" in
value_from_datadict
  65. return data.get(name, None)

views:

profile = Profile()
user = User()

   if request.POST:
   ... (i'm not using POST)
   else:
  form_user = UserForm(user)
form_profile = UserBasicForm(profile)

return render_to_response(
  'Member/register.html',
  {'basic_user_form': form_user,
   'basic_profile_form': form_profile},
context_instance=RequestContext(request)
  )

What do you thing about it?
I get this using FastCGI in shared environment, Python 2.5.1, Django
0.97-pre-SVN-6976
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Time.sleep & HttpResponse

2007-12-17 Thread l5x

"I propose to design and implement an API to make Comet behavior
available to Django applications."
http://hosted.corp.it/django/full.html
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Time.sleep & HttpResponse

2007-12-16 Thread l5x

If you put /print "hello"/, the server should print it with given
delay (on the server side).
I think that you should use JS/AJAX to update the page after it is
sent to the user (script on the user side).
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms: drop down datefield

2007-12-16 Thread l5x

Thank you Luis!

I hope that internationalization will replace English months :)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms: drop down datefield

2007-12-15 Thread l5x

Look here, I have similar problem, but unfortunately nobody was able
to help me. I'm still waiting for answer, because it's important for
me.

http://groups.google.com/group/django-users/browse_thread/thread/d3b03b7fc5288ae0

Maybe it will iluminate you somehow :)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: MultiWidget, value_from_datadict, SplitDateWidget

2007-12-14 Thread l5x

No problem, just waiting for somebody more advanced than me to help
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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: list index out of range

2007-12-13 Thread l5x

Can you give us "class RegistrationProfile" from C:\Python25\Lib\site-
packages\registration\models.py ?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: list index out of range

2007-12-13 Thread l5x

Traceback? Template variables?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: MultiWidget, value_from_datadict, SplitDateWidget

2007-12-13 Thread l5x

> Doesn't Django have something very similar inbuilt to newforms?

You mean: SplitDateTimeWidget
But there is no custom 'value_from_datadict'
See: 
http://code.djangoproject.com/browser/django/trunk/django/newforms/widgets.py#L459
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



MultiWidget, value_from_datadict, SplitDateWidget

2007-12-13 Thread l5x

Hello,

Based on this thread: 
http://groups.google.com/group/django-users/browse_thread/thread/fd450734295e450f/68d466b0d6b24eb7

I have the following code for the SplitDateWidget:

class SplitDateWidget(forms.MultiWidget):
def __init__(self, attrs=None):
widgets = (Select(attrs=attrs, choices=DAY_LIST),
Select(attrs=attrs, choices=MONTH_LIST), Select(attrs=attrs,
choices=YEAR_LIST))
super(SplitDateWidget, self).__init__(widgets, attrs)

def value_from_datadict(self, data, files, name):
return [widget.value_from_datadict(data, files, name + '_
%s' % i) for i, widget in enumerate(self.widgets)]

def decompress(self, value):
if value:
print 'value: ', value
value=unicode(value).split('-')
return [value[2],value[1],value[0]]
return None

And I don't know what do I need to change in value_from_datadict to
get this work after request.POST. As for now I get error: "Ensure this
value has at most 3 characters (it has 22)."
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Trying to reuse models and forms

2007-12-12 Thread l5x

form_for_instance? Check: 
http://www.djangoproject.com/documentation/newforms/#generating-forms-for-models
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Performance of a django website

2007-12-11 Thread l5x

I think that some info about your web-server could be important.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: using FileField.delete_file to remove unused images

2007-12-11 Thread l5x

I didn't use delete_file, but if you can't solve this you can write
your own code for that using signals (pre_delete or post_delete).
More: http://code.djangoproject.com/wiki/Signals

Anyway I'm also curious how to do that without signals.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best way to make content in templates

2007-12-11 Thread l5x

Isn't it just putting variable into template? I don't know if I
understand you correctly but for example:

models.py

Image(models.Model)
name = CharField(...)
location = ImageField(...)

YourModel(models.Model)
image = ForeignKey(Image)
user = ForeignKey(User)

(...)

index.html:



views.py:

(...)
from django.template import RequestContext
def my_request_context():
my_model = MyModel.objects.get(user=request.user)
# you can get the Image : my_model.image
return my_model # or my_model.image

and then use it when you need (rememer to add it to
TEMPLATE_CONTEXT_PROCESSORS in settings, and to call the request
context everytime you need it in views in 'render_to_response')

But I don'f now if it is what you need.

You should focus on http://www.djangoproject.com/documentation/templates_python/
(everything is written there)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: just starting out with django along with the tutorial - getting a type error

2007-12-11 Thread l5x

Thank you Malcolm, you are very helpful today :)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: creating user and profile in just one form

2007-12-11 Thread l5x

I suppose that you should also check if the username isn't already
taken.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: just starting out with django along with the tutorial - getting a type error

2007-12-11 Thread l5x

Oops, Malcolm answered first :)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: just starting out with django along with the tutorial - getting a type error

2007-12-11 Thread l5x

I don't know if it could help, but anyway you should:

1) add the following line at the beggining of models.py

# -*- coding: utf8 -*-

2) change the order of stuff in models, at first fields: CharField
etc, then classes (Admin, Meta) and methods at the end (__unicode__
etc).
3) add after 'coding', at the beggining:

from django.utils.encoding import smart_unicode

3) on model Ticket:

def __unicode__(self):
return self.ticket_numb

change it to:

def __unicode__(self):
return smart_unicode(self.ticket_numb)

I suppose that's the reason. You are returning Integer (ticket_numb is
integer) in __unicode__ when django expects unicode string.

Hope it will help.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: cannot import ModelForm

2007-12-11 Thread l5x

Once again, you were right Malcolm.
Python was importing the old django version, so I did:
python setup.py install

in the trunk and now it's working.

Thank you everyone for your suggestions.

Ps. I'm really happy that ModelForm exists, it's very useful.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



cannot import ModelForm

2007-12-10 Thread l5x

Hello,

I have been working Django (mod_python or Django server as well). I
have updated it to SVN 6906 (newest at this time), because I wanted to
use the ModelForm, but unfortunately:

Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.newforms import ModelForm
Traceback (most recent call last):
  File "", line 1, in 
ImportError: cannot import name ModelForm

Any ideas?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: parameters getting modified

2007-12-10 Thread l5x

If the example from Rajesh isn't working maybe you should do sth like
that:

/post// ?

For example:

/post/http/google.com

Then join it 'http' + '://' + 'google.com'
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Non-programmer looking to create more sophisticated site

2007-12-07 Thread l5x

I suppose that you should take a look at 
http://www.djangoproject.com/documentation/flatpages/
as well.
It will give you the basic possibilty to manage the content, than you
can extend it while learning more.

Best regards,
l
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: mark form field as required in markup

2007-12-07 Thread l5x

You also do this like that:

class CommentForm(forms.Form):
name = forms.CharField(
widget=forms.TextInput(attrs={'class':'special'}))
url = forms.URLField()
comment = forms.CharField(
   widget=forms.TextInput(attrs={'size':'40'}))


'class':'special' -- it marks your field with the class
'special' (example straight from Django documentation)

http://www.djangoproject.com/documentation/newforms/#creating-custom-fields

Best regards,
l
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



overriding User model list_display and fields in Admin

2007-12-07 Thread l5x

Hello,

I couldn't find the information how to override the 'list_display' and
'fields' of the Django (SVN) User model in Admin interface.

I need to display User altogether with his two profiles. I know that
there is a get_profile(), but I want to display everything related to
User in the Admin, in one place (the same for adding/changing).  Is
there any way to do that? Can I subclass it somehow in a way that it
will work with further Django releases?

If not, is there a possibility to display on the first profile a link
to another profile and vice versa? How can I do that?

If there is no possibility, I suppose the only solution will be to
join these two profiles and show information from the User model in
custom list_display of that 'super profile'.

Any ideas? If my thinking is incorrect, please feel free to correct 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: _real_get_response: global name '_' is not defined

2007-10-22 Thread l5x

Thank you, it's working now.

Now I know to look for changes on 
http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges
every time I use svn.

Best regards,
l5x


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



_real_get_response: global name '_' is not defined

2007-10-22 Thread l5x

Hello,

my code was working fine, until I put it on my another system.
The error I get with newest SVN django version is:

NameError at /
global name '_' is not defined
Request Method: GET
Request URL:http://localhost:8000/
Exception Type: NameError
Exception Value:global name '_' is not defined
Exception Location: /usr/lib/python2.5/site-packages/django/core/
handlers/base.py in _real_get_response, line 81
Python Executable:  /usr/bin/python
Python Version: 2.5.1

Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in _real_get_response
  81. response = callback(request, *callback_args, **callback_kwargs)

  NameError at /
  global name '_' is not defined


I tried both bulit-in server and mod_python, but result is the same.
Any idea? Unfortunately, I didn't find anything related to that issue
on the net.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Related Field has invalid lookup: icontains

2007-07-23 Thread l5x

Okay. It works!

The missing part in my code was:
Q(author__username__icontains=phrase). I couldn't find it. Thank you
for your help.
@Tim: I will remember to debug it that way in the future. 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Related Field has invalid lookup: icontains

2007-07-23 Thread l5x

Hello,

I have code for searching:

news = News.objects.filter(
Q(title__icontains=phrase)
  | Q(tags__icontains=phrase)
  | Q(short__icontains=phrase)
  | Q(content__icontains=phrase)
  | Q(author__icontains=phrase)
  | Q(source__icontains=phrase)
 )

News model looks like that:

class News(models.Model):
title = models.CharField(maxlength="100")
tags = models.CharField(maxlength="75")
short = models.TextField()
content = models.TextField()
author = models.ForeignKey(User, editable=False)
source = models.CharField(maxlength="100")
date = models.DateTimeField(auto_now_add=True)
status = models.IntegerField(editable=False, default="0")
def __str__(self):
   return '%s' % (self.title)
class Admin():
pass

and when trying to display 'news' in template i get:

Request Method: POST
Request URL:http://localhost:8000/search/
Exception Type: TypeError
Exception Value:Related Field has invalid lookup: icontains
Exception Location: /usr/lib/python2.5/site-packages/django/db/models/
fields/related.py in get_db_prep_lookup, line 109
Python Executable:  /usr/bin/python
Python Version: 2.5.1

Does anybody know what can I do to fix that ?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: forms and designers

2007-07-08 Thread l5x

Maybe it will be useful:
http://groups.google.com/group/django-users/browse_thread/thread/a60038f4d0777391/a94a8e1dff4865db#a94a8e1dff4865db


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: gettatr() access to ManyToMany huuuge delay?

2007-06-27 Thread l5x

On Jun 27, 11:32 pm, grassoalvaro <[EMAIL PROTECTED]> wrote:
> Here some code:
> -
> class TestField(models.Model):
> name = models.TextField()
> text = models.ManyToManyField(TextOption)
> class Meta:
> db_table = 'test'
>
> test = TestField.objects.get()
> a = time.time()
> for i in range(0, 1):
> t = getattr(test, "text")
> print "text: %f"%(time.time()-a)
> a = time.time()
> for i in range(0, 1):
> t = getattr(test, "name")
> print "name: %f"%(time.time()-a)
>
> text: 1.149759
> name: 0.017819
> -
>
> Can someone explain me, why when i'm doing gettatr(test, "text")
> (ManyToMany) i have so long delay? That is django (not database)
> problem but i really don't know why. Anyone?

Doesn't it depend on server ?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Attrs in models

2007-06-25 Thread l5x

If it is by design - it is ok. I thought that I just can't find
information *how* to do it. Thanks for your time & effort.

On Jun 25, 3:19 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Sun, 2007-06-24 at 22:49 +, l5x wrote:
> > This is a great stuff and I'm really glad that you show me that, but I
> > still wonder if it is possible to do sth like that in a model ;-)
>
> No, it isn't possible and that's by design. Here's the reasoning behind
> why we are doing it the way we are:
>
> In the general case ,tying a particular presentation to the data
> representation isn't a flexible procedure and long-term in medium to
> large projects, not great design practice either: the person responsible
> for creating the form designs has to also edit the code that is part of
> the data representation. We try very hard in Django (and are continually
> smoothing out places as we go along) to keep independent
> responsibilities separate in the code and this includes moving
> presentation information out of models.
>
> We have to make a choice when creating the API here and, as with all
> choices, some use-cases might become a little harder (but never
> impossible) whilst we are making the common and best-practice cases
> easier. In this particular instance, the case where you have a single
> presentation style and are always creating forms directly from a single
> model requires you to write the field names twice sometimes. That's one
> of the trade-offs in the broader design, unfortunately.
>
> Consequently, you can't drop presentation information into the model
> directly. However, you could store a list of that extra information
> mapped to field names in a dictionary and then write a helper function
> that takes your model and that dictionary and creates a form. So if you
> did have a desire to keep the information together, it's possible. You
> just can't hijack the Field class definitions to store it, because that
> would require changing the API (you could write new classes, one for
> each Field that takes the extra information, but at some point the extra
> work to support that might become onerous).
>
> Regards,
> Malcolm


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Attrs in models

2007-06-24 Thread l5x

This is a great stuff and I'm really glad that you show me that, but I
still wonder if it is possible to do sth like that in a model ;-)
I mean:

Model looks like that:

class ShortNews(models.Model):
url = models.URLField("URL")
description = models.CharField("Desc", maxlength="200")
author = models.ForeignKey(User, editable=False)
date = models.DateTimeField("Date", auto_now_add=True)
status = models.IntegerField("Status", editable=False, default="0")

and I don't know why it is not possible to do sth like:

class ShortNews(models.Model):
url = models.URLField("URL", attr['class':'required'])
description = models.CharField("Desc", maxlength="200",
attr['class':'highlight'])
 ..etc

It's much faster than doing that at every form_for_* and you don't
have to have it spread all over the code. But the point is, that I
don't know if there is something which can allow to do that :)

Thanks,
l5x


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Attrs in models

2007-06-24 Thread l5x

And what if I need a class only in selected fields ?:)
Can I pass it somehow through a list of the fields ?

Something like that should be nice:

list_of_required = ['name', 'username']
MyForm = form_for_model(MyModel, form=
BaseYourForm(list_of_required))

Hm. I guess that I only have to modify the loop:

for i in self.fields:
self.fields[i].widget.attrs['class'] =
'yourclassname'

But what's the name of field ? i.name ? or what ?


On Jun 24, 10:31 pm, l5x <[EMAIL PROTECTED]> wrote:
> I think that it's a right thing for me. Thanks for your effort.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: psycopg2.ProgrammingError: relation * already exists

2007-06-24 Thread l5x

Hm.. I suppose that if you change the name of model it'll be okay.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Attrs in models

2007-06-24 Thread l5x

I think that it's a right thing for me. Thanks for your effort.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Attrs in models

2007-06-24 Thread l5x

Hello,

is there any possibility in django to put a widget into a model
instead of creating the whole forms for each model (using widgets
render)? I only need to add a css class to each field in a model...

Best regards


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---