Model field validation available in 0.96 but removed in 1.0?

2009-03-19 Thread Crispin Wellington

Hey there.

I want to add a custom validator to a model field. In django 0.96 there
was the validator_list parameter that could easily do this for me. Now
it is no more. Also django.core.validators is gone.

How do I add a custom validator to a form field now? I want to ensure
that that a FloatField contains a positive value, but NOT zero. I need
this to be enforced in Django admin.

How do I do this now in Django 1.0?

Regards

Crispin Wellington




--~--~-~--~~~---~--~~
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: Map events in space on a django app

2009-03-19 Thread Andy Mckay


On 19-Mar-09, at 5:29 PM, Alessandro wrote:

> I'm looking for some documentation, but it seems not too simple.
> it should be very easier if someone shared a sample simple app using
> django.contrib.gis

You need two fields on a model, longitude and latitude. The rest of it  
is pure Javascript to place the pin on a map. You can see javascript I  
used for my site on http://www.cleartrain.ca, if you really want to  
see the code behind the scenes, I can share some with you in private.
--
   Andy McKay
   Clearwind Consulting: www.clearwind.ca
   Blog: www.agmweb.ca/blog/andy
   Twitter: twitter.com/clearwind


--~--~-~--~~~---~--~~
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: Permission model's CharField fields, name and codename, too short

2009-03-19 Thread Malcolm Tredinnick

On Thu, 2009-03-19 at 21:58 -0400, Giovannetti, Mark wrote:
> Hi Everyone,
> 
> Has anyone else run across this?  I tried to enter it as
> a ticket at: 
> 
>  http://code.djangoproject.com/simpleticket
> 
> but was mistaken for a spammer.  ;-)

You need to register then, as it says in the big coloured box on that
page.

I was hoping your mail would finish with "so I decided to check if the
ticket was already in Trac and realised it was #8632".

I found that by typing "Django long permission names" into Google and it
was the first link. Please, please, please search before opening
tickets. There's a good chance it's been discovered before.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Map events in space on a django app

2009-03-19 Thread Vasil Vangelovski

If you don't need any spatial related queries (although django people  
uses something like  that) you don't really need a spatial database.  
You can store geographic coordinates in either FloatFields or  
CharFields. Your question is more related to GoogleMaps API than django.

I'm assuming you only need to store points, not lines or shapes.

If you try out some google maps API examples you'll find out it's  
pretty straightforward to let users post geographic coordinates to you  
backend.  Publishing these coordinates on a map is even easier.

I don't think there's anything special in django.contrib.gis that you  
may use. Except if you want to use the geo admin (which is awesome  
btw) in that case you'll need to use a spatial database.

On Mar 20, 2009, at 1:29 AM, Alessandro wrote:

>
> On Fri, Mar 20, 2009 at 12:42 AM, Alex Gaynor  
>  wrote:
>
>>> I thought geo django is too much complex for what I need. I don't  
>>> need
>>> to calculate spatial areas, only to store the gps coordinates of a
>>> point and publish them in a google map, like django people does.
>>>
>
> I'm looking for some documentation, but it seems not too simple.
> it should be very easier if someone shared a sample simple app using
> django.contrib.gis
>
> -- 
> Alessandro Ronchi
> Skype: aronchi
> http://www.alessandroronchi.net
>
> SOASI Soc.Coop. - www.soasi.com
> Sviluppo Software e Sistemi Open Source
> Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
> Tel.: +39 0543 798985 - Fax: +39 0543 579928
>
> Rispetta l'ambiente: se non ti è necessario, non stampare questa mail
>
> >


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Permission model's CharField fields, name and codename, too short

2009-03-19 Thread Giovannetti, Mark

Hi Everyone,

Has anyone else run across this?  I tried to enter it as
a ticket at: 

 http://code.djangoproject.com/simpleticket

but was mistaken for a spammer.  ;-)

Django versions 1.0.x through 1.1 alpha 1, PostgreSQL 8.3.5,
Python 2.5.2

django/contrib/auth/models.py

I have long model names.  I am aware that postgresql has a 128
character limit for tables.  I don't think there is any
practical limit in python to a class name's length.

My problem is:

The definition of the name and codename fields within the
Permission model specify 50 and 100 character limits, 
respectively.

For an app that has a model name of
AgreementGeographicBoundaryApplicability,
the permission name becomes:

Can change agreement geographic boundary applicability

which is 55 characters and generates a database overflow error
(shown below).  I can easily fix this by changing the max_length 
values both to 255 (in the installed source code and the database) 
to overcome this.   Should I be doing this?  If so, can these values
be bumped up in the official release?

I.e. change the Permission class' field definitions to:
{{{
name = models.CharField(_('name'), max_length=255)
content_type = models.ForeignKey(ContentType)
codename = models.CharField(_('codename'), max_length=255)

}}}

running manage.py test
{{{ 
Creating table pdf_...
Permission generation starts next:
Traceback (most recent call last):
  File "manage.py", line 11, in 
execute_manager(settings)
  File
"/usr/local/lib/python2.5/site-packages/django/core/management/__init__.
py", line 350, in execute_manager
utility.execute()
  File
"/usr/local/lib/python2.5/site-packages/django/core/management/__init__.
py", line 295, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File
"/usr/local/lib/python2.5/site-packages/django/core/management/base.py",
line 195, in run_from_argv
self.execute(*args, **options.__dict__)
  File
"/usr/local/lib/python2.5/site-packages/django/core/management/base.py",
line 222, in execute
output = self.handle(*args, **options)
  File
"/usr/local/lib/python2.5/site-packages/django/core/management/commands/
test.py", line 30, in handle
failures = test_runner(test_labels, verbosity=verbosity,
interactive=interactive)
  File "/usr/local/lib/python2.5/site-packages/django/test/simple.py",
line 191, in run_tests
connection.creation.create_test_db(verbosity, autoclobber=not
interactive)
  File
"/usr/local/lib/python2.5/site-packages/django/db/backends/creation.py",
line 316, in create_test_db
call_command('syncdb', verbosity=verbosity, interactive=False)
  File
"/usr/local/lib/python2.5/site-packages/django/core/management/__init__.
py", line 158, in call_command
return klass.execute(*args, **options)
  File
"/usr/local/lib/python2.5/site-packages/django/core/management/base.py",
line 222, in execute
output = self.handle(*args, **options)
  File
"/usr/local/lib/python2.5/site-packages/django/core/management/base.py",
line 351, in handle
return self.handle_noargs(**options)
  File
"/usr/local/lib/python2.5/site-packages/django/core/management/commands/
syncdb.py", line 98, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive)
  File
"/usr/local/lib/python2.5/site-packages/django/core/management/sql.py",
line 205, in emit_post_sync_signal
interactive=interactive)
  File
"/usr/local/lib/python2.5/site-packages/django/dispatch/dispatcher.py",
line 148, in send
response = receiver(signal=self, sender=sender, **named)
  File
"/usr/local/lib/python2.5/site-packages/django/contrib/auth/management/_
_init__.py", line 28, in create_permissions
defaults={'name': name, 'content_type': ctype})
  File
"/usr/local/lib/python2.5/site-packages/django/db/models/manager.py",
line 96, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
  File
"/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line
372, in get_or_create
obj.save(force_insert=True)
  File
"/usr/local/lib/python2.5/site-packages/django/db/models/base.py", line
328, in save
self.save_base(force_insert=force_insert, force_update=force_update)
  File
"/usr/local/lib/python2.5/site-packages/django/db/models/base.py", line
400, in save_base
result = manager._insert(values, return_id=update_pk)
  File
"/usr/local/lib/python2.5/site-packages/django/db/models/manager.py",
line 144, in _insert
return insert_query(self.model, values, **kwargs)
  File
"/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line
1033, in insert_query
return query.execute_sql(return_id)
  File
"/usr/local/lib/python2.5/site-packages/django/db/models/sql/subqueries.
py", line 317, in execute_sql
cursor = super(InsertQuery, self).execute_sql(None)
  File
"/usr/local/lib/python2.5/site-packages/django/db/models/sql/query.py",
line 2020, in execute_sql
cursor.execute(sql, params)
psycopg2.DataError: value too long for type character varying(50)

}}}

Re: Can't import flup.server.fcgi

2009-03-19 Thread coffeepunk


> This has been reported as ticket #10556 earlier today. It will be fixed
> in the next few hours, I suspect. So back up a few versions for now or
> apply the patch in that ticket manually.


Sweet! I've been looking around like crazy, searching on google and
djangoproject but without finding any answer or the ticket. Since I
was on a fresh installed server I was starting to pull my hair,
wondering over why it wouldn't work, but now I know why at least.

Thanks for the Answer Malcom.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Map events in space on a django app

2009-03-19 Thread Alessandro

On Fri, Mar 20, 2009 at 12:42 AM, Alex Gaynor  wrote:

>> I thought geo django is too much complex for what I need. I don't need
>> to calculate spatial areas, only to store the gps coordinates of a
>> point and publish them in a google map, like django people does.
>>

I'm looking for some documentation, but it seems not too simple.
it should be very easier if someone shared a sample simple app using
django.contrib.gis

-- 
Alessandro Ronchi
Skype: aronchi
http://www.alessandroronchi.net

SOASI Soc.Coop. - www.soasi.com
Sviluppo Software e Sistemi Open Source
Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
Tel.: +39 0543 798985 - Fax: +39 0543 579928

Rispetta l'ambiente: se non ti è necessario, non stampare questa mail

--~--~-~--~~~---~--~~
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: Can't import flup.server.fcgi

2009-03-19 Thread Malcolm Tredinnick

On Thu, 2009-03-19 at 16:55 -0700, coffeepunk wrote:
> Heya,
> 
> I'm getting the following error when I try to run the ./manage.py
> funfcgi only or with various options, the result is the same.
> 
> Can't import flup.server.fcgi
> 
> The error occur with 1.1 alpha 1 SVN-10091 and not with 1.1 alpha 1
> SVN-9910 which was the previous version I had installed and now have
> rolled back to. No other versions tested, using Ubuntu LTS 8.04.2.
> Anyone else with the same problem or a possible solution to run Django
> with FastCGI using 1.1 alpha 1 SVN-10091?

This has been reported as ticket #10556 earlier today. It will be fixed
in the next few hours, I suspect. So back up a few versions for now or
apply the patch in that ticket manually.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Crazy error with utf-8 & apache (please help!)

2009-03-19 Thread Ian Kelly

On Mar 19, 4:55 pm, elm  wrote:
> I have bee trying to deal with an erratic error for the last 3 day. I
> hope you can rescue me!!!
>
> After experiencing erratic errors that appeared from time to time on a
> larger project (i.e. ViewDoesNotExist) I have reduced my project to a
> very simple application that runs on apache with mod_python and
> connects to Oracle via cx_oracle (4.3).
>
> after reloading apache I get the following error:
>
> 
> TemplateSyntaxError at /test/
>
> Caught an exception while rendering: 'utf8' codec can't decode bytes
> in position 3-4: invalid data. You passed in 'OTO\xd1O' ()

Indeed, that's the latin1 encoding of 'OTOÑO', not utf8.  Maybe Oracle
is getting somehow getting the client encoding confused.  Try setting
the environment variable NLS_LANG = '.UTF8' for the Apache process.

HTH,
Ian
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Can't import flup.server.fcgi

2009-03-19 Thread coffeepunk

Heya,

I'm getting the following error when I try to run the ./manage.py
funfcgi only or with various options, the result is the same.

Can't import flup.server.fcgi

The error occur with 1.1 alpha 1 SVN-10091 and not with 1.1 alpha 1
SVN-9910 which was the previous version I had installed and now have
rolled back to. No other versions tested, using Ubuntu LTS 8.04.2.
Anyone else with the same problem or a possible solution to run Django
with FastCGI using 1.1 alpha 1 SVN-10091?

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
-~--~~~~--~~--~--~---



Re: Using _default_manager in a model causes many idle MySQL connections. (Django 1.0)

2009-03-19 Thread MikeL

I wasn't sure where this stuff was being tracked, but I did find a
circular reference in the database wrapper. The DatabaseCreation and
DatabaseIntrospection objects being created in the MySQL wrapper where
passing references of itself, but there wasn't a per-defined method
for removing those references.

Should BaseDatabaseIntrospection and BaseDatabaseCreation be holding a
weakref of the database wrapper instead?
Or is there some connection pooling system that needs to be aware of
the Mulit-db stuff?
Does any of this seem sane?

My _hack_ (temp and not perfect I know) involved a class wrapping
around QuerySet and monitoring the clone counts (split per wrapper
instance) so when the final QuerySet was deleted it would clear the
two references allowing the database wrapper to be garbage collected.

TIA,

Michael LaRue

On Mar 19, 2:10 pm, Alex Gaynor  wrote:
> On Thu, Mar 19, 2009 at 5:06 PM, MikeL  wrote:
>
> > I'm using the code from:
>
> >http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/
>
> > After repeated use, there can be over a hundred idling connection to
> > MySQL for both production and development builds. Removing the
> > Multiple DB in the model causes the symptoms to stop.
>
> > I've been trying to track down where the circular reference (if it's
> > that) is causing the connections to not be closed/deleted without much
> > luck. Is this use of _default_manager just plain flawed? If not, does
> > anyone know if there is a working fix?
>
> > TIA,
>
> > Michael LaRue
>
> It's not a default manager issue, the issue is by default django closes the
> connection at the end of the request, but it only tracks the default
> connection, so your cusotm multidb support isn't tracked.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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: Map events in space on a django app

2009-03-19 Thread Alex Gaynor
On Thu, Mar 19, 2009 at 7:41 PM, Alessandro wrote:

>
> On Thu, Mar 19, 2009 at 9:08 PM, Alex Gaynor 
> wrote:
>
> > Geo Django has a lot of tools for working with maps and geographic data,
> you might want to look at it: http://geodjango.org/ .
> >
>
> I thought geo django is too much complex for what I need. I don't need
> to calculate spatial areas, only to store the gps coordinates of a
> point and publish them in a google map, like django people does.
>
>
> --
> Alessandro Ronchi
> Skype: aronchi
> http://www.alessandroronchi.net
>
> SOASI Soc.Coop. - www.soasi.com
> Sviluppo Software e Sistemi Open Source
> Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
> Tel.: +39 0543 798985 - Fax: +39 0543 579928
>
> Rispetta l'ambiente: se non ti è necessario, non stampare questa mail
>
> >
>
Well, you can always just use a pair of float fields to store the latitude
and longitude and then write some javascript to interact with google maps.
But django.contrib.gis comes with Django so, in my view, there aren't many
good reasons not to use it.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: Map events in space on a django app

2009-03-19 Thread Alessandro

On Thu, Mar 19, 2009 at 9:08 PM, Alex Gaynor  wrote:

> Geo Django has a lot of tools for working with maps and geographic data, you 
> might want to look at it: http://geodjango.org/ .
>

I thought geo django is too much complex for what I need. I don't need
to calculate spatial areas, only to store the gps coordinates of a
point and publish them in a google map, like django people does.


--
Alessandro Ronchi
Skype: aronchi
http://www.alessandroronchi.net

SOASI Soc.Coop. - www.soasi.com
Sviluppo Software e Sistemi Open Source
Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
Tel.: +39 0543 798985 - Fax: +39 0543 579928

Rispetta l'ambiente: se non ti è necessario, non stampare questa mail

--~--~-~--~~~---~--~~
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: customizing admin interface: showing descriptive names for objects

2009-03-19 Thread Alex Gaynor
On Thu, Mar 19, 2009 at 7:36 PM, Nate Reed  wrote:

> On Thu, Mar 19, 2009 at 4:29 PM, Alex Gaynor wrote:
>
>>
>>
>> On Thu, Mar 19, 2009 at 7:21 PM, Nate Reed wrote:
>>
>>> I'm working on an admin interface for my app, and wondering how to
>>> customize what gets displayed.
>>>
>>> Under Home->MyModels->MyModels, MyModel instances are listed as "MyModel
>>> object."  When editing another model, the foreign key reference to MyModel
>>> gets displayed as a list of:
>>>
>>> MyModel object
>>> MyModel object
>>> 
>>> etc
>>>
>>> I'd like it to make it show MyModel.name instead.  How is this changed?
>>>
>>> Nate
>>>
>>>
>>>
>> Using the __unicode__ method on models.  If you read through the tutorial
>> you'll see how this works.
>>
>> Alex
>>
>
> Thanks.
>
> There's no mention of it in the section on the admin site.  Is __unicode__
> used for anything else?
>
>
>
>
> >
>
__unicode__ is used for almost every default display of an object.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: customizing admin interface: showing descriptive names for objects

2009-03-19 Thread Nate Reed
On Thu, Mar 19, 2009 at 4:29 PM, Alex Gaynor  wrote:

>
>
> On Thu, Mar 19, 2009 at 7:21 PM, Nate Reed  wrote:
>
>> I'm working on an admin interface for my app, and wondering how to
>> customize what gets displayed.
>>
>> Under Home->MyModels->MyModels, MyModel instances are listed as "MyModel
>> object."  When editing another model, the foreign key reference to MyModel
>> gets displayed as a list of:
>>
>> MyModel object
>> MyModel object
>> 
>> etc
>>
>> I'd like it to make it show MyModel.name instead.  How is this changed?
>>
>> Nate
>>
>>
>>
> Using the __unicode__ method on models.  If you read through the tutorial
> you'll see how this works.
>
> Alex
>

Thanks.

There's no mention of it in the section on the admin site.  Is __unicode__
used for anything else?

--~--~-~--~~~---~--~~
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: customizing admin interface: showing descriptive names for objects

2009-03-19 Thread Alex Gaynor
On Thu, Mar 19, 2009 at 7:21 PM, Nate Reed  wrote:

> I'm working on an admin interface for my app, and wondering how to
> customize what gets displayed.
>
> Under Home->MyModels->MyModels, MyModel instances are listed as "MyModel
> object."  When editing another model, the foreign key reference to MyModel
> gets displayed as a list of:
>
> MyModel object
> MyModel object
> 
> etc
>
> I'd like it to make it show MyModel.name instead.  How is this changed?
>
> Nate
>
> >
>
Using the __unicode__ method on models.  If you read through the tutorial
you'll see how this works.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: form.save_m2m and intermediary models

2009-03-19 Thread Delta20

On Mar 19, 6:50 pm, Malcolm Tredinnick 
wrote:
> The error is telling you exactly what the problem is. You can't do the
> automatic assignment to many-to-many relations that use an intermediate
> table. The reason being that the whole point of an intermediate table is
> that it has *extra* information specified on it (otherwise you could
> just use a normal ManyToManyField). So you need to create objects with
> that extra information and save then explicitly.
>
> Short version is you can't use save_m2m() in that case for precisely
> this reason. You'll need to extract out the necessary data from the
> form, and save it on the intermediate model.

In this case, all I need is the post_save signal for when the m2m is
saved. The reason being is that I have Ticket.do_stuff in the example
above computes the value of a field in Ticket and the value depends on
what what Systems are related.

Is there a way I can achieve that without a custom intermediate model?
Manually invoking a method to do this doesn't work because that would
break in cases like modifying things in admin.




--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



customizing admin interface: showing descriptive names for objects

2009-03-19 Thread Nate Reed
I'm working on an admin interface for my app, and wondering how to customize
what gets displayed.

Under Home->MyModels->MyModels, MyModel instances are listed as "MyModel
object."  When editing another model, the foreign key reference to MyModel
gets displayed as a list of:

MyModel object
MyModel object

etc

I'd like it to make it show MyModel.name instead.  How is this changed?

Nate

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Crazy error with utf-8 & apache (please help!)

2009-03-19 Thread elm

I have bee trying to deal with an erratic error for the last 3 day. I
hope you can rescue me!!!

After experiencing erratic errors that appeared from time to time on a
larger project (i.e. ViewDoesNotExist) I have reduced my project to a
very simple application that runs on apache with mod_python and
connects to Oracle via cx_oracle (4.3).

after reloading apache I get the following error:


TemplateSyntaxError at /test/

Caught an exception while rendering: 'utf8' codec can't decode bytes
in position 3-4: invalid data. You passed in 'OTO\xd1O' ()
...

After refreshing the browser page a few times the error disappears the
the template displays correctly (a list of words, some of which are in
spanish).  After that the error reappears form time to time.

I guess that the database is sending the data in a non UTF8 format
when the error appears, but I can not understand:

-  Why it happens sometimes and not always?
-  If it is a problem with oracle (or cx_oracle) why is it manifested
afer reloading apache?

PLEASE help me with any idea or suggestion!!

I am using
Redhat ES release 4 U7
Apache 2.0.52-41.ent.2
python 2.3
django1.0
mod_python 3.2.1
cx_oracle 4.4

These are my basic models/views/templates:

prueba1.models.py
-
from django.db import models

class PeriodosAcademicos(models.Model):
  peri_ccod= models.IntegerField(db_column='PERI_CCOD',
primary_key=True)
  peri_tdesc = models.CharField(max_length=100,
db_column='PERI_TDESC')
  class Meta:
db_table = 'PERIODOS_ACADEMICOS'

prueba1.views.py
---
from prueba1.models import PeriodosAcademicos
from django.shortcuts import render_to_response

def test(request):
  periods = PeriodosAcademicos.objects.all()
  return render_to_response('test.html',{'periods':periods})

prueba1/templates/test.html
-
Test
{% for period in periods %}
{{period.peri_tdesc}}
{% endfor %}

This is the full error transcript:
TemplateSyntaxError at /test/

Caught an exception while rendering: 'utf8' codec can't decode bytes
in position 3-4: invalid data. You passed in 'OTO\xd1O' ()

Original Traceback (most recent call last):
  File "/usr/lib/python2.3/site-packages/django/template/debug.py",
line 71, in render_node
result = node.render(context)
  File "/usr/lib/python2.3/site-packages/django/template/
defaulttags.py", line 123, in render
len_values = len(values)
  File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
line 154, in __len__
self._result_cache = list(self.iterator())
  File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
line 269, in iterator
for row in self.query.results_iter():
  File "/usr/lib/python2.3/site-packages/django/db/models/sql/
query.py", line 206, in results_iter
for rows in self.execute_sql(MULTI):
  File "/usr/lib/python2.3/site-packages/django/db/models/sql/
query.py", line 1714, in 
result = iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
  File "/usr/lib/python2.3/site-packages/django/db/backends/oracle/
base.py", line 400, in fetchmany
return tuple([tuple([to_unicode(e) for e in r]) for r in
Database.Cursor.fetchmany(self, size)])
  File "/usr/lib/python2.3/site-packages/django/db/backends/oracle/
base.py", line 411, in to_unicode
return force_unicode(s)
  File "/usr/lib/python2.3/site-packages/django/utils/encoding.py",
line 70, in force_unicode
raise DjangoUnicodeDecodeError(s, *e.args)
DjangoUnicodeDecodeError: 'utf8' codec can't decode bytes in position
3-4: invalid data. You passed in 'OTO\xd1O' ()

Request Method: GET
Request URL:http://172.16.110.42/test/
Exception Type: TemplateSyntaxError
Exception Value:

Caught an exception while rendering: 'utf8' codec can't decode bytes
in position 3-4: invalid data. You passed in 'OTO\xd1O' ()

Original Traceback (most recent call last):
  File "/usr/lib/python2.3/site-packages/django/template/debug.py",
line 71, in render_node
result = node.render(context)
  File "/usr/lib/python2.3/site-packages/django/template/
defaulttags.py", line 123, in render
len_values = len(values)
  File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
line 154, in __len__
self._result_cache = list(self.iterator())
  File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
line 269, in iterator
for row in self.query.results_iter():
  File "/usr/lib/python2.3/site-packages/django/db/models/sql/
query.py", line 206, in results_iter
for rows in self.execute_sql(MULTI):
  File "/usr/lib/python2.3/site-packages/django/db/models/sql/
query.py", line 1714, in 
result = iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
  File "/usr/lib/python2.3/site-packages/django/db/backends/oracle/
base.py", line 400, in fetchmany
return tuple([tuple([to_unicode(e) for e in r]) for r in
Database.Cursor.fetchmany(self, size)])
  File "/usr/lib/python2.3/site-packages/django/db/backends/oracle/
base.py", line

Re: form.save_m2m and intermediary models

2009-03-19 Thread Malcolm Tredinnick

On Thu, 2009-03-19 at 14:21 -0700, Delta20 wrote:
> I'm getting the error "Cannot set values on a ManyToManyField which
> specifies an intermediary model." when I try to call form.save_m2m()
> and I would appreciate any tips as to how to work around this.

The error is telling you exactly what the problem is. You can't do the
automatic assignment to many-to-many relations that use an intermediate
table. The reason being that the whole point of an intermediate table is
that it has *extra* information specified on it (otherwise you could
just use a normal ManyToManyField). So you need to create objects with
that extra information and save then explicitly.

Short version is you can't use save_m2m() in that case for precisely
this reason. You'll need to extract out the necessary data from the
form, and save it on the intermediate model.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: accessing related fields of model

2009-03-19 Thread Malcolm Tredinnick

On Thu, 2009-03-19 at 13:20 -0700, adrian wrote:
> 
> The doc gives this example for querying an Entry model which has a
> foreign key field to a Blog model.
> 
> e = Entry.objects.get(id=2)
> e.blog = some_blog
> 
> Fine.  Now if I do it in a loop like this:
> 
> e = Entry.objects.all()
> for entry in e:
> entry.blog = some_blog
> #do stuff here with Entry and Blog
> 
> My question is, would this create a lot of SQL statements?   When does
> Django query the
> foreign key field?   Does it get all the blog entries at once with the
> Entry.objects.all() query,
> or does it do it one by one in the loop?

It does it one by one because Python and Django have a limitation in
that they cannot predict the future. When processing entry.blog the
first time around, it doesn't know that you will be wanting to access
another entry.blog (for a different entry). The Entry.objects.all()
query only retrieves Entry objects, not all the related objects.

The example is a little contrived, since you wouldn't normally work like
that if you had a *lot* of entries. On the other hand, for a small
number of entries, even one SQL query per time around the loop simply
isn't that horrible.

> 
> How would I do that efficiently because I need to create a single dict
> from the value of my model and all its foreign key models, so that I
> can serialize it for Ajax?

I'd start by reading the documentation. All of it, so that you know what
is possible. That isn't intended to be rude, but we do put a lot of time
into documenting this stuff. If you're up to the point of trying to
optimise things at this level, it's reasonable to hope that you've read
as much of the documentation as you can get your hands on it.

In particular, have a look at select_related(), which is designed for
exactly this purpose. In other cases, you can often reduce the number of
queries by turning things around and, say, querying on blogs rather than
entries (for some different style of query construction).

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic app_label

2009-03-19 Thread Malcolm Tredinnick

On Thu, 2009-03-19 at 12:53 -0700, Dan wrote:
> Hi all,
> 
> Is there a way to set app_label in the model Meta class dynamically?
> I'm trying to break up my models into separate files which now (as I
> understand) requires that each model specify it's app explicitly.
> However, I'd like to have my __init__.py in my models package handle
> this for me.

Not really, no. The app_label is processed when the file is imported
(because that's when the Model's __new__ method is run).

The proper solution here is for Django to work out the app_label more
appropriately in the automatic case -- perhaps walking up the module
tree until it hits something an app name. Fixing the real problem
correctly would be a better use of your time than trying to hack it like
this, I suspect (plus -- added bonus -- helping everybody). Note that
when people have tried to do this in the past, they've always forgotten
that directories can be nested to arbitrary levels and only allowed one
extra directory level, which isn't acceptable.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: accessing related fields of model

2009-03-19 Thread Daniel Roseman

On Mar 19, 8:20 pm, adrian  wrote:
> The doc gives this example for querying an Entry model which has a
> foreign key field to a Blog model.
>
> e = Entry.objects.get(id=2)
> e.blog = some_blog
>
> Fine.  Now if I do it in a loop like this:
>
> e = Entry.objects.all()
> for entry in e:
>     entry.blog = some_blog
>     #do stuff here with Entry and Blog
>
> My question is, would this create a lot of SQL statements?   When does
> Django query the
> foreign key field?   Does it get all the blog entries at once with the
> Entry.objects.all() query,
> or does it do it one by one in the loop?
>
> How would I do that efficiently because I need to create a single dict
> from the value of my model and all its foreign key models, so that I
> can serialize it for Ajax?
>
> Thanks

Yes, as written it would create an SQL statement for each Entry
object.

The solution - which is documented - is to use select_related when
getting the entry options. This follows the relation and prepopulates
the blog object:
e = Entry.objects.select_related().all()
See http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4

By the way, if you're concerned about how many queries your ORM code
is generating, you can use the tip here to see them:
http://docs.djangoproject.com/en/dev/faq/models/#how-can-i-see-the-raw-sql-queries-django-is-running
--
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-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: Signals, sites and instances

2009-03-19 Thread TiNo
You could do this in the save method. If the News_item is newly created,
it's id will not be set, so to assure it only happens on creation, you could
use this code:

if self.id is None:
do your stuff...

Tino

On Thu, Mar 19, 2009 at 6:19 PM, Baxter  wrote:

>
> Talking with Andy more on IRC, it looks like I can't do what I want to
> do, unless maybe there's some way to pass the request on to the signal.
>  >
>

--~--~-~--~~~---~--~~
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: hashed file name on ImageField

2009-03-19 Thread Chris Van Horne

Seems I found a way around this by overriding the 'save' method on the
model which has the ImageField.

On Mar 19, 1:11 pm, Chris Van Horne  wrote:
> Hello,
>
> I am looking to modify ImageField so that the filename saved to disk
> is a hashed (sha1 or md5) digest. I have looked at the documentation
> and it seemed to point me towards subclassing
> django.core.files.storage.Storage but I haven't had any luck--worse,
> I'm not sure if this is the "correct" way to do this.
>
> What would be the best way to go about achieving this functionality?
--~--~-~--~~~---~--~~
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: form.save_m2m and intermediary models

2009-03-19 Thread Delta20

I forgot to add: the full error message is:

"Cannot set values on a ManyToManyField which specifies an
intermediary model.  Use SystemTicket's Manager instead."

I'm not sure how I'd use the manager in this particular case though.


On Mar 19, 5:21 pm, Delta20  wrote:
> I'm getting the error "Cannot set values on a ManyToManyField which
> specifies an intermediary model." when I try to call form.save_m2m()
> and I would appreciate any tips as to how to work around this.
>
> Here's some code that illustrates what I am doing:
>
> ---
> # Using a basic form in a view function:
>
> ticket = form.save(commit=False)
> ticket.save()
> form.save_m2m() # this does not work
>
> ---
> # in models.py:
>
> class System(models.Model):
>     # fields omitted for brevity
>
> class Ticket(models.Model):
>     systems = models.ManyToManyField(System, through='SystemTicket')
>
>     def do_stuff(self):
>         # Do some stuff that has to happen after m2m
>
> # custom m2m so we can act on the post_save signal
> class SystemTicket(models.Model):
>     ticket = models.ForeignKey(Ticket)
>     system = models.ForeignKey(System)
>
> def update_stuff(instance, **kwargs):
>     instance.ticket.do_stuff()
>     instance.ticket.save()
>
> post_save.connect(update_stuff, sender=SystemTicket)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



form.save_m2m and intermediary models

2009-03-19 Thread Delta20

I'm getting the error "Cannot set values on a ManyToManyField which
specifies an intermediary model." when I try to call form.save_m2m()
and I would appreciate any tips as to how to work around this.

Here's some code that illustrates what I am doing:

---
# Using a basic form in a view function:

ticket = form.save(commit=False)
ticket.save()
form.save_m2m() # this does not work

---
# in models.py:

class System(models.Model):
# fields omitted for brevity

class Ticket(models.Model):
systems = models.ManyToManyField(System, through='SystemTicket')

def do_stuff(self):
# Do some stuff that has to happen after m2m

# custom m2m so we can act on the post_save signal
class SystemTicket(models.Model):
ticket = models.ForeignKey(Ticket)
system = models.ForeignKey(System)

def update_stuff(instance, **kwargs):
instance.ticket.do_stuff()
instance.ticket.save()

post_save.connect(update_stuff, sender=SystemTicket)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Error of Bad file descriptor

2009-03-19 Thread arbi

Hi,

I use geopy (a python module)  that geocodes addresses. It works on my
computer, but badly on internet. I don't know why. I got a "Bad file
descriptor" errors sometimes.

Here is my traceback :

Environment:

Request Method: POST
Request URL: http://antrive.alwaysdata.net/routes/index/result/
Django Version: 1.0.2 final
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'antrive.routes']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/var/lib/python/django/1.0.2/django/core/handlers/base.py" in
get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "/home/antrive/www/antrive/routes/views.py" in route_result
  195.  address_object = render_route_dict_elements (departure,
arrival, key)
File "/home/antrive/www/antrive/routes/func.py" in
render_route_dict_elements
  26.   addressNormalizedObject = 
AddressNormalizedObject(address_dict
[address][0], gkey)
File "/home/antrive/www/antrive/routes/routeClasses.py" in __init__
  32.   addLatLng_list = list(gmaps_geocoder.geocode(self.address,
exactly_one=False)) # get normalized tuple (address, (lat, lng)) from
Google
File "/home/antrive/www/modules/geopy/geocoders_old.py" in geocode
  328. return self.geocode_url(url, exactly_one)
File "/home/antrive/www/modules/geopy/geocoders_old.py" in geocode_url
  331. print "Fetching %s..." % url

Exception Type: IOError at /routes/index/result/
Exception Value: [Errno 9] Bad file descriptor


Thanks for help :)
Arbi
--~--~-~--~~~---~--~~
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: Using _default_manager in a model causes many idle MySQL connections. (Django 1.0)

2009-03-19 Thread Alex Gaynor
On Thu, Mar 19, 2009 at 5:06 PM, MikeL  wrote:

>
> I'm using the code from:
>
> http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/
>
> After repeated use, there can be over a hundred idling connection to
> MySQL for both production and development builds. Removing the
> Multiple DB in the model causes the symptoms to stop.
>
> I've been trying to track down where the circular reference (if it's
> that) is causing the connections to not be closed/deleted without much
> luck. Is this use of _default_manager just plain flawed? If not, does
> anyone know if there is a working fix?
>
> TIA,
>
> Michael LaRue
>
> >
>
It's not a default manager issue, the issue is by default django closes the
connection at the end of the request, but it only tracks the default
connection, so your cusotm multidb support isn't tracked.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Using _default_manager in a model causes many idle MySQL connections. (Django 1.0)

2009-03-19 Thread MikeL

I'm using the code from:

http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/

After repeated use, there can be over a hundred idling connection to
MySQL for both production and development builds. Removing the
Multiple DB in the model causes the symptoms to stop.

I've been trying to track down where the circular reference (if it's
that) is causing the connections to not be closed/deleted without much
luck. Is this use of _default_manager just plain flawed? If not, does
anyone know if there is a working fix?

TIA,

Michael LaRue

--~--~-~--~~~---~--~~
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: Django-Tagging not working with Oracle

2009-03-19 Thread Ian Kelly

On Mar 19, 9:21 am, Brandon Taylor  wrote:
> Hi Everyone,
>
> I'm using the svn checkout of Django-Tagging and Django-Trunk. Tagging
> is working perfectly for me with any other database except, of course,
> Oracle, which is what I need it to work in.
>
> I can't get the TagField() to show up in the admin at all without
> adding a custom form for my ModelAdmin class, and when I do, it won't
> populate the Tags table.

This is working correctly for me with the same setup.  Can you come up
with a simple test case that exhibits the problem?

Regards,
Ian
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



hashed file name on ImageField

2009-03-19 Thread Chris Van Horne

Hello,

I am looking to modify ImageField so that the filename saved to disk
is a hashed (sha1 or md5) digest. I have looked at the documentation
and it seemed to point me towards subclassing
django.core.files.storage.Storage but I haven't had any luck--worse,
I'm not sure if this is the "correct" way to do this.

What would be the best way to go about achieving this functionality?

--~--~-~--~~~---~--~~
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: Guys, anyone get working Firebird database backend?

2009-03-19 Thread mariuz



On Mar 17, 5:07 am, brawaga  wrote:
> Guys, who even got Django-to-Firebirddatabase backend working, or
> knows how to, tell me please, how I can retrieve valid one? Maybe,
> there is guru who knows a common structure of the backend? In this
> case I can write it myself, maybe. I am finally tired out making
> cripplings to existing backend, but, now it can only support basic
> model functionality, such as queries with joins. I can not carry on.
> DjangoAdmin is not working, and, also, slicing. I am very disappointed
> and do not know what to do. Queries django constructs for slicing
> contains LIMIT word at the end, like for SQLite, not FIRST word after
> SELECT, which is needed byFirebird. I only need about 12 first
> records from about several thousands. All data is being queried so
> long... Help me, please!
>
> P.S. I use Django 1.0,FireBird2.0, Python 2.5.2.
>
> P.P.S. I googled, triedhttp://code.djangoproject.com/ticket/1261, but
> unsuccessfully.

I started to use the book examples with the pre 1.0 version I will
upgrade later to 1.0 and then 1.1
http://firebirdnews.blogspot.com/2009/03/django-and-firebird-support.html
I will create an branch in bzr in ubuntu and try to make it work with
1.0/1.1
could you make an list of things that do not work yet and with
examples ...

ps: for the moment i'm happy that the very basic things works with
firebird 2.1 so I will check the more advaced stuff
also i'm an python beginner (<21 days) so it will be slower
until now i'm very excited about the book and i can't stop finishing
until the end :)


--~--~-~--~~~---~--~~
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: accessing related fields of model

2009-03-19 Thread adrian

I found a serializer that can follow foreign key fields, which solves
my problem.

http://code.google.com/p/wadofstuff/wiki/DjangoFullSerializers

But I would still like
to understand if someone cares to answer!   I think this should be in
the documentation also.

On Mar 19, 3:20 pm, adrian  wrote:
> The doc gives this example for querying an Entry model which has a
> foreign key field to a Blog model.
>
> e = Entry.objects.get(id=2)
> e.blog = some_blog
>
> Fine.  Now if I do it in a loop like this:
>
> e = Entry.objects.all()
> for entry in e:
>     entry.blog = some_blog
>     #do stuff here with Entry and Blog
>
> My question is, would this create a lot of SQL statements?   When does
> Django query the
> foreign key field?   Does it get all the blog entries at once with the
> Entry.objects.all() query,
> or does it do it one by one in the loop?
>
> How would I do that efficiently because I need to create a single dict
> from the value of my model and all its foreign key models, so that I
> can serialize it for Ajax?
>
> 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
-~--~~~~--~~--~--~---



accessing related fields of model

2009-03-19 Thread adrian


The doc gives this example for querying an Entry model which has a
foreign key field to a Blog model.

e = Entry.objects.get(id=2)
e.blog = some_blog

Fine.  Now if I do it in a loop like this:

e = Entry.objects.all()
for entry in e:
entry.blog = some_blog
#do stuff here with Entry and Blog

My question is, would this create a lot of SQL statements?   When does
Django query the
foreign key field?   Does it get all the blog entries at once with the
Entry.objects.all() query,
or does it do it one by one in the loop?

How would I do that efficiently because I need to create a single dict
from the value of my model and all its foreign key models, so that I
can serialize it for Ajax?

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
-~--~~~~--~~--~--~---



Re: Map events in space on a django app

2009-03-19 Thread Alex Gaynor
On Thu, Mar 19, 2009 at 4:07 PM, Alessandro Ronchi <
alessandro.ron...@soasi.com> wrote:

> I need to make a website that permits users to put warnings of dangerous
> points in a city map.
>
> Users should drag a signal on a street map and put text of the warning, and
> then send them to the server.
>
> The site should presents them in a navigable map, like it does
> http://djangopeople.net/
>
> is there any snippet or sample code to do the same?
>
> --
> Alessandro Ronchi
> Skype: aronchi
> http://www.alessandroronchi.net
>
> SOASI Soc.Coop. - www.soasi.com
> Sviluppo Software e Sistemi Open Source
> Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
> Tel.: +39 0543 798985 - Fax: +39 0543 579928
>
> Rispetta l'ambiente: se non ti è necessario, non stampare questa mail
>
> >
>
Geo Django has a lot of tools for working with maps and geographic data, you
might want to look at it: http://geodjango.org/ .

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Map events in space on a django app

2009-03-19 Thread Alessandro Ronchi
I need to make a website that permits users to put warnings of dangerous
points in a city map.

Users should drag a signal on a street map and put text of the warning, and
then send them to the server.

The site should presents them in a navigable map, like it does
http://djangopeople.net/

is there any snippet or sample code to do the same?

-- 
Alessandro Ronchi
Skype: aronchi
http://www.alessandroronchi.net

SOASI Soc.Coop. - www.soasi.com
Sviluppo Software e Sistemi Open Source
Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
Tel.: +39 0543 798985 - Fax: +39 0543 579928

Rispetta l'ambiente: se non ti è necessario, non stampare questa mail

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Dynamic app_label

2009-03-19 Thread Dan

Hi all,

Is there a way to set app_label in the model Meta class dynamically?
I'm trying to break up my models into separate files which now (as I
understand) requires that each model specify it's app explicitly.
However, I'd like to have my __init__.py in my models package handle
this for me.

Example:

/project
   /core
  /models
 __init__.py
 blog.py

-- __init__.py: --
from blog import *
for model in locals.values():
if inspect.isclass(model) and issubclass(model, models.Model):
model._meta.app_label = 'core'


Thanks,
Dan
--~--~-~--~~~---~--~~
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: custom validation (clean_) based on image height and width

2009-03-19 Thread Michael A. Repucci
Perfect. Thank you!


On Thu, Mar 19, 2009 at 3:36 PM, Alex Gaynor  wrote:

>
>
> On Thu, Mar 19, 2009 at 3:31 PM, Michael Repucci wrote:
>
>>
>> I'm struggling with what seems like should be a very straightforward
>> task. I have a model with a field named image of type ImageField, and
>> I'd like to do custom validation via the model form's clean_image
>> method based on the height and width (in pixels) of the image.
>>
>> If I just grab the image object from the cleaned_data dictionary it
>> doesn't have attributes height and width, and if I specify the
>> height_field and width_field parameters in the ImageField
>> instantiation, I don't have access to those fields from the
>> clean_image method (or do I?).
>>
>> Is there a simple way to do this that I'm missing?
>>
>>
> Yep, here's an example of a method I use:
>
> def clean_image(self):
> from django.core.files.images import get_image_dimensions
> w, h = get_image_dimensions(self.cleaned_data['image'])
> if h > 500 or w > 800:
> raise forms.ValidationError("The image is too large, the
> maximum size is 800x500, your image was %sx%s." % (w, h))
> return self.cleaned_data['image']
>
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
>
> >
>

--~--~-~--~~~---~--~~
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: custom validation (clean_) based on image height and width

2009-03-19 Thread Alex Gaynor
On Thu, Mar 19, 2009 at 3:31 PM, Michael Repucci wrote:

>
> I'm struggling with what seems like should be a very straightforward
> task. I have a model with a field named image of type ImageField, and
> I'd like to do custom validation via the model form's clean_image
> method based on the height and width (in pixels) of the image.
>
> If I just grab the image object from the cleaned_data dictionary it
> doesn't have attributes height and width, and if I specify the
> height_field and width_field parameters in the ImageField
> instantiation, I don't have access to those fields from the
> clean_image method (or do I?).
>
> Is there a simple way to do this that I'm missing?
> >
>
Yep, here's an example of a method I use:

def clean_image(self):
from django.core.files.images import get_image_dimensions
w, h = get_image_dimensions(self.cleaned_data['image'])
if h > 500 or w > 800:
raise forms.ValidationError("The image is too large, the maximum
size is 800x500, your image was %sx%s." % (w, h))
return self.cleaned_data['image']


-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: Django form: Allow user to insert a date in dd-mm-yyyy format and then convert in yyyy-mm-dd

2009-03-19 Thread Adi Sieker

On 18.03.2009, at 20:48, MarcoS wrote:

>
> Thanks for your replies, Koeb and Ady.
>
> Ady, if I understood I've to place the code from
>
> http://code.djangoproject.com/attachment/ticket/3672/ticket%233672--patch-test.diff
>
> to
>
> - python/site-packages/django/forms/forms.py and
> - python/site-packages/django/forms/widgets.py
>
Yes, basically.


> and then I call the form with the follow field:
>
> date = forms.DateField(widget=DateTextInput(format='d/m/y'),
> input_formats=['%d/%m/%y'])
>
> It's correct?
>

In the diff file there are some regression tests which show you how to  
use the Fields.

adi


> On 18 Mar, 13:45, Adi Sieker  wrote:
>> Hi,
>>
>> On 18.03.2009, at 13:01, MarcoS wrote:
>>
>>
>>
>>> Hi Adi, thanks for your reply!
>>
>>> I had just tried the DateField.input_formats, but the problem was  
>>> that
>>> I'm using the date admin widgets.
>>> If I specify input_formats like: '%d.%m.%y', I can't use the admin
>>> widgets 'cause it insert the date in the format: '%Y-%m-%d' (how you
>>> can see in django/contrib/admin/media/js/admin/DateTimeShortcuts.js
>>> line 239)...
>>
>> The Problem with the Admin is that the DateField doesn't respect any
>> output formats.
>> Check this ticket for a possible 
>> solution:http://code.djangoproject.com/ticket/3672
>>
>> adi
>>
>> --
>> Adi J. Sieker mobile: +49 - 178 - 88 5 88 13
>> Freelance developer   skype:  adijsieker
>> SAP-Consultantweb:http://www.sieker.info/profile
>>openbc:https://www.openbc.com/hp/
>> AdiJoerg_Sieker/
> 
--
Adi J. Sieker mobile: +49 - 178 - 88 5 88 13
Freelance developer   skype:  adijsieker
SAP-Consultantweb:http://www.sieker.info/profile
   openbc: https://www.openbc.com/hp/ 
AdiJoerg_Sieker/




--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



custom validation (clean_) based on image height and width

2009-03-19 Thread Michael Repucci

I'm struggling with what seems like should be a very straightforward
task. I have a model with a field named image of type ImageField, and
I'd like to do custom validation via the model form's clean_image
method based on the height and width (in pixels) of the image.

If I just grab the image object from the cleaned_data dictionary it
doesn't have attributes height and width, and if I specify the
height_field and width_field parameters in the ImageField
instantiation, I don't have access to those fields from the
clean_image method (or do I?).

Is there a simple way to do this that I'm missing?
--~--~-~--~~~---~--~~
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: admin: search generic relation?

2009-03-19 Thread patrickk

hmmm, what about defining a custom search_method? is that possible?
maybe with using a Custom Manager?



On 19 Mrz., 19:59, Alex Gaynor  wrote:
> On Thu, Mar 19, 2009 at 12:37 PM, patrickk  wrote:
>
> > is there any way to search for a "content_object" within the change-
> > list?
>
> > my model:
>
> > class Trailer(models.Model):
> >    ...
> >    content_type = models.ForeignKey(ContentType)
> >    object_id = models.PositiveIntegerField()
> >    content_object = generic.GenericForeignKey()
> >    ...
>
> > now, I´d like to do something like:
>
> > class TrailerOptions(admin.ModelAdmin):
> >    ...
> >    search_fields = ('content_object',)
> >    ...
>
> > this obviously doesn´t work ... are there any workarounds?
>
> > thanks,
> > patrick
>
> Not really, but that's because there's no way to preform that query at the
> database level.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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: admin: search generic relation?

2009-03-19 Thread Alex Gaynor
On Thu, Mar 19, 2009 at 12:37 PM, patrickk  wrote:

>
> is there any way to search for a "content_object" within the change-
> list?
>
> my model:
>
> class Trailer(models.Model):
>...
>content_type = models.ForeignKey(ContentType)
>object_id = models.PositiveIntegerField()
>content_object = generic.GenericForeignKey()
>...
>
> now, I´d like to do something like:
>
> class TrailerOptions(admin.ModelAdmin):
>...
>search_fields = ('content_object',)
>...
>
> this obviously doesn´t work ... are there any workarounds?
>
> thanks,
> patrick
>
> >
>
Not really, but that's because there's no way to preform that query at the
database level.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: update facebook status

2009-03-19 Thread Baxter

On Mar 19, 1:34 pm, "Shantanoo Mahajan (शंतनू महाजन)"
 wrote:

> you may 
> findhttp://wiki.developers.facebook.com/index.php/PythonPyFacebookTutorial
>   useful.


thanks. I'm not sure that's what I'm after, though. I don't really
want to create a facebook app, just update status on the single page.
--~--~-~--~~~---~--~~
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: Editing base_site.html

2009-03-19 Thread Frank Wiles

On Tue, Mar 17, 2009 at 9:45 AM, TP  wrote:
>
> How would people recommend me to do this?
>
> By editing the base_site.html file in text editor?
>
> By creating my own html page called base_site.html and putting it in
> the right Dir?

The best way is to copy the existing version into your own template
directory, maintaining the nested structure ( i.e.
admin/base_site.html ) and editing it to suit your needs. Hope that
helps!

-- 
Frank Wiles
Revolution Systems | http://www.revsys.com/
fr...@revsys.com   | (800) 647-6298

--~--~-~--~~~---~--~~
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: update facebook status

2009-03-19 Thread Shantanoo Mahajan (शंतनू महाजन)


On 19-Mar-09, at 11:17 PM, bax...@gretschpages.com wrote:

>
> Now that I've got my twitter integration sorted out, I'm trying to
> figure out how to update the facebook status, too.  Twitter was
> relatively easy. Can someone point me to the how-to on updating
> facebook? The catch: it's the status on a product page, not a profile.

you may find 
http://wiki.developers.facebook.com/index.php/PythonPyFacebookTutorial 
  useful.

hth.
regards,
shantanoo

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



update facebook status

2009-03-19 Thread bax...@gretschpages.com

Now that I've got my twitter integration sorted out, I'm trying to
figure out how to update the facebook status, too.  Twitter was
relatively easy. Can someone point me to the how-to on updating
facebook? The catch: it's the status on a product page, not a profile.
--~--~-~--~~~---~--~~
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: add https to django

2009-03-19 Thread Vasil Vangelovski

I'd recommend you use all the power of your webserver for this (apache
or nginx or whatever). There should be no specific modifications on
the django site if you do it right.

I think this gui has the fix for what you asked tho:
http://hotsyk.com/blog/2008/11/05/https-django-and-wsgi/

On Thu, Mar 19, 2009 at 3:30 PM, djanm...@gmail.com  wrote:
>
> Dear all,
>
> to add 'https' to my application, I followed this steps "http://
> www.djangosnippets.org/snippets/240/",
> and i add {ssl:true} to urls of admin,  but when from browser i acess
> to the http://ip:8000/admin/ i have redirection to https://ip:8000/admin/
> and not acess "transfert of data are interoppted"
> the error is  "  File "/usr/lib/python2.5/site-packages/django/core/
> servers/basehttp.py", line 603, in log_message
>    if self.path.startswith(self.admin_media_prefix) or self.path == '/
> favicon.ico':
> AttributeError: WSGIRequestHandler instance has no attribute 'path'  "
>
> Thank you for any 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to properly use limit_choices_to on self-joins

2009-03-19 Thread Laran Evans

I have a Company class. A Company has many Clients, each of which is
also a Company. The problem I have is that in the auto-generated Admin
site, the Clients show up as a multi-select with the Company in the
select box. This doesn't make sense, because a company can't select
itself as a client.

So, how do I specify in the model that the company should not show up
in its list of clients?

I tried to do it by saying the client id should not equal the parent
company id. But I don't seem to be able to get the syntax right.

Can anyone shed light on this? Thanks.

---

class Company(models.Model):
name = models.CharField(max_length=128)
main_phone_number= models.CharField
(max_length=64,blank=True,null=True)
main_email_address   = models.EmailField(blank=True,null=True)
url  = models.URLField(blank=True,null=True)
clients  = models.ManyToManyField
('self',blank=True,null=True,limit_choices_to={'id__ne':'id'})

def __unicode__(self):
return u'%s' % self.name

--~--~-~--~~~---~--~~
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: model already registered error

2009-03-19 Thread ikalooby

I am guessing that you created an admin.py but still have the admin
class registered in the models.py ?
In which case remove and restart the dev server.


On Mar 18, 7:45 am, nixon66  wrote:
> I just redid my models in an application and ran "manage.py
> runserver". But when I tried to log into the admin interface I get
>  model is alreadyregistered errors. Anyone have suggestions on how
> to fix 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-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
-~--~~~~--~~--~--~---



add https to django

2009-03-19 Thread djanm...@gmail.com

Dear all,

to add 'https' to my application, I followed this steps "http://
www.djangosnippets.org/snippets/240/",
and i add {ssl:true} to urls of admin,  but when from browser i acess
to the http://ip:8000/admin/ i have redirection to https://ip:8000/admin/
and not acess "transfert of data are interoppted"
the error is  "  File "/usr/lib/python2.5/site-packages/django/core/
servers/basehttp.py", line 603, in log_message
if self.path.startswith(self.admin_media_prefix) or self.path == '/
favicon.ico':
AttributeError: WSGIRequestHandler instance has no attribute 'path'  "

Thank you for any 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Signals, sites and instances

2009-03-19 Thread Baxter

Talking with Andy more on IRC, it looks like I can't do what I want to
do, unless maybe there's some way to pass the request on to the signal.
--~--~-~--~~~---~--~~
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: Need two response statements on same def

2009-03-19 Thread Jesse

Thanks everyone for the suggestions!  I will get started on redoing
the functions and views.


On Mar 19, 9:29 am, Andy Mckay  wrote:
> On 19-Mar-09, at 8:35 AM, Jesse wrote:
>
> > My concern is that each view has 87 lines of duplicate code from the
> > "GET" data to get the appended list (shown here as: data retrieved to
> > create a list .list.append(publications)).  Anytime I make a
> > change in one view I have to remember to make the change in the other
> > view.
>
> A view is just a Python function, you can do whatever you'd normally  
> do to refactor Python to refactor views. So move the 87 lines of  
> duplicated code into another function and re-use.
> --
>    Andy McKay
>    Clearwind Consulting:www.clearwind.ca
>    Blog:www.agmweb.ca/blog/andy
>    Twitter: twitter.com/clearwind
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



admin: search generic relation?

2009-03-19 Thread patrickk

is there any way to search for a "content_object" within the change-
list?

my model:

class Trailer(models.Model):
...
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()
...

now, I´d like to do something like:

class TrailerOptions(admin.ModelAdmin):
...
search_fields = ('content_object',)
...

this obviously doesn´t work ... are there any workarounds?

thanks,
patrick

--~--~-~--~~~---~--~~
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: Signals, sites and instances

2009-03-19 Thread Baxter

On Mar 19, 11:28 am, Andy Mckay  wrote:

> Well I would have lots of questions there, some real code might help,  
> not sure we have enough info. But lets start with what signal are you  
> trying to catch (theres a few different ones)?

Thanks Andy. In the model I've got:

class News_item(models.Model):
 ...
sites = models.ManyToManyField(Site)
...

models.signals.post_save.connect(post_to_twitter, sender=News_item)

In the signal, this is where I'm pretty sure I'm failing:
if instance.sites.filter(id=1):
   do stuff for site 1

If I grab instance.sites, it appears to be an empty list. It looks
like it hasn't been created yet in this stage of the process?
--~--~-~--~~~---~--~~
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: Need two response statements on same def

2009-03-19 Thread Andy Mckay


On 19-Mar-09, at 8:35 AM, Jesse wrote:
> My concern is that each view has 87 lines of duplicate code from the
> "GET" data to get the appended list (shown here as: data retrieved to
> create a list .list.append(publications)).  Anytime I make a
> change in one view I have to remember to make the change in the other
> view.

A view is just a Python function, you can do whatever you'd normally  
do to refactor Python to refactor views. So move the 87 lines of  
duplicated code into another function and re-use.
--
   Andy McKay
   Clearwind Consulting: www.clearwind.ca
   Blog: www.agmweb.ca/blog/andy
   Twitter: twitter.com/clearwind


--~--~-~--~~~---~--~~
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: Signals, sites and instances

2009-03-19 Thread Andy Mckay


On 19-Mar-09, at 7:59 AM, bax...@gretschpages.com wrote:
> So what can I do? Is the POST info available to the signal maybe?

Well I would have lots of questions there, some real code might help,  
not sure we have enough info. But lets start with what signal are you  
trying to catch (theres a few different ones)?
--
   Andy McKay
   Clearwind Consulting: www.clearwind.ca
   Blog: www.agmweb.ca/blog/andy
   Twitter: twitter.com/clearwind


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Selecting a parent in admin for a child model?

2009-03-19 Thread Wyley

Hi all,

I have a quick question about editing instances of child models in the
admin interface.  I have a couple of models which derive from a (non-
abstract) parent model, thusly:

class Contact(models.Model):
first_name = models.CharField(...)
last_name = models.CharField(...)
# etc.

class LabMember(Contact):
hire_date = models.DateField(...)
# etc.

class Collaborator(Contact):
institution = models.CharField(...)
   # etc.

I have another model with a ForeignKey field to Contact, because I
would like to be able to associate either LabMembers or Collaborators
with that field.

What I would l like to do is be able to add a Contact in the admin
interface (using the standard popup form) when creating an instance of
that model, and then later associate a new LabMember or Collaborator
instance with the previously-added Contact (either by changing the
Contact record, or by adding a new LabMember and having the option to
select an existing Contact).

I realize this may be a use case for an explicit OneToOne field
instead of inheritance, though I do like having the Contact fields
displayed inline when I add a new LabMember.  So yes, I want to have
my cake and eat it too...but if I can only do one, suggestions for
this use case would be greatly appreciated!

Thanks,
Richard
--~--~-~--~~~---~--~~
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: Need two response statements on same def

2009-03-19 Thread Daniel Roseman

On Mar 19, 3:35 pm, Jesse  wrote:
> My concern is that each view has 87 lines of duplicate code from the
> "GET" data to get the appended list (shown here as: data retrieved to
> create a list .list.append(publications)).  Anytime I make a
> change in one view I have to remember to make the change in the other
> view.  Since I'm fairly new at Django, I'm thinking there must be a
> more efficient way to write the views?  I'm very pleased with how
> everything is working, so now I am going back to try to clean up the
> code.
>
> Thanks.

Malcolm hinted at what needs to be done, but he assumed you'd already
done it - that is, take that 87 lines of duplicate code into a
separate function, and call it from both views.

def get_data(request):
... your 87 lines of code ...
data.append(publications)
return data

def by_pub(request):
data = get_data(request)
... proceed with view ...

def text_file(request):
data = get_data(request)
... proceed with view ...

(note I've renamed your views - Python convention is to use
lower_with_underscores for function names, and reserve StudlyCaps for
names of classes. Also, don't use 'list' as the name of a variable in
your get_data code, as that will hide the built-in list() type).
--
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-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: Need two response statements on same def

2009-03-19 Thread Baxter

Pass something in the request, like ?output=csv

Then look for it in the view and feed the appopriate version.

On Mar 19, 10:35 am, Jesse  wrote:
> My concern is that each view has 87 lines of duplicate code from the
> "GET" data to get the appended list (shown here as: data retrieved to
> create a list .list.append(publications)).  Anytime I make a
> change in one view I have to remember to make the change in the other
> view.  Since I'm fairly new at Django, I'm thinking there must be a
> more efficient way to write the views?  I'm very pleased with how
> everything is working, so now I am going back to try to clean up the
> code.
>
> Thanks.
>
> On Mar 18, 6:43 pm, Malcolm Tredinnick 
> wrote:
>
> > On Wed, 2009-03-18 at 11:24 -0700, Jesse wrote:
> > > In the view.py I have  (def Bypub) that sends data to a template and
> > > paginates it.  I have a second (def TextFile) that uses the same data
> > > to send to a CSV file.  I would like to combine the two (def Bypub and
> > > def TextFile) together into def Bypub, but I'm not sure how to write
> > > the statements to combine two responses.
>
> > What problem are you trying to solve here? You already have two views
> > where the common stuff is in a separate function (the bit you've marked
> > as retrieving the data in a list) and the distinct stuff is in the
> > separate views. That ideal.
>
> > If the problem is that you want one URL to be able to access both
> > formats, then simplest is to create a third view that works out which of
> > the current two views to call and then passes onto them:
>
> >         def dispatch_view(request,...):
> >            # ... work out which to call somehow...
>
> >            if output_format == 'csv':
> >               return TextFile(request)
> >            else:
> >               return Bypub(request)
>
> > Is that what you're trying to do?
>
> > 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Strategy for extending DB tables with additional columns

2009-03-19 Thread Frank Wiles

On Mon, Mar 16, 2009 at 11:36 AM, Trey  wrote:
>
> Hello everyone, I am hoping someone has some experience in this
> already. I have a rough idea of how to do it, but I am hoping to
> discover a better way.
>
> What I have:
> A contact manager. A contact has a set of data that makes sense on
> anyone's version of a contact, things like name, email address, etc.
>
> Depending on the use of the contact manager, special fields may be
> required. Something like, birthplace or SSN.
>
> I would like to build the contact manager for all purposes and have
> those extra fields configured through the CRM's admin.
>
> My Plan:
> What I have in mind is a standard columnar table that holds all the
> basic fields. And then two additional tables, one for the customized
> field names and one to related the custom fields to the contact. I can
> foresee tons of performance issues and problems updating data.
>
> Does anyone have any advice, working example, snippet or other general
> comment?

Your plan is fine, it's exactly what I would do in the same situation.
 With proper caching of the data, I wouldn't expect to see any serious
performance issues with your plan.  Assuming given adequate hardware.
Sure it would be an issue if you have 100k users and are running this
on a 5 year old laptop, but that isn't a good reason to not build the
software properly.

-- 
Frank Wiles
Revolution Systems | http://www.revsys.com/
fr...@revsys.com   | (800) 647-6298

--~--~-~--~~~---~--~~
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: Need two response statements on same def

2009-03-19 Thread Jesse

My concern is that each view has 87 lines of duplicate code from the
"GET" data to get the appended list (shown here as: data retrieved to
create a list .list.append(publications)).  Anytime I make a
change in one view I have to remember to make the change in the other
view.  Since I'm fairly new at Django, I'm thinking there must be a
more efficient way to write the views?  I'm very pleased with how
everything is working, so now I am going back to try to clean up the
code.

Thanks.

On Mar 18, 6:43 pm, Malcolm Tredinnick 
wrote:
> On Wed, 2009-03-18 at 11:24 -0700, Jesse wrote:
> > In the view.py I have  (def Bypub) that sends data to a template and
> > paginates it.  I have a second (def TextFile) that uses the same data
> > to send to a CSV file.  I would like to combine the two (def Bypub and
> > def TextFile) together into def Bypub, but I'm not sure how to write
> > the statements to combine two responses.
>
> What problem are you trying to solve here? You already have two views
> where the common stuff is in a separate function (the bit you've marked
> as retrieving the data in a list) and the distinct stuff is in the
> separate views. That ideal.
>
> If the problem is that you want one URL to be able to access both
> formats, then simplest is to create a third view that works out which of
> the current two views to call and then passes onto them:
>
>         def dispatch_view(request,...):
>            # ... work out which to call somehow...
>
>            if output_format == 'csv':
>               return TextFile(request)
>            else:
>               return Bypub(request)
>
> Is that what you're trying to do?
>
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django-Tagging not working with Oracle

2009-03-19 Thread Brandon Taylor

Hi Everyone,

I'm using the svn checkout of Django-Tagging and Django-Trunk. Tagging
is working perfectly for me with any other database except, of course,
Oracle, which is what I need it to work in.

I can't get the TagField() to show up in the admin at all without
adding a custom form for my ModelAdmin class, and when I do, it won't
populate the Tags table.

Creating a ModelForm instance also omits the tags = TagField() field
from the form.

'tagging' is in my installed apps, and the tagging tables get created
when I syncdb. When compared to another project that leverages Django-
Tagging, the tables look ok, so I'm not sure what might be causing it
not to work.

Does anyone know of a workaround?

Kind regards,
Brandon
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Signals, sites and instances

2009-03-19 Thread bax...@gretschpages.com

Follow up to my earlier question (http://groups.google.com/group/
django-users/browse_thread/thread/8f41540343634178/c05242e6d3b07d62)

As I mentioned there, I'm trying to use a snippet to send a twitter
update when a news item is created. The news items have a M2M
relationship with sites-- news can go on one site or both.

So I need to make sure I'm posting the news item to the correct
twitter account. Based on that earlier question, I have:

if instance.sites.filter(id=1):
   do stuff for first site
if instance.sites.filter(id=2):
   do stuff for other site
else:
   return false

This is failing to post when the news item is first created. If I re-
save the item, THEN it will post. I believe it's because
instance.sites is still an empty list at this stage (not yet been
created).

So what can I do? Is the POST info available to the signal maybe?

--~--~-~--~~~---~--~~
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: Test Client doesn't populate request.META["HTTP_HOST"] ...

2009-03-19 Thread Ramiro Morales

On Thu, Mar 19, 2009 at 11:40 AM, Johan  wrote:
>
>  Given:
>
 from django.test.client import Client
 c = Client()
 c.post('/register/',{username=username,password=password})
>
> Traceback (most recent call last):
> ...
> KeyError: 'HTTP_HOST'
>
> Part of the register view  code contains the following:
>
>  ... request.META["HTTP_HOST"] ...
>
> The problem seems to be  that the test client does not inject the META
> (Or at least some of the META) data.
>
> Am I using the wrong construct? If so how do I get around this
> problem?
>

See this thread from a few days ago:

http://groups.google.com/group/django-users/browse_frm/thread/ab3c16762a4aceab

The last example Russell gave there:

> or by providing an 'extra' argument to an individual request:
>
> >>> client.get('/foo/bar/',extra={'HTTP_HOST':'example.com'}

 actually results in a 'extra' key whose value is a nested dictionary
in the request.META dictionary. Use

>>> client.get('/foo/bar/', HTTP_HOST='example.com'}

instead.

HTH,

-- 
Ramiro Morales
http://rmorales.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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Test Client doesn't populate request.META["HTTP_HOST"] ...

2009-03-19 Thread Jacob Kaplan-Moss

On Thu, Mar 19, 2009 at 9:40 AM, Johan  wrote:
> Am I using the wrong construct? If so how do I get around this
> problem?

::

>>> c.post('/register/', data, HTTP_HOST='example.com')

Jacob

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Test Client doesn't populate request.META["HTTP_HOST"] ...

2009-03-19 Thread Johan

Hiya,


  Given:

>>> from django.test.client import Client
>>> c = Client()
>>> c.post('/register/',{username=username,password=password})

Traceback (most recent call last):
...
KeyError: 'HTTP_HOST'

Part of the register view  code contains the following:

 ... request.META["HTTP_HOST"] ...

The problem seems to be  that the test client does not inject the META
(Or at least some of the META) data.

Am I using the wrong construct? If so how do I get around this
problem?

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
-~--~~~~--~~--~--~---



Pixidou and Django

2009-03-19 Thread Oni

Hi guys. Has anyone used this:

http://htmlblog.net/pixidou-an-open-source-ajax-image-editor-php-and-yui-based/

... with Django? Im trying to get a picture uploaded to a temp store,
have that photo edited and then saved in its edited form? So far,
customising the admin views seems simple enough, and reqiring the PHP
to Python shouldnt be too bad.

Im wondering if anyone has done something like this before?

Create model  -> goto Ajax form with our image uploader -> upload
image to temp space and edit in this form -> save edited version
--~--~-~--~~~---~--~~
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: Value proposition of Rails

2009-03-19 Thread Wes Winham

It's also important to note the architectural differences between Java
and your favorite LAMP flavor. LAMP is generally a "shared nothing"
situation where scaling out is a matter of just adding more machines
with some transparent load balancing (on the non-database side). Java
scaling tends towards beefing up the one box that's running your
application server. Often, when you're talking about "will my site
work with x million page views" you're talking about scalability more
than performance.

The bottom line though is that every one of the options mentioned
scale "well enough" for any real world need. You can name sites
written in all of those languages/frameworks (plus .NET) that work
well with load above what a VAST majority of other apps will see. If
Django only showed half the performance of J2EE (not true), then for a
lot of sites you're talking about doubling a cost which is tiny
compared to your development costs. My company gets a bill around $400
per month for our hosting on ec2. If we doubled that, it still
wouldn't be worth spending a day per month doubling the performance of
our application. Whichever tool you (and your clients) can use most
effectively from a development and maintenance standpoint is almost
definitely the right tool for the job.

-Wes

On Mar 19, 7:33 am, Brian Morton  wrote:
> Given how expensive developer time is relative to current hardware
> costs (especially on the x86 server platforms), it is almost always
> more cost effective to throw hardware at the problem than it is to
> spend countless hours porting apps from one language or framework to
> another for performance reasons.  If you want examples, see the Django
> book's deployment section.  On that same note, it is more effective to
> spend money on hardware (usually) than to code in a language that
> takes 5 times as long to develop, configure, and deploy.
> Configuration alone for most Java applications is enough to make your
> head spin.
>
> In my opinion, Django does this way better than PHP's many frameworks
> thanks to the "batteries included" approach.  I have been developing
> PHP for many years, and I do so professionally.  My hope is that one
> day more companies will go the way of Django so I can combine my play
> time and my work time.
>
> On Mar 19, 3:17 am, Torsten Bronger 
> wrote:
>
> > Hallöchen!
>
> > Malcolm Tredinnick writes:
> > > [...]
>
> > > Even PHP: I mean, Flickr, Wikipedia, Yahoo -- these are some
> > > pretty large sites running on PHP.
>
> > I've always wondered why anybody uses something non-Java for Web
> > applications.  Given that Java is faster than PHP, Python etc., this
> > also means that you need less computing power in your server farm.
> > On the long run, this should *always* be worth it financially,
> > unless Java is a nightmare to maintain, which I don't assume.
>
> > Granted, I use Python for our institute's internal Web application,
> > but I expect our traffic to be smaller than what one single
> > processor can handle.
>
> > Is it because the network and the database are the limiting factors?
> > But even then, the part of your server farm running the interpreters
> > could be reduced.
>
> > On the other hand, PHP is *highly* popular.  So why is this?
>
> > Tschö,
> > Torsten.
>
> > --
> > Torsten Bronger, aquisgrana, europa vetus
> >                    Jabber ID: torsten.bron...@jabber.rwth-aachen.de
--~--~-~--~~~---~--~~
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 do I 'redirect' in my test code after a 301 response?

2009-03-19 Thread Johan

Thanks ... I'd din't see the follow parameter. It works like a
charm.. :)

On Mar 19, 3:38 pm, Alex Gaynor  wrote:
> On Thu, Mar 19, 2009 at 9:22 AM, Johan  wrote:
>
> > Hiya,
>
> >  I trying to write test code for my views. I am using the following
> > approach.
>
> > >>>from django.test.client import Clien
> > >>>c = Client()
> > >>>c.get('/courses/system/home').status_code
> > 301
>
> >  The question is now: How do I 'redirect' in my code? I would expect
> > something along the lines of:
>
> > >>> response = c.get('/courses/system/home')
> > >>> if response.status_code == 301:
> > >>>   actual_response = c.get(response.ulr)
>
> >  Any ideas? Help? Pointers to documentation?
>
> > Thanks
>
> In the Django development version you can do 
> this:http://docs.djangoproject.com/en/dev/topics/testing/?from=olddocs#dja...
> the bits on follow = True.  On 1.0 you'll need to do it manually.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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: request object needed in form methods

2009-03-19 Thread Thomas Guettler

>> Why not store the request
>> object (in a thread safe way) on module level?
...
> The biggest con is encourages bad design practices, the way Python works is
> you have a global and local scope, if you want something in your local scope
> you pass it to it.
> 
> If you really want to have the request object stored you can write a custom
> middleware to do it, but I wouldn't.

I don't want to enable this for all parts. Just for a single, complex form.

{{{
class MasterForm(object):
... contains several sub forms which need request

class SubForm(form.Form):
def clean(self):
if threadlocal.request.user .

threadlocal=threading.local()
def view(request):
threadlocal.request=request
mform=MasterForm()
}}}



-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--~--~-~--~~~---~--~~
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: request object needed in form methods

2009-03-19 Thread Daniel Roseman

On Mar 19, 1:22 pm, Thomas Guettler  wrote:
> Hi,
>
> I know that you can pass the request object to form like this:
>
> class MyForm(forms.Form):
>     def __init__(self, request, *args, **kwargs):
>         self.request=request
>         forms.Form.__init__(self, *args, **kwargs)
>
> Somehow I am tired of rewriting this. Why not store the request
> object (in a thread safe way) on module level?
>
> I recall that someone said this is not good. What are the pro and
> contra arguments?
>
> Most of the time I need request.user to hide some input fields.
>
>   Thomas
>


So create a library module and define your own form subclass with that
overridden init defined. Now instead of creating a form inheriting
from forms.Form, create them based on mylib.RequestForm or whatever
you call it.
--
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-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: Unicode issue with Oracle

2009-03-19 Thread João Olavo Baião de Vasconcelos

On 1/27/09, Karen Tracey  wrote:
> Don't use cx_Oracle 5.0, use a 4.X version.  The docs were recently changed
> to specify that, after investigation into
> http://code.djangoproject.com/ticket/9935 revealed the problem is due to a
> bug in cx_Oracle 5.0.

Just for the record: this bug doesn't exist anymore with cx_Oracle 5.0.1.

-- 
João Olavo Baião de Vasconcelos
Bacharel em Ciência da Computação
Analista de Sistemas - Infraestrutura
joaoolavo.wordpress.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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Adding a field to a form during runtime

2009-03-19 Thread Preston Timmons

Hi Marek,
I think that your problem is that the make_car_form function returns a
form class rather than an instance of that class. Once you have the
class you still need to make an instance of it. Something like this
might work:

form_class = make_car_form(True)
carForm = form_class()


Preston


On Mar 19, 7:05 am, Thomas Guettler  wrote:
> Sorry, I can't help you here, since I don't create classes
> at runtime (*). I think using __init__() is better, and I guess
> you can solve your problem with it, too.
>
> (*) type('ContactForm', (forms.BaseForm, ), { 'base_fields': fields})
>
> Marek W schrieb:
>
>
>
> > Thanks for your response. Probably the reason was I didn't update a
> > database, because now(after making syncdb) it works correctly. But by the
> > time I've found a second problem:
>
> > while to create a dynamic form this way:
>
> > def make_car_form(extra):
> >     fields = { 'carType' : forms.CharField() }
> >     if extra:
> >         fields['extraField'] = forms.CharField()
> >     return type('ContactForm', (forms.BaseForm, ), { 'base_fields': fields
> > })
>
> > View method:
> > (...)
> >     carForm = make_car_form(True)
> > (...)
>
> > then on the page there aren't any fields, whether calling make_car_form with
> > extra=True or extra=False.
>
> --
> Thomas Guettler,http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + de
--~--~-~--~~~---~--~~
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: Getting logged in username in admin

2009-03-19 Thread Alex Gaynor
On Thu, Mar 19, 2009 at 9:32 AM, Joshua Partogi wrote:

>
> Dear all,
>
> How do I get the current logged in user to be used and inserted to a model?
> from django.db import models
> from django.contrib.auth.models import User
>
> class News(models.Model):
>creator = models.ForeignKey(User)
>
> I want the creator field to be the current logged in user.
>
> Thank you very much.
>
> --
> If you can't believe in God the chances are your God is too small.
>
> Read my blog: http://joshuajava.wordpress.com/
> Follow me on twitter: http://twitter.com/jpartogi
>
> >
>
The admin has a specific method you can overide just for this:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#save-model-self-request-obj-form-change

The example should make it pretty clear what you need to do.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: request object needed in form methods

2009-03-19 Thread Alex Gaynor
On Thu, Mar 19, 2009 at 9:22 AM, Thomas Guettler  wrote:

>
> Hi,
>
> I know that you can pass the request object to form like this:
>
> class MyForm(forms.Form):
>def __init__(self, request, *args, **kwargs):
>self.request=request
>forms.Form.__init__(self, *args, **kwargs)
>
> Somehow I am tired of rewriting this. Why not store the request
> object (in a thread safe way) on module level?
>
> I recall that someone said this is not good. What are the pro and
> contra arguments?
>
> Most of the time I need request.user to hide some input fields.
>
>  Thomas
>
> --
> Thomas Guettler, http://www.thomas-guettler.de/
> E-Mail : guettli (*)
> thomas-guettler + de
>
> >
>
The biggest con is encourages bad design practices, the way Python works is
you have a global and local scope, if you want something in your local scope
you pass it to it.

If you really want to have the request object stored you can write a custom
middleware to do it, but I woulldn't.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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 do I 'redirect' in my test code after a 301 response?

2009-03-19 Thread Alex Gaynor
On Thu, Mar 19, 2009 at 9:22 AM, Johan  wrote:

>
> Hiya,
>
>  I trying to write test code for my views. I am using the following
> approach.
>
> >>>from django.test.client import Clien
> >>>c = Client()
> >>>c.get('/courses/system/home').status_code
> 301
>
>  The question is now: How do I 'redirect' in my code? I would expect
> something along the lines of:
>
> >>> response = c.get('/courses/system/home')
> >>> if response.status_code == 301:
> >>>   actual_response = c.get(response.ulr)
>
>  Any ideas? Help? Pointers to documentation?
>
> Thanks
> >
>
In the Django development version you can do this:
http://docs.djangoproject.com/en/dev/topics/testing/?from=olddocs#django.test.client.Clientsee
the bits on follow = True.  On 1.0 you'll need to do it manually.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Newbie to Novice – Using Admin DateTime Picker in your Form

2009-03-19 Thread Paul Nema
I've noticed many people new to Django (and sometimes also new to Python)
often post the same/similar questions in various forums. How to I get
something to work and/or do you have an example for X. As I've also
experienced this problem I've decided to post my little solution. Its not
the only way to do this, just the way I did it. Hopefully this will provide
the answer people are searching for or at least get them started. I guess it
will also serve as a quick code review by those so inclined to comment.


 You've probably heard of DRY but I think something is missing. There should
also be a Don't Repeat Other's Work (DROW) when they already solved the
problem. Thus another motivation to post this.  On a side note there is a
bit of debate out there about using the Django AdminDateWidget verse other
solutions (Jquery, etc). Your decision to make but why increase dependencies
when you don't have to.


 As I'm still learning Django everything in the code below may not be
required but I'm listing it anyway. You may need to modify to your
particular environment.  As I don't have a blog to post this I'm sending it
to this group. I'm open to any suggestions for a better place to post this.


 For this example I will focus on adding a date picker for date of birth
(dob) and a date time picker for sponsor sign date (sponsor_sign_date). Key
items are in *Bold*.


 Another reference to adding the AdminDateTime widget is here:
http://stackoverflow.com/questions/38601/using-django-time-date-widgets-in-custom-form




 ---

My top level (django-admin.py startproject izbo) directory Structure:

mylo...@lx-d620:~/dev/izbo$ ll

drwxrwxr-x 2 mylogin mylogin 4096 2009-03-17 10:52 account/

drwxr-xr-x 2 mylogin mylogin 4096 2009-03-17 10:53 add/

drwxr-xr-x 2 mylogin mylogin 4096 2009-03-18 04:34 adjudicator/

drwxrwxr-x 2 mylogin mylogin 4096 2009-03-18 09:43 application/

drwxr-xr-x 2 mylogin mylogin 4096 2009-03-18 10:06 contract/

drwxrwxrwx 2 mylogin mylogin 4096 2009-03-18 09:49 DB/

drwxr-xr-x 2 mylogin mylogin 4096 2009-03-17 10:51 employer/

drwxr-xr-x 2 mylogin mylogin 4096 2009-03-18 04:34 entity/

-rw-r--r-- 1 mylogin mylogin 207 2009-03-08 04:54 exclude

drwxrwxrwx 2 mylogin mylogin 4096 2009-03-18 10:06 gzbo/

-rw-r--r-- 1 mylogin mylogin 0 2009-01-06 04:55 __init__.py

-rw-r--r-- 1 mylogin mylogin 546 2009-01-06 04:55 manage.py

drwxrwxrwx 5 mylogin mylogin 4096 2009-02-08 12:35 media/

drwxr-xr-x 2 mylogin mylogin 4096 2009-03-17 10:53 member/

drwxr-xr-x 2 mylogin mylogin 4096 2009-03-17 10:52 note/

drwxr-xr-x 2 mylogin mylogin 4096 2009-02-20 12:47 search/

-rw-r--r-- 1 mylogin mylogin 4192 2009-03-05 23:39 settings.py

drwxrwxrwx12 mylogin mylogin 4096 2009-03-16 11:48 templates/

-rw-r--r-- 1 mylogin mylogin 2118 2009-03-16 11:16 urls.py


 --

Media directory Listing:

mylo...@lx-d620:~/dev/izbo/media$ ll

total 12

drwxr-xr-x 5 mylogin mylogin 4096 2009-03-18 10:56 admin/

drwxrwxrwx 2 mylogin mylogin 4096 2009-02-07 15:45 css/

drwxrwxrwx 2 mylogin mylogin 4096 2009-01-27 10:07 images/

lrwxrwxrwx 1 mylogin mylogin 36 2009-03-18 11:07 img ->
/home/mylogin/dev/izbo/media/admin/img/


 * Note: admin/ is 'cp -r' of directory
/usr/lib/python2.5/site-packages/django/contrib/admin/media.  Then I linked
the img directory.



 

In my “settings.py”


 import os.path

PROJECT_DIR = os.path.dirname(__file__)


 MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')

MEDIA_URL = 'http://www.izbo.com/media/'

*ADMIN_MEDIA_PREFIX = '/media/admin/'*

TEMPLATE_DIRS = (

   os.path.join(PROJECT_DIR, 'templates'),

   ...

)


 

In my top level “urls.py” file

*from django.contrib import admin *


 urlpatterns = patterns('',

   # Uncomment the admin/doc line below and add 'django.contrib.admindocs'

   # to INSTALLED_APPS to enable admin documentation:

   (r'^admin/doc/', include('django.contrib.admindocs.urls')),


*# Add this to get widgets.AdminDateWidget() working for non is_staff,
is_superuser *

   *# This must be placed before (r'^admin/(.*)', admin.site.root), as that
gobals up everything *

   *(r'^admin/jsi18n/$', 'django.views.i18n.javascript_catalog'), *


# Uncomment the next line to enable the admin:

   (r'^admin/(.*)', admin.site.root),


# IZBO related URLs

   (r'^$', splash),

   .

)



 -

In “gzbo/models.py” I have my class


 #

# Application

#

class App (Record) :

# Personal Information

*dob = DateField(null=True, *

*verbose_name=_('Date of Birth'), *

*help_text=_('Enter Date of Birth Format: CCYY-MM-DD')) *

*sponsor_sign_date = DateTimeField(null=True, *

*blank=True, *

*verbose_name=_('Date Sponsor Electronically Signed')*)


 --

In “application/” I have a forms.py that describes the fields I want to have
a date time picker

So in application/forms.py


 #

# DJANGO Libraries

#

from django.forms import ModelForm

from django import forms

from django.contrib.admin import widgets

Getting logged in username in admin

2009-03-19 Thread Joshua Partogi

Dear all,

How do I get the current logged in user to be used and inserted to a model?
from django.db import models
from django.contrib.auth.models import User

class News(models.Model):
creator = models.ForeignKey(User)

I want the creator field to be the current logged in user.

Thank you very much.

-- 
If you can't believe in God the chances are your God is too small.

Read my blog: http://joshuajava.wordpress.com/
Follow me on twitter: http://twitter.com/jpartogi

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



request object needed in form methods

2009-03-19 Thread Thomas Guettler

Hi,

I know that you can pass the request object to form like this:

class MyForm(forms.Form):
def __init__(self, request, *args, **kwargs):
self.request=request
forms.Form.__init__(self, *args, **kwargs)

Somehow I am tired of rewriting this. Why not store the request
object (in a thread safe way) on module level?

I recall that someone said this is not good. What are the pro and
contra arguments?

Most of the time I need request.user to hide some input fields.

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



How do I 'redirect' in my test code after a 301 response?

2009-03-19 Thread Johan

Hiya,

  I trying to write test code for my views. I am using the following
approach.

>>>from django.test.client import Clien
>>>c = Client()
>>>c.get('/courses/system/home').status_code
301

  The question is now: How do I 'redirect' in my code? I would expect
something along the lines of:

>>> response = c.get('/courses/system/home')
>>> if response.status_code == 301:
>>>   actual_response = c.get(response.ulr)

  Any ideas? Help? Pointers to documentation?

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
-~--~~~~--~~--~--~---



Re: Sort of OT on the django book

2009-03-19 Thread Gour
> "James" == James Bennett  writes:

James> Well, what's not welcome is being asked the same question over
James> and over again when the publication date's listed on the Amazon
James> page for anyone and everyone to look at ;)

Well, the context of the question was announcement about django's delay
of 1.1 release...

Otoh, when I e.g. pre-ordered Python Essential Reference 4th ed. the
date listed was 15th of January, and it's May 15th as of today which
makes a difference :-D


Still, I wish you to make it before the autumn...


Sincerely,
Gour

-- 

Gour  | Zagreb, Croatia  | GPG key: C6E7162D



pgpxR1KAVtGv2.pgp
Description: PGP signature


Re: Sort of OT on the django book

2009-03-19 Thread brad



On Mar 19, 2:03 am, James Bennett  wrote:
> Well, what's not welcome is being asked the same question over and
> over again when the publication date's listed on the Amazon page for
> anyone and everyone to look at ;)


Which just happens to be June 1, 2009.
--~--~-~--~~~---~--~~
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: Adding a field to a form during runtime

2009-03-19 Thread Thomas Guettler

Sorry, I can't help you here, since I don't create classes
at runtime (*). I think using __init__() is better, and I guess
you can solve your problem with it, too.

(*) type('ContactForm', (forms.BaseForm, ), { 'base_fields': fields})

Marek W schrieb:
> Thanks for your response. Probably the reason was I didn't update a
> database, because now(after making syncdb) it works correctly. But by the
> time I've found a second problem:
> 
> while to create a dynamic form this way:
> 
> def make_car_form(extra):
> fields = { 'carType' : forms.CharField() }
> if extra:
> fields['extraField'] = forms.CharField()
> return type('ContactForm', (forms.BaseForm, ), { 'base_fields': fields
> })
> 
> 
> View method:
> (...)
> carForm = make_car_form(True)
> (...)
> 
> then on the page there aren't any fields, whether calling make_car_form with
> extra=True or extra=False.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--~--~-~--~~~---~--~~
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: Testing

2009-03-19 Thread Filip Gruszczyński

I see. Thanks a lot.

2009/3/19 Preston Timmons :
>
> Hi Filip,
> The Django test runner looks for tests in two places in an
> application--the models.py file and an optional tests.py file. If you
> want to run tests for your views you can move your tests into a file
> called tests.py in your application.
>
> An example of testing a view with doctests can be found here:
> http://docs.djangoproject.com/en/dev/topics/testing/#overview-and-a-quick-example
>
> Preston
>
>
>
> On Mar 18, 6:34 pm, Filip Gruszczyński  wrote:
>> I am trying to have my function tested using docstring with examples.
>> When I put it into models.py of an app, it gets tested. If I put
>> it into views.py, it is not tested; this happens also, if I add
>> another module (which I import). How can make testing framework test
>> those?
>>
>> --
>> Filip Gruszczyński
> >
>



-- 
Filip Gruszczyński

--~--~-~--~~~---~--~~
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: Value proposition of Rails

2009-03-19 Thread Brian Morton

Given how expensive developer time is relative to current hardware
costs (especially on the x86 server platforms), it is almost always
more cost effective to throw hardware at the problem than it is to
spend countless hours porting apps from one language or framework to
another for performance reasons.  If you want examples, see the Django
book's deployment section.  On that same note, it is more effective to
spend money on hardware (usually) than to code in a language that
takes 5 times as long to develop, configure, and deploy.
Configuration alone for most Java applications is enough to make your
head spin.

In my opinion, Django does this way better than PHP's many frameworks
thanks to the "batteries included" approach.  I have been developing
PHP for many years, and I do so professionally.  My hope is that one
day more companies will go the way of Django so I can combine my play
time and my work time.

On Mar 19, 3:17 am, Torsten Bronger 
wrote:
> Hallöchen!
>
> Malcolm Tredinnick writes:
> > [...]
>
> > Even PHP: I mean, Flickr, Wikipedia, Yahoo -- these are some
> > pretty large sites running on PHP.
>
> I've always wondered why anybody uses something non-Java for Web
> applications.  Given that Java is faster than PHP, Python etc., this
> also means that you need less computing power in your server farm.
> On the long run, this should *always* be worth it financially,
> unless Java is a nightmare to maintain, which I don't assume.
>
> Granted, I use Python for our institute's internal Web application,
> but I expect our traffic to be smaller than what one single
> processor can handle.
>
> Is it because the network and the database are the limiting factors?
> But even then, the part of your server farm running the interpreters
> could be reduced.
>
> On the other hand, PHP is *highly* popular.  So why is this?
>
> Tschö,
> Torsten.
>
> --
> Torsten Bronger, aquisgrana, europa vetus
>                    Jabber ID: torsten.bron...@jabber.rwth-aachen.de
--~--~-~--~~~---~--~~
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: Forms: custom clean for DateField

2009-03-19 Thread johan . uhle

> if (data['firstDate'] >= data['lastDate']):
> raise ValidationError("Error")

it should read
raise forms.ValidationError

If you want to have the error not only as a non_field global error,
but actually added to the fields where the error occured, you can do
the following in the clean(self) method:

error_list=self.errors.get("firstDate")
if error_list is None:
error_list=forms.util.ErrorList()
self.errors["firstDate"]=error_list
error_list.append("Error Message because firstDate > lastDate. Please
correct that!")

I dont know if this is the nicest way, but it works :)

On 18 Mrz., 11:57, Wim Feijen  wrote:
> Hi Marco,
>
> In Django 1.0, you don't need to call clean from clean, Django will do
> that automatically for you. :)
>
> So what you can do is:
>
>     def clean(self):
>         data =  self.cleaned_data
>
>         if (data['firstDate'] >= data['lastDate']):
>             raise ValidationError("Error")
>
>         # else
>         return data
>
> That should work.
>
> For more info, see:http://docs.djangoproject.com/en/dev/ref/forms/validation/
>
> Wim
>
> On Mar 6, 11:46 am, MarcoS  wrote:
>
> >  Sorry, i've posted without finishing the message :)
>
> > So, if I call clean(self), Django give me this exception for the
> > following line:
>
> >     super(forms.DateField, self).clean()
>
> > Exception Type:         TypeError
> > Exception Value:
> > super(type, obj): obj must be an instance or subtype of type
>
> > To solve it I tried to replace
>
> >     super(forms.DateField, self).clean()
>
> > with:
>
> >     super(DateField, self.fields['firstDate']).clean(self)
>
> > but I think isn't correct and however the super class doesn't raises
> > any
> > exception for input that isn't in a date format.
>
> > Please, give me 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django choises field

2009-03-19 Thread Psihonavt



Briel, I ubderstand what you want to say, i'll try to find another
way.
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
-~--~~~~--~~--~--~---



Re: Value proposition of Rails

2009-03-19 Thread James Bennett

On Thu, Mar 19, 2009 at 2:53 AM, Torsten Bronger
 wrote:
> Okay, C.  Well, most of the library and framework stuff is missing
> but I assume that this could be done, given that the financial
> benefit is there.  But actually I still don't get your analogy.

You asked, basically, "since Java is faster than Python, why would
anybody use Python instead of Java?"

I turned this around into "since C is faster than Java, why would you
use Java instead of C?"

In other words, if raw execution speed of the application code is the
decisive factor for you, why are you choosing to use anything other
than the "fastest" available language?

Since you're not using the "fastest" available language, this means
you recognize that there are often other factors which are just as
important, and which can sway the final decision. Which means you
already know the answer to your question: raw execution speed isn't
everything.


Also, there are web frameworks in C. They just aren't that popular,
for some reason...

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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: Value proposition of Rails

2009-03-19 Thread Torsten Bronger

Hallöchen!

James Bennett writes:

> On Thu, Mar 19, 2009 at 2:35 AM, Torsten Bronger
>  wrote:
>
>> I think is *is* a nightmare to maintain.  At least, Java and PHP
>> play in the same league of maintainability, whereas assembly is
>> *far* away from that.
>
> OK, then, why not write everything in C?

Okay, C.  Well, most of the library and framework stuff is missing
but I assume that this could be done, given that the financial
benefit is there.  But actually I still don't get your analogy.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
   Jabber ID: torsten.bron...@jabber.rwth-aachen.de


--~--~-~--~~~---~--~~
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: Value proposition of Rails

2009-03-19 Thread Malcolm Tredinnick

On Thu, 2009-03-19 at 08:17 +0100, Torsten Bronger wrote:
> Hallöchen!
> 
> Malcolm Tredinnick writes:
> 
> > [...]
> >
> > Even PHP: I mean, Flickr, Wikipedia, Yahoo -- these are some
> > pretty large sites running on PHP.
> 
> I've always wondered why anybody uses something non-Java for Web
> applications.  Given that Java is faster than PHP, Python etc., this
> also means that you need less computing power in your server farm.
> On the long run, this should *always* be worth it financially,
> unless Java is a nightmare to maintain, which I don't assume.

There are a lot of assumptions in that a paragraph which may or may not
be true (particularly the last part depends on a lot of variables and I
would default to not-true unless the developers have been
super-careful). My professional experience is certainly that Python is a
lot easier to maintain than the equivalent program in Java (I've
actually had the good or bad fortune to help develop more or less
exactly the same program in Java and Python, so I have at least one
medium-sized, multi-machine project to use as a comparison).

I don't think I've ever been swayed by any blinding speed difference of
Java over Python on very many different projects. You can certainly find
projects where Java or C will be a faster choice. I can also find code
where Python wins unless you put a lot of effort into ironing out
problems (doing work with lots of string manipulations is almost the
exact opposite of fun in Java, for example).

> Granted, I use Python for our institute's internal Web application,
> but I expect our traffic to be smaller than what one single
> processor can handle.
> 
> Is it because the network and the database are the limiting factors?
> But even then, the part of your server farm running the interpreters
> could be reduced.

The difference isn't going to be *that* significant when you measure it,
in a lot of cases, I suspect. You're right that the database and network
are often limiting factors. Although, we (large system developers) also
spend a lot of time removing the need to do things like database
accesses, or even disk reads. At that point, all the languages are
converging on things like the speed of your caches and communication
speeds. For web applications, you're hopefully not doing that much
computation. If you are, you're passing it off to native system
libraries.

There are also considerations such as Java using a lot more memory in
cases than an equivalent algorithm in Python.

On the reduced server farm load, remember that things are discrete.
Saving 0.05 of the server load doesn't mean you now only have to buy
0.95 of a server. You still have to buy them in whole units. When
combined with the natural wish for a bit of overhead on busy sites, and
you might end up not saving that much (for which you've traded off
things such as, possibly, maintenance and development speed).

> On the other hand, PHP is *highly* popular.  So why is this?

You realise you've now guaranteed this thread will go on for about 50
messages, right? :-)

My take: PHP isn't a horrible language to program in. It's got some
flaws, but if you really understand the language it's easy enough to
work around them. A lot of its bad reputation comes from software that
*uses* the language and does things badly. The language itself isn't
necessarily bad. I would say it makes it a bit easier to shoot yourself
in the foot in the web space than Java or C or Perl, but Python has some
cool ways to do that, too (I'll argue that taint mode in Perl makes it a
slightly better native web language than Python in that respect).

The barrier to initial entry for PHP coding is very low. This means, of
course, that the number of beginning coders in that space is very large
and many of them don't move up the learning curve. So popularity by raw
numbers favours the simpler languages (BASIC was also very popular when
I was a young 'un for the same reason; then again, so was 6502 assembly,
so my impressions may not be too relevant these days). Popularity on the
right-hand side of the curve (call it "expert level" or "large,
professional systems") is interesting and I don't have the information
to make a judgement. Except for this: the fact that Yahoo have moved to
PHP internally (they actually moved from "other stuff" a few years back)
and things like Flickr are built on it (independently, prior to being
bought by Yahoo, presumably) means it has something going for it.

I will note, though, that PHP has some of the best integration with a
web browser of any language (including Java). Have a read of Ian
Bicking's piece comparing mod_php to mod_python (et al), for example. He
gives a good description of that strength of PHP as a language as an
implementation for Apache.

I would love for somebody like Cal Henderson to make their next book be
"Writing enterprise systems in PHP", except without the "enterprise"
word, because I suspect there's a lot to learn there.

Again, raw language popul

Re: Value proposition of Rails

2009-03-19 Thread James Bennett

On Thu, Mar 19, 2009 at 2:35 AM, Torsten Bronger
 wrote:
> I think is *is* a nightmare to maintain.  At least, Jva and PHP play
> in the same league of maintainability, whereas assembly is *far*
> away from that.

OK, then, why not write everything in C? Hard to get faster than C
without doing assembly, and most of the same types of
"maintainability" problems you'd see in C are also present in Java
(build processes, dependency management, etc.).

So why write Java instead of saying "C is faster, let's use C"?


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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: Value proposition of Rails

2009-03-19 Thread Torsten Bronger

Hallöchen!

James Bennett writes:

> On Thu, Mar 19, 2009 at 2:17 AM, Torsten Bronger
>  wrote:
>
>> I've always wondered why anybody uses something non-Java for Web
>> applications.  Given that Java is faster than PHP, Python etc.,
>> this also means that you need less computing power in your server
>> farm.  On the long run, this should *always* be worth it
>> financially, unless Java is a nightmare to maintain, which I
>> don't assume.
>
> I've always wondered why anybody uses something other than
> assembly for Web applications. [...] On the long run, this should
> *always* be worth it financially, unless assembly is a nightmare
> to maintain, which I don't assume.

I think is *is* a nightmare to maintain.  At least, Jva and PHP play
in the same league of maintainability, whereas assembly is *far*
away from that.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
   Jabber ID: torsten.bron...@jabber.rwth-aachen.de


--~--~-~--~~~---~--~~
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: Value proposition of Rails

2009-03-19 Thread James Bennett

On Thu, Mar 19, 2009 at 2:17 AM, Torsten Bronger
 wrote:
> I've always wondered why anybody uses something non-Java for Web
> applications.  Given that Java is faster than PHP, Python etc., this
> also means that you need less computing power in your server farm.
> On the long run, this should *always* be worth it financially,
> unless Java is a nightmare to maintain, which I don't assume.

I've always wondered why anybody uses something other than assembly
for Web applications. Given that assembly is faster than Java, .NET,
C, etc., this also means that you need less computing power in your
server farm. On the long run, this should *always* be worth it
financially, unless assembly is a nightmare to maintain, which I don't
assume.

(reflect on why you said "Java" instead of "assembly", and perhaps you
will be enlightened)



-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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: Value proposition of Rails

2009-03-19 Thread Torsten Bronger

Hallöchen!

Malcolm Tredinnick writes:

> [...]
>
> Even PHP: I mean, Flickr, Wikipedia, Yahoo -- these are some
> pretty large sites running on PHP.

I've always wondered why anybody uses something non-Java for Web
applications.  Given that Java is faster than PHP, Python etc., this
also means that you need less computing power in your server farm.
On the long run, this should *always* be worth it financially,
unless Java is a nightmare to maintain, which I don't assume.

Granted, I use Python for our institute's internal Web application,
but I expect our traffic to be smaller than what one single
processor can handle.

Is it because the network and the database are the limiting factors?
But even then, the part of your server farm running the interpreters
could be reduced.

On the other hand, PHP is *highly* popular.  So why is this?

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
   Jabber ID: torsten.bron...@jabber.rwth-aachen.de


--~--~-~--~~~---~--~~
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: Sort of OT on the django book

2009-03-19 Thread James Bennett

On Thu, Mar 19, 2009 at 1:55 AM, Gour  wrote:
> Don't ask this question. I asked him on #django (several times), and
> found out that such sort of inquiry is not very welcome ;)

Well, what's not welcome is being asked the same question over and
over again when the publication date's listed on the Amazon page for
anyone and everyone to look at ;)



-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---