Can the admin site link foreign keys?

2009-04-29 Thread Rex

Let's say I've got two models: User, and Country. Each user is from
one country, and each country has multiple users. so the User model
contains a ForeignKey for a Country object.

Can I do either of the following through the Django admin web
interface?

(1) When I'm looking at the list of Users, have the "country" column
contain a hyperlink that takes me to that particular Country object.
(2) When I'm looking at a Country object, show the set of all users
that have a ForeignKey to this Country, along with a hyperlink to
those User objects.

Any tips would be appreciated.

Thanks,

Rex
--~--~-~--~~~---~--~~
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, FCGI, Cherokee. Spawning PHP Processes and detaching?

2009-04-29 Thread aaron smith

Hey All,

Sorry If I don't have some of this terminology correct. Here's my
problem. I have a django app, which I'm serving with Cherokee and
FCGI. My django app manages a bunch of stuff, and has to make a couple
calls to an external soap service, to record some customer data.

Unfortunately, I can't get the soap service working with Python. And
the people who write the service only provide php as an "official"
language. So what I'm doing is running PHP as a cli, reading
parameters, kick of to soap etc.

The problem I'm hitting is that in Python, when I send out the php
call. It's blocking. So the request to the user on the site sits there
and waits because the soap service is jank slow. So, what I'm trying
to figure out is how to launch the PHP script from Python, but have it
detach from the current process so it finishes by itself. The php
script does all the work, I don't care about the exit code or any
STDOUT data.

I've tried a number of methods. subprocess.Popen, os.system, etc. When
those don't work, I've even tried having python call a shell script,
which does the actual PHP call for me so I can add on the & at the end
to daemonize it. Bleh, I just can't figure out why this is not
working. To give some context into things i've tried:

#directly calling the php script
cmd = "/usr/bin/php "
cmd += settings.CODEIGNITER_CRON_SCRIPTS_PATH+settings.INSERT_VN
cmd += " "+str(customer.id)+" "+ph+" "+fn+" "+ln+" "+amount+" &"
os.system(cmd)

#this is the shell script which takes the args, and adds &, in the
call to the php script
cmd = settings.CODEIGNITER_CRON_SCRIPTS_PATH+"insert_virtual_number.sh"
cmd += " "+str(customer.id)+" "+ph+" "+fn+" "+ln+" "+amount
os.system(cmd)

#using Popen to call the php script
pid=subprocess.Popen(["/usr/bin/php",settings.CODEIGNITER_CRON_SCRIPTS_PATH+settings.INSERT_VN,str(customer.id),ph,fn,ln,amount]).pid

#using Popen to call the shell script version
pid=subprocess.Popen(["/bin/bash",settings.CODEIGNITER_CRON_SCRIPTS_PATH+"insert_virtual_number.sh",str(customer.id),ph,fn,ln,amount]).pid

Does anyone have any pointers, or tips in the right direction? I'm so
close, arg!

Thanks much.
A

--~--~-~--~~~---~--~~
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: url template tag help

2009-04-29 Thread Julián C . Pérez

uhhh
i tried but nooo... your suggestion doesn't work...
let me show you 2 versions of error...

1. "Reverse for 'proyName.view_aboutPage' with arguments '()' and
keyword arguments '{}' not found."
settings:
# in proyName.packages.appName.urls.py:
 ... url(r'^about/$', 'view_aboutPage',
name='proyName.link_aboutPage'), ...
# in the template (about.html):
... show 'about' ...

2. "Reverse for '' with
arguments '()' and keyword arguments '{}' not found."
settings:
# in proyName.packages.appName.urls.py:
 ... url(r'^about/$', 'view_aboutPage', name='link_aboutPage'), ... #
also fails with "name='proyName.link_aboutPage'"
# in the template (about.html):
... show
'about' ...

by the way, the view loks like:
# in proyName.packages.appName.views.py:
...
def view_aboutPage(request):
return render_to_response('pages/about.html',
context_instance=RequestContext(request))
...

what can i do?? honestly, i do not know...
thanks!


On Apr 29, 12:37 pm, Kevin Audleman  wrote:
> You might be able to solve your problem by changing the name attribute
> of your URL to include  "proyName":
>
> url(r'^about/$', 'view_aboutPage', name='proyName.view_aboutPage'),
>
> ---
>
> The error message is telling you exactly what it's looking for, after
> all:
>
> the error:
> "Reverse for 'proyName.view_aboutPage' with arguments '()' and keyword
> arguments '{}' not found."
>
> I have solved most of my URL problems this way.
>
> Cheers,
> Kevin
--~--~-~--~~~---~--~~
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: Saving Multiple forms? or fields... confused.

2009-04-29 Thread Karen Tracey
On Wed, Apr 29, 2009 at 4:00 PM, tdelam  wrote:

>
> Hi,
>
> I am building a small survey app, questions are added to a survey
> through django-admin, I am building the form dynamically, when the
> form is submitted I only get the first form saving, here is the code:
> http://dpaste.com/hold/39401/ Does anyone have any tips on how I can
> get the other ones to save when the submit is clicked? Do I need to
> loop somewhere prior to saving?


You already have a loop, the problem is you are returning after the first
save:

if request.method == 'POST':
questions = get_list_or_404(Question)
for q in questions:
form = TrueFalseForm(q, data=request.POST)
if form.is_valid():
form.save(q)
return HttpResponseRedirect("/thanks/")

Thus immediately after you find the first valid form, you save it (though I
don't see, actually, where you use the form's data during save, but I could
just be missing what you're doing there) and return a response, terminating
the loop you are in.  If you want to save all the valid forms, you'll need
to move that return statement to outside the loop.  (Also note you'll just
ignore invalid forms, as opposed to re-displaying the page with errors.
Also if all forms are invalid, you'll fall through to the render_to_response
without having set the forms variable used by it to a value, which will
likely cause a server error.)

Karen

--~--~-~--~~~---~--~~
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: FileField uploading into an user-specific path

2009-04-29 Thread Julián C . Pérez

OMG!
excellent, kevin... just what i wanted!
works smooth and nice
thanks a lot
;)

On Apr 29, 12:42 pm, Kevin Audleman  wrote:
> You're in luck, I just programmed this exact thing:
>
> Define the following function right above your model:
>
> def upload_location(instance, filename):
>         return 'profile_photos/%s/%s' % (instance.user.username,
> filename)
>
> My function uses 'profile_photos' as the base directory appended to
> MEDIA_ROOT; you might want to rename that. Then in your model, define
> your image field as so:
>
> photo_1 = models.ImageField(upload_to=upload_location, blank=True)
>
> Cheers,
> Kevin
>
> On Apr 29, 8:12 am, Julián C. Pérez  wrote:
>
> > thanks...
> > but...
> > how can i make that attribute a callable tto work with user-specif
> > paths??
>
> > On 29 abr, 03:18, Kip Parker  wrote:
>
> > > upload_to can be a callable 
> > > -http://docs.djangoproject.com/en/dev/ref/models/fields/#filefield.
>
> > > On Apr 29, 4:59 am, "Carlos A. Carnero Delgado"
>
> > >  wrote:
> > > > Oops, too quick to press reply :o
>
> > > > On Tue, Apr 28, 2009 at 11:53 PM, Carlos A. Carnero Delgado >
> > > > destination_file = open('somewhere based on the user', 'wb+')
>
> > > > >  for chunk in request.FILES['audio_file'].chunks():
> > > > >      destination_file.write(chunk)
> > > > >  destination_file.close()
>
> > > > with this method you are manually handling the file, stepping over
> > > > Django's FileField. You should make adjustments & corrections to
> > > > account for that.
>
> > > > Also note that 'audio_file' is just the name of the field, it should
> > > > be named with your field name, of course. Remember also to include
> > > > request.FILES when creating your form object after a POST.
>
> > > > HTH,
> > > > Carlos.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



contrib.auth Group class

2009-04-29 Thread CrabbyPete

Is there any advantage to using the Group class in contrib.auth, over
making your own group. Or is it best to extend Group?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



mystery with my form being saved

2009-04-29 Thread Milan Andric

Hello,

I've been banging my head on this for several hours ... for some
reason on my reservation edit view, the start_when field will not save
but summary does.  The assertEquals always fails on line 198 in the
paste below.  Do you see anything fishy here?

http://dpaste.com/39489/

Is it because my form does not have that field defined so the save
ignores it?  Or am I just going about this wrong by not setting the
value explicitly in the view.  The next thing I am going to try is to
add hidden fields for the fields that I want saved by the form.

Your thoughts are appreciated,

Milan
--~--~-~--~~~---~--~~
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 primary key

2009-04-29 Thread Timboy

Thank you for your time and response Malcom, I appreciate it very
much.

On Apr 29, 3:42 pm, Malcolm Tredinnick 
wrote:
> On Wed, 2009-04-29 at 15:37 -0700, Timboy wrote:
> > I am trying to make a pk for an object that starts with the year
> > followed by seven additional digits. YYXXX I want the digits to
> > automatically increase like normal.
>
> > I'm guessing I need to pass force_insert=True to my save if not
> > self.pk. I'd appreciate some advice.
>
> If you're not using Django's AutoField for primary key values (which you
> aren't), then you need to always supply the primary key value before
> calling save(). Django cannot guess what value you want to put in there.
>
> Now, you could "provide" the value by specifying a (Python) function for
> the "default" attribute on, say, an integer field and use that to create
> the value, although there's then no way to enforce the sequential
> increase if multiple new models are created more or less imsultaneously
> in separate threads.
>
> I would encourage stepping back a bit to consider your problem in a
> different way, which might be much simpler. Use a normal
> auto-incrementing sequence for the primary key in the table (i.e. use
> Django's default) and have another field that specifies the year of
> creation. Then have a property or method on the model which combines the
> year-of-creation field with the pk value to get the combined value
> you're after for display or reference purposes. Modifications on this
> are possible if you're also doing lookups, etc.
>
> Or you could, at the database level, set the sequence value to a
> particular value before doing the first insert for a year. How this is
> done is database dependent and is done with direct database
> modification, not via Django directly (you could do it with
> cursor.execute(), but it's something you only want to do once a year, in
> any case).
>
> 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: manage.py syncdb error

2009-04-29 Thread David

it works now.  thanks Kai.

On Apr 29, 3:54 pm, Kai Kuehne  wrote:
> No TOFU please.
>
> On Thu, Apr 30, 2009 at 12:49 AM, David  wrote:
> > sorry i can not find a database that table
> > 'auth_permission' belongs to. any more hints what i should do?
>
> Did you FLUSH PRIVILEGES?
--~--~-~--~~~---~--~~
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: manage.py syncdb error

2009-04-29 Thread Kai Kuehne

No TOFU please.

On Thu, Apr 30, 2009 at 12:49 AM, David  wrote:
> sorry i can not find a database that table
> 'auth_permission' belongs to. any more hints what i should do?

Did you FLUSH PRIVILEGES?

--~--~-~--~~~---~--~~
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: manage.py syncdb error

2009-04-29 Thread David

sorry i can not find a database that table
'auth_permission' belongs to. any more hints what i should do?

thanks so much.


On Apr 29, 3:35 pm, David  wrote:
> i see. i should grant priviliges on the database that table
> 'auth_permission' belongs to.  let me do it.
>
> thanks.
>
> On Apr 29, 3:32 pm, David  wrote:
>
>
>
> > mysql> show grants;
> > +--­­
> > +
> > | Grants for
> > da...@localhost
> > |
> > +--­­
> > +
> > | GRANT USAGE ON *.* TO 'david'@'localhost' IDENTIFIED BY PASSWORD
> > '*2A032F7C5BA932872F0F045E0CF6B53CF702F2C5' |
> > | GRANT ALL PRIVILEGES ON `david_database`.`david_database` TO
> > 'david'@'localhost'                             |
> > +--­­
> > +
> > 2 rows in set (0.00 sec)
>
> > mysql>
>
> > thanks for your prompt reply. i tried this already. why does not it
> > work?
>
> > On Apr 29, 3:29 pm, Kai Kuehne  wrote:
>
> > > Hi,
>
> > > On Thu, Apr 30, 2009 at 12:17 AM, David  wrote:
> > > > [error message]
> > > > anybody knows how to fix it?
>
> > > Grant CREATE permission for your user on that database.- Hide quoted text 
> > > -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
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 primary key

2009-04-29 Thread Malcolm Tredinnick

On Wed, 2009-04-29 at 15:37 -0700, Timboy wrote:
> I am trying to make a pk for an object that starts with the year
> followed by seven additional digits. YYXXX I want the digits to
> automatically increase like normal.
> 
> I'm guessing I need to pass force_insert=True to my save if not
> self.pk. I'd appreciate some advice.

If you're not using Django's AutoField for primary key values (which you
aren't), then you need to always supply the primary key value before
calling save(). Django cannot guess what value you want to put in there.

Now, you could "provide" the value by specifying a (Python) function for
the "default" attribute on, say, an integer field and use that to create
the value, although there's then no way to enforce the sequential
increase if multiple new models are created more or less imsultaneously
in separate threads.

I would encourage stepping back a bit to consider your problem in a
different way, which might be much simpler. Use a normal
auto-incrementing sequence for the primary key in the table (i.e. use
Django's default) and have another field that specifies the year of
creation. Then have a property or method on the model which combines the
year-of-creation field with the pk value to get the combined value
you're after for display or reference purposes. Modifications on this
are possible if you're also doing lookups, etc.

Or you could, at the database level, set the sequence value to a
particular value before doing the first insert for a year. How this is
done is database dependent and is done with direct database
modification, not via Django directly (you could do it with
cursor.execute(), but it's something you only want to do once a year, in
any case).

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



Custom primary key

2009-04-29 Thread Timboy

I am trying to make a pk for an object that starts with the year
followed by seven additional digits. YYXXX I want the digits to
automatically increase like normal.

I'm guessing I need to pass force_insert=True to my save if not
self.pk. I'd appreciate some advice.

TIA
--~--~-~--~~~---~--~~
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: manage.py syncdb error

2009-04-29 Thread David

i see. i should grant priviliges on the database that table
'auth_permission' belongs to.  let me do it.

thanks.


On Apr 29, 3:32 pm, David  wrote:
> mysql> show grants;
> +--­
> +
> | Grants for
> da...@localhost
> |
> +--­
> +
> | GRANT USAGE ON *.* TO 'david'@'localhost' IDENTIFIED BY PASSWORD
> '*2A032F7C5BA932872F0F045E0CF6B53CF702F2C5' |
> | GRANT ALL PRIVILEGES ON `david_database`.`david_database` TO
> 'david'@'localhost'                             |
> +--­
> +
> 2 rows in set (0.00 sec)
>
> mysql>
>
> thanks for your prompt reply. i tried this already. why does not it
> work?
>
> On Apr 29, 3:29 pm, Kai Kuehne  wrote:
>
>
>
> > Hi,
>
> > On Thu, Apr 30, 2009 at 12:17 AM, David  wrote:
> > > [error message]
> > > anybody knows how to fix it?
>
> > Grant CREATE permission for your user on that database.- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
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 you manage the depenedencies between your project and other open source?

2009-04-29 Thread Kai Kuehne

Hi,

On Wed, Apr 29, 2009 at 10:44 PM, meppum  wrote:
>
> Just wanted to get an idea of what tools others were using to manage
> the dependencies between their code and other projects. For instance,
> if I have a project that uses django registration, voting, and tags
> I'd like to have an automated way of downloading this source code when
> i deploy to new locations. I guess sort of like Maven for Java. What
> are my options?

Capistrano, Fabric, Puppet. I use virtualenv and a custom
bootstrap script like Pinax does.

--~--~-~--~~~---~--~~
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: manage.py syncdb error

2009-04-29 Thread David


mysql> show grants;
+--
+
| Grants for
da...@localhost
|
+--
+
| GRANT USAGE ON *.* TO 'david'@'localhost' IDENTIFIED BY PASSWORD
'*2A032F7C5BA932872F0F045E0CF6B53CF702F2C5' |
| GRANT ALL PRIVILEGES ON `david_database`.`david_database` TO
'david'@'localhost' |
+--
+
2 rows in set (0.00 sec)

mysql>


thanks for your prompt reply. i tried this already. why does not it
work?


On Apr 29, 3:29 pm, Kai Kuehne  wrote:
> Hi,
>
> On Thu, Apr 30, 2009 at 12:17 AM, David  wrote:
> > [error message]
> > anybody knows how to fix it?
>
> Grant CREATE permission for your user on that database.
--~--~-~--~~~---~--~~
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: manage.py syncdb error

2009-04-29 Thread Kai Kuehne

Hi,

On Thu, Apr 30, 2009 at 12:17 AM, David  wrote:
> [error message]
> anybody knows how to fix it?

Grant CREATE permission for your user on that database.

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



manage.py syncdb error

2009-04-29 Thread David

Hi,

i followed django tutorial part 1 to learn django, however i met
following error when i used "python manage.py syncdb".

da...@django:~/mysite$ python manage.py syncdb
Creating table auth_permission
Traceback (most recent call last):
  File "manage.py", line 11, in 
execute_manager(settings)
  File "/usr/lib/python2.5/site-packages/django/core/management/
__init__.py", line 340, in execute_manager
utility.execute()


File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line
166, in execute
self.errorhandler(self, exc, value)
  File "/var/lib/python-support/python2.5/MySQLdb/connections.py",
line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1142, "CREATE command denied to
user 'david'@'localhost' for table 'auth_permission'")
da...@django:~/mysite$

anybody knows how to fix it?

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: Admin css being weird

2009-04-29 Thread Cole

just to add, the images are actually working fine..

On 29 Apr, 22:57, Cole  wrote:
> Hi,
>
> I've used Django a fair bit and have just installed it on a ubuntu-
> based distro.  I've got everything working fine with apache2 and
> mod_python but the admin css,
>
> I have a soft link at /var/www/admin_media ponting to the admin media
> folder and going to something like:
>
> http://localhost/admin_media/img/admin/down_arrow.gif
>
> shows the image fine in the browser - but the admin interface has no
> css or images - except, weirdly on the logout page.
>
> both the logout page and any other admin page have exactly the same
> reference to the CSS:
>
> login (not styled):
>
> 
>
> logout (styled fine):
> 
>
> I've deleted and redone the soft link a couple of times and tried
> trailing slashes in the apache2.conf declarations (below for
> reference) and it's made no difference.
>
> Please help!
>
> Cheers,
> Cole
>
>  APACHE SETTINGS
> MaxRequestsPerChild 1
> 
>     SetHandler python-program
>     PythonHandler django.core.handlers.modpython
>     SetEnv DJANGO_SETTINGS_MODULE blog.settings
>     PythonPath "['/home/cole/web-dev/django_projects'] + sys.path"
> 
>
> 
>     SetHandler None
> 
>
> 
>     SetHandler None
> 
>
> 
>     SetHandler None
> 
--~--~-~--~~~---~--~~
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 css being weird

2009-04-29 Thread Cole

Hi,

I've used Django a fair bit and have just installed it on a ubuntu-
based distro.  I've got everything working fine with apache2 and
mod_python but the admin css,

I have a soft link at /var/www/admin_media ponting to the admin media
folder and going to something like:

http://localhost/admin_media/img/admin/down_arrow.gif

shows the image fine in the browser - but the admin interface has no
css or images - except, weirdly on the logout page.

both the logout page and any other admin page have exactly the same
reference to the CSS:

login (not styled):



logout (styled fine):


I've deleted and redone the soft link a couple of times and tried
trailing slashes in the apache2.conf declarations (below for
reference) and it's made no difference.

Please help!

Cheers,
Cole

 APACHE SETTINGS
MaxRequestsPerChild 1

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE blog.settings
PythonPath "['/home/cole/web-dev/django_projects'] + sys.path"



SetHandler None



SetHandler None



SetHandler None

--~--~-~--~~~---~--~~
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 vs Formsets vs Sessions vs FormWizard ??

2009-04-29 Thread TheCorp

Kevin,

Your fuzzy memory is quite correct. After some research it seems that
you definitely can't do that unless you do some tricky **kwargs stuff
to get around it. The lesson here is that the HTTP spec doesn't want
you to do that and the Django Framework actively dissuades you from
doing things like this. After implementing sessions it definitely
seems like the right approach here. Passing variables became simple, I
no longer needed subclass forms and mangle form data and most
importantly I can use the correct Django style of posting each form to
itself for validation before moving on to the next step. I don't mind
that dead sessions means lost data, the scope of the app means that
this data should definitely not be stored indefinitely.

As for the stored in db option, I will have a path in the code that
allows logged in users to save more of their process while flowing
through the app but in the end it shouldn't be saved at all till the
process is done so sessions still works nicely. Ill see how ugly
things get if I want to enable elegant back and forward buttons
though :)

Thanks again!

Jason

On Apr 29, 11:07 am, Kevin Audleman  wrote:
> TheCorp,
>
> My memory on the issue is rather fuzzy, but I seem to recall that you
> can't pass POST data along with a redirect, and that this has to do
> with the way HTTP is designed.
>
> Using session variables seems like an excellent idea in my opinion.
> One of the reason session variables were invented were to save the
> programmer from having to pass data back-and-forth via forms. One side-
> effect of this will be that if the user's session expires they will
> lose their form data. This could be either good or bad based on your
> needs.
>
> Another option that I have used in the past is to actually store the
> data in the database as the user is going through the form. This would
> require the user to create an account before filling out the form, but
> it has the added benefit that it perfectly stores the state of their
> form, allowing them to stop and restart at will. It also makes it easy
> to create back buttons on each page, which you might find more
> difficult if you are trying to pass form data (I think you'd have to
> write extra code to pass the form backwards).
>
> Cheers,
> Kevin
>
> On Apr 28, 5:40 pm, TheCorp  wrote:
>
> > As a note, I found this post which basically describes my current
> > issue.
>
> >http://groups.google.com/group/django-users/browse_thread/thread/70c0...
>
> > The only problem is that I can't use the PRG approach. Half way
> > through my steps I don't want forms to be displayed via URL/GET params
> > because there will be sensitive info involved.
>
> > Seems to be leaning more and more towards sessions as my only option?
>
> > Thanks :)
>
> > On Apr 28, 3:49 pm, TheCorp  wrote:
>
> > > Hey all, fairly new to the Django community and trying to get a small
> > > side project going. Basically im running into an issue with
> > > architecture in that I am not sure how to proceed.
>
> > > Basically I am trying to code up a reservation system which spans a
> > > few pages. Select a few things, input some text, add your billing info
> > > and reserve. So the problem I am running into and I am fairly certain
> > > this is from my own ineptitude, is that I am not sure the right way to
> > > pass data between all of the pages.
>
> > > Nothing gets posted to the db till the end of the process but data
> > > needs to be saved through each step because each step relies on the
> > > data submitted from the previous step and all the steps before it.
> > > Originally I wasn't even using Django Forms, I was just using Views/
> > > Templates. Each page would have an HTML form that would POST to the
> > > next page/view and I would keep pushing data on via  > > type="hidden"> tags.
>
> > > After reading about Django Forms I figured that would be a good way to
> > > go about doing it because I liked the idea of the built in validation
> > > hooks. The problem I am running into now is that I have each step in
> > > the process represented by a Form and in the template each HTML form
> > > POSTs back to itself. This way I can check whether its validated
> > > before moving on to the next step. The problem I have is that once I
> > > have validated (is_valid()) that the form data was submitted
> > > correctly, I can't seem to pass the request.POST data or the Form
> > > itself onto the next page.
>
> > > I tried return render_to_response('template.html', {'form':form})
> > > which passes the data correctly to a template but then the URL is
> > > messed up because its still the original URL from when the form posted
> > > to itself and things get funky with my URLConf. I also tried to return
> > > via HttpResponseRedirect() with different combinations (using reverse
> > > () and other things) but I still can't seem to pass the POST data
> > > correctly.
>
> > > So basically 

Re: Finding Reason for Form.is_valid()

2009-04-29 Thread Alex Gaynor
On Wed, Apr 29, 2009 at 4:18 PM, Jari Pennanen wrote:

>
> Remember to check also: form.non_field_errors
>
> On Apr 29, 11:59 pm, Ayaz Ahmed Khan  wrote:
> > On 28-Apr-09, at 8:35 PM, Margie wrote:
> >
> > > I often put a break point using pdb
> >
> > > import pdb
> > > pdb.set_trace()
> >
> > > This  causes the server (assuming you are using the django
> > > development server) to drop to the pdb prompt when it hits the
> > > set_trace().
> >
> > > Then I just print the form and look at the output.
> >
> > Oh, that's lovely, indeed. The thought of using the debugger never
> > crossed my mind. The OP may or may not have had a slightly different
> > requirement than mine, but for me the task of debugging a problem when
> > writing unit tests and subsequently the views being tested, may become
> > daunting. I could always drop to an interactive shell, instantiate
> > objects and inspect their contents and stuff, but the alternative to
> > use pdb the way you have suggested is much, much better and more
> > convenient.
> >
> > --
> > Ayaz Ahmed Khan
> >
> > You might have mail.
> >
>
form.non_field_errors are in form.errors with the "__all__" key.

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: Finding Reason for Form.is_valid()

2009-04-29 Thread Jari Pennanen

Remember to check also: form.non_field_errors

On Apr 29, 11:59 pm, Ayaz Ahmed Khan  wrote:
> On 28-Apr-09, at 8:35 PM, Margie wrote:
>
> > I often put a break point using pdb
>
> > import pdb
> > pdb.set_trace()
>
> > This  causes the server (assuming you are using the django
> > development server) to drop to the pdb prompt when it hits the
> > set_trace().
>
> > Then I just print the form and look at the output.
>
> Oh, that's lovely, indeed. The thought of using the debugger never
> crossed my mind. The OP may or may not have had a slightly different
> requirement than mine, but for me the task of debugging a problem when
> writing unit tests and subsequently the views being tested, may become
> daunting. I could always drop to an interactive shell, instantiate
> objects and inspect their contents and stuff, but the alternative to
> use pdb the way you have suggested is much, much better and more
> convenient.
>
> --
> Ayaz Ahmed Khan
>
> You might have 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: Login redirect url truncated

2009-04-29 Thread Bastien

Thanks Malcolm,

That was very informative. I tried the percent encoding trick with no
success. Now I'll try the second part and post here if I am
successful.

Thanks,
Bastien

On Apr 29, 6:50 pm, Malcolm Tredinnick 
wrote:
> On Wed, 2009-04-29 at 07:43 -0700, Bastien wrote:
> > Hi,
>
> > I'm trying to get Django to do the following:
>
> > A user must be logged in to comment on a content. If the user is not
> > logged in then I provide a link to the login page and use the 'next'
> > function to take her back to the content page where the comment box
> > will be waiting for her to fill it.
>
> > It almost works, the only thing is that the comment box can be quite
> > far away down the page if there are lots of comments and I would like
> > to go to it directly adding a '#comment_form' at the end the 'next'
> > url. That's what I do, I call a url that looks like this:
> >http://mysite.com/accounts/login/?next=/content/#comment_formbut the
> > url returned by the login is a stripped down version that doesn't
> > contain the trailing part with the '#comment_form'.
>
> You need to do some URL encoding here and/or possibly something extra in
> the view. The anchor portion of the URL (the part following the "#") is
> not sent to the server when the URL is submitted. This is arguably
> somewhat of a flaw in the way HTTP URI's are interpreted by browsers,
> but that's the way things work, so we have to work with it. You can send
> URLs containing anchor elements from the server to the browser, but
> browsers won't send the anchor to the server.
>
> As a first step, try percent-encoding the "#" (%23). That might then
> work out of the box. If it doesn't, the next step would be to add a
> wrapper around the login view and convert the URL you submit to the URL
> you want to redirect to before calling the real login() view and passing
> in the true target URL.
>
> 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
-~--~~~~--~~--~--~---



Saving Multiple forms? or fields... confused.

2009-04-29 Thread tdelam

Hi,

I am building a small survey app, questions are added to a survey
through django-admin, I am building the form dynamically, when the
form is submitted I only get the first form saving, here is the code:
http://dpaste.com/hold/39401/ Does anyone have any tips on how I can
get the other ones to save when the submit is clicked? Do I need to
loop somewhere prior to saving?
--~--~-~--~~~---~--~~
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: Finding Reason for Form.is_valid()

2009-04-29 Thread Ayaz Ahmed Khan


On 28-Apr-09, at 8:35 PM, Margie wrote:

> I often put a break point using pdb
>
> import pdb
> pdb.set_trace()
>
> This  causes the server (assuming you are using the django
> development server) to drop to the pdb prompt when it hits the
> set_trace().
>
> Then I just print the form and look at the output.


Oh, that's lovely, indeed. The thought of using the debugger never
crossed my mind. The OP may or may not have had a slightly different
requirement than mine, but for me the task of debugging a problem when
writing unit tests and subsequently the views being tested, may become
daunting. I could always drop to an interactive shell, instantiate
objects and inspect their contents and stuff, but the alternative to
use pdb the way you have suggested is much, much better and more
convenient.


-- 
Ayaz Ahmed Khan

You might have 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: Detecting Disabled Cookies

2009-04-29 Thread Tim Chase

>> I thought this would be a common question, but Google doesn't show any
>> Django-specific solutions. What's the general best practice for
>> detecting disabled cookies in a single request?
   ^^^
> 
> Maybe this could help: request.session.test_cookie_worked()

I don't believe there's a way to detect it in a single request. 
The flow usually follows the pattern (C=client, S=server):

C: request a page
S: if no cookie, set a test cookie and redirect to a probe page
C: request the probe page (including or excluding the cookie)
S: now knows whether cookies were (dis/en)abled and deals with it 
accordingly (using Gabriel's suggestion of test_cookie_worked)

-tkc






--~--~-~--~~~---~--~~
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: Detecting Disabled Cookies

2009-04-29 Thread Gabriel .

On Wed, Apr 29, 2009 at 3:46 PM, Chris  wrote:
>
> I thought this would be a common question, but Google doesn't show any
> Django-specific solutions. What's the general best practice for
> detecting disabled cookies in a single request?
>

Maybe this could help: request.session.test_cookie_worked()

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



Detecting Disabled Cookies

2009-04-29 Thread Chris

I thought this would be a common question, but Google doesn't show any
Django-specific solutions. What's the general best practice for
detecting disabled cookies in a single request?

Regards,
Chris
--~--~-~--~~~---~--~~
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: Displaying content in different styles.

2009-04-29 Thread Malcolm Tredinnick

On Wed, 2009-04-29 at 21:11 +0300, Oleg Oltar wrote:
[...]
> Is there a way to check in the loop if it's a first item. And if so to
> process it in a different way? Or do I have pass first article to
> template separately?

Inside a for-loop you have access to a the counter for the loop and
there are some handy booleans for when it's the first or last time
through the loop, too. Have a look at the documentation for the "for"
template tag:
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for

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



Displaying content in different styles.

2009-04-29 Thread Oleg Oltar
Hi!

I created a simple view to display articles on my homepage. Here's the code:

def homepage(request):
news = models.Section.objects.get(section = 'News')

articles = models.Article.objects.exclude(section = news.id
).order_by("-pub_date")
list_of_news = models.Article.objects.filter(section = news.id
).order_by("-pub_date")
return render_to_response('home.html', {'news' : list_of_news[:4],
'articles' : articles[:6]
}


Now I want to make first news item a little bit bigger, and to place it in a
different form.
I am processing the list in a template this way:

{% for item in news %}

  
  {{ item.title }}
  
{{ item.short_description|truncatewords:60}}
  




{% endfor  %}


Is there a way to check in the loop if it's a first item. And if so to
process it in a different way? Or do I have pass first article to template
separately?

Thanks,
Oleg

--~--~-~--~~~---~--~~
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 vs Formsets vs Sessions vs FormWizard ??

2009-04-29 Thread Kevin Audleman

TheCorp,

My memory on the issue is rather fuzzy, but I seem to recall that you
can't pass POST data along with a redirect, and that this has to do
with the way HTTP is designed.

Using session variables seems like an excellent idea in my opinion.
One of the reason session variables were invented were to save the
programmer from having to pass data back-and-forth via forms. One side-
effect of this will be that if the user's session expires they will
lose their form data. This could be either good or bad based on your
needs.

Another option that I have used in the past is to actually store the
data in the database as the user is going through the form. This would
require the user to create an account before filling out the form, but
it has the added benefit that it perfectly stores the state of their
form, allowing them to stop and restart at will. It also makes it easy
to create back buttons on each page, which you might find more
difficult if you are trying to pass form data (I think you'd have to
write extra code to pass the form backwards).

Cheers,
Kevin

On Apr 28, 5:40 pm, TheCorp  wrote:
> As a note, I found this post which basically describes my current
> issue.
>
> http://groups.google.com/group/django-users/browse_thread/thread/70c0...
>
> The only problem is that I can't use the PRG approach. Half way
> through my steps I don't want forms to be displayed via URL/GET params
> because there will be sensitive info involved.
>
> Seems to be leaning more and more towards sessions as my only option?
>
> Thanks :)
>
> On Apr 28, 3:49 pm, TheCorp  wrote:
>
> > Hey all, fairly new to the Django community and trying to get a small
> > side project going. Basically im running into an issue with
> > architecture in that I am not sure how to proceed.
>
> > Basically I am trying to code up a reservation system which spans a
> > few pages. Select a few things, input some text, add your billing info
> > and reserve. So the problem I am running into and I am fairly certain
> > this is from my own ineptitude, is that I am not sure the right way to
> > pass data between all of the pages.
>
> > Nothing gets posted to the db till the end of the process but data
> > needs to be saved through each step because each step relies on the
> > data submitted from the previous step and all the steps before it.
> > Originally I wasn't even using Django Forms, I was just using Views/
> > Templates. Each page would have an HTML form that would POST to the
> > next page/view and I would keep pushing data on via  > type="hidden"> tags.
>
> > After reading about Django Forms I figured that would be a good way to
> > go about doing it because I liked the idea of the built in validation
> > hooks. The problem I am running into now is that I have each step in
> > the process represented by a Form and in the template each HTML form
> > POSTs back to itself. This way I can check whether its validated
> > before moving on to the next step. The problem I have is that once I
> > have validated (is_valid()) that the form data was submitted
> > correctly, I can't seem to pass the request.POST data or the Form
> > itself onto the next page.
>
> > I tried return render_to_response('template.html', {'form':form})
> > which passes the data correctly to a template but then the URL is
> > messed up because its still the original URL from when the form posted
> > to itself and things get funky with my URLConf. I also tried to return
> > via HttpResponseRedirect() with different combinations (using reverse
> > () and other things) but I still can't seem to pass the POST data
> > correctly.
>
> > So basically either I am not understanding how Forms work or I need to
> > use something else like Formsets/Sessions/FormWizard. Anyone have any
> > suggestions? My current idea is to use sessions to store the variables
> > as they flow through the process and POST everything in the final step
> > but tell me what you think. 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: FileField uploading into an user-specific path

2009-04-29 Thread Kevin Audleman

You're in luck, I just programmed this exact thing:

Define the following function right above your model:

def upload_location(instance, filename):
return 'profile_photos/%s/%s' % (instance.user.username,
filename)

My function uses 'profile_photos' as the base directory appended to
MEDIA_ROOT; you might want to rename that. Then in your model, define
your image field as so:

photo_1 = models.ImageField(upload_to=upload_location, blank=True)

Cheers,
Kevin

On Apr 29, 8:12 am, Julián C. Pérez  wrote:
> thanks...
> but...
> how can i make that attribute a callable tto work with user-specif
> paths??
>
> On 29 abr, 03:18, Kip Parker  wrote:
>
> > upload_to can be a callable 
> > -http://docs.djangoproject.com/en/dev/ref/models/fields/#filefield.
>
> > On Apr 29, 4:59 am, "Carlos A. Carnero Delgado"
>
> >  wrote:
> > > Oops, too quick to press reply :o
>
> > > On Tue, Apr 28, 2009 at 11:53 PM, Carlos A. Carnero Delgado >
> > > destination_file = open('somewhere based on the user', 'wb+')
>
> > > >  for chunk in request.FILES['audio_file'].chunks():
> > > >      destination_file.write(chunk)
> > > >  destination_file.close()
>
> > > with this method you are manually handling the file, stepping over
> > > Django's FileField. You should make adjustments & corrections to
> > > account for that.
>
> > > Also note that 'audio_file' is just the name of the field, it should
> > > be named with your field name, of course. Remember also to include
> > > request.FILES when creating your form object after a POST.
>
> > > HTH,
> > > Carlos.
--~--~-~--~~~---~--~~
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 form and template rendering

2009-04-29 Thread Kevin Audleman

As is often the case in django, they have already provided a mechanism
for what you are trying to do the hard way: Formsets.
http://docs.djangoproject.com/en/dev/topics/forms/formsets/

Cheers,
Kevin

On Apr 29, 7:18 am, MarcoS  wrote:
> Hi all,
>    I post a problem, hoping someone can help me:
>
> I want to render a dynamic form which many rows how the number of
> entries from a database table
> (something similar at the list in the "change_list.html" template in
> admin)
>
> This is the model:
>
> class Book(models.Model):
>     title = models.CharField(max_length=100)
>     quantity = models.IntegerField()
>     price = models.DecimalField(max_digits=5, decimal_places=2)
>
> So, I've create this forms.py:
>
> class choose_book_form(forms.Form):
>     def __init__(self, *args, **kwargs):
>         CHOICES = (("1", "1"), ("2", "2"), ("3", "3"))
>         super(choose_book_form, self).__init__(*args, **kwargs)
>         books = Book.objects.all()
>         for item in books:
>             checkbox = 'checkbox_%s' % item.pk
>             self.fields[checkbox] = forms.BooleanField()
>             quantity = 'quantity_%s' % item.pk
>             self.fields[faild] = forms.CharField(max_length=3,
> widget=forms.Select(choices=CHOICES))
>
> The template will have to show rows with this data
>  "checkbox" - "book title" - "select-option" - "book price"
> this is my template
>
> 
> 
> SelectTitleQuantityPrice
> 
> {% for item in books %}
> 
>  {{ form.checkbox_??? }} 
>  {{ item.title }} 
>  {{ form.quantity_??? }} 
>  {{ item.price }} 
> 
> {% endfor %}
> 
> 
> 
>
> The problem is that I can't figure how access the correct pk value
> for  {{ form.checkbox_ }} and {{ form.quantity_ }}
--~--~-~--~~~---~--~~
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: url template tag help

2009-04-29 Thread Kevin Audleman

You might be able to solve your problem by changing the name attribute
of your URL to include  "proyName":

url(r'^about/$', 'view_aboutPage', name='proyName.view_aboutPage'),
 
---

The error message is telling you exactly what it's looking for, after
all:

the error:
"Reverse for 'proyName.view_aboutPage' with arguments '()' and keyword
arguments '{}' not found."

I have solved most of my URL problems this way.

Cheers,
Kevin
--~--~-~--~~~---~--~~
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: url template tag help

2009-04-29 Thread Julián C . Pérez

jajaja it's not top secret
what more information should i provide??

On 29 abr, 11:55, Malcolm Tredinnick  wrote:
> On Wed, 2009-04-29 at 08:10 -0700, Julián C. Pérez wrote:
> > actually... i don't use underscores into my url or views names...
> > that 'view_aboutPage' was actually just a made up example name
>
> Sounds like you need to provide more accurate information then. Provide
> the actual data that is failing. If you can't use the real string from
> your program because it reveals Secret Project Name, then change it to
> something else, but check that the something else *still fails*. Reverse
> URL resolving is not broken, as a concept. Which means it's something
> specific about what you are doing, so the precise details are important.
>
> 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: help, I want restrict usernames available for registrion.

2009-04-29 Thread j0s390

After some time, I got IT... Thanks for your response.
Hre is the solution I got, and yeah - it a Python problem (regular
expression)

from django import forms
from django.forms.util import ErrorList
import re

class ExtraRegForm(forms.Form):
username=forms.CharField(min_length=4, max_length=16)
def clean(self):
cleaned_data=self.cleaned_data
username=cleaned_data.get("username")
pattern='(__)|(\w*)(_)(\w*)(_)(\w*)(_)(\w*)'
u_name=re.search(pattern, username)
if u_name:
msg="No consecutive underscores and no more than 3
underscores"
self._error["username"]=ErrorList(msg)
return cleaned_data
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to deal with problem about ForeignKey

2009-04-29 Thread Phil Mocek

On Wed, Apr 29, 2009 at 03:06:37PM +0800, Vincent wrote:
> The situation is, i have model A and model B, B has a foreignkey
> point to A,.
> 
> now i find that i wanna delete records of A without deleting
> records of B which pointing to A.

You're trying to do something that a relational database
management system is specifically designed to prevent you from
doing.  This would be a violation of referential integrity.

If you delete the foreign key, then the records of B which refer
to it would cease to be valid, destroying the integrity of your
database, so the DBMS shouldn't allow you to do so.  Typically,
you'd configure your DBMS to disallow the deletion from A, cascade
the deletion to B, or update the record in B to NULL or some
default foreign key.

See: 

This information is not specific to Django, but applies to all
relational databases.  Maybe someone else can tell you how to
select one of the aforementioned options using Django's ORM.

-- 
Phil Mocek

--~--~-~--~~~---~--~~
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 to deal with problem about ForeignKey

2009-04-29 Thread Malcolm Tredinnick

On Wed, 2009-04-29 at 01:36 -0700, Margie wrote:
[...]
> Would love to hear a summary of where this might be going from any
> developers!  I realize it is a tough problem - not complaining here.
> Just trying to get a grip on what do do in my own app and whether
> there are any changes coming and if so, what they would be and what
> the timeframe might be.

Here is where it is going: At some point, we would like to have a
manageable solution here. At no point are we interested in putting in
something half-baked. We already have something half-baked and changing
to something else half-baked isn't going to help things. As soon as a
great solution is implemented, we will include it. Until then, people
have to make do and hopefully people for whom this is an obstacle to
their work will be sufficiently motivated to come up with aforementioned
great solution.

When all that will happen is no more specific than "when it's done",
simply because we can't be more specific than that.

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: Admin menu not logging in

2009-04-29 Thread Phil Mocek

On Wed, Apr 29, 2009 at 09:34:55AM -0700, Jordash wrote:
> How would I go about creating a super user?

What I would do is use Google to search the Web for "django create
superuser":



and follow the link to the very first result:



Or see the in-built help for the Django management utility or the
manage.py by running:

django-admin.py help

or

manage.py help


Or, assuming you're on a UNIX-like operating system such as
GNU/Linux or Apple Mac OS X, check the man page for the admin
util:

man django-admin.py



You need to run either:

manage.py createsuperuser

or:

django-admin.py createsuperuser

-- 
Phil Mocek

--~--~-~--~~~---~--~~
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: url template tag help

2009-04-29 Thread Malcolm Tredinnick

On Wed, 2009-04-29 at 08:10 -0700, Julián C. Pérez wrote:
> actually... i don't use underscores into my url or views names...
> that 'view_aboutPage' was actually just a made up example name

Sounds like you need to provide more accurate information then. Provide
the actual data that is failing. If you can't use the real string from
your program because it reveals Secret Project Name, then change it to
something else, but check that the something else *still fails*. Reverse
URL resolving is not broken, as a concept. Which means it's something
specific about what you are doing, so the precise details are important.

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: url template tag help

2009-04-29 Thread Malcolm Tredinnick

On Wed, 2009-04-29 at 03:17 -0700, Christian Berg wrote:
> it also helps to rename the URL to view-about-page. Dashed do work.
> It seems that URL Namen are bound to slug resitrictions.

Slugs have nothing to do with it. If you can't use underscores in URL
pattern names, it's a bug. Create a small test case and open a ticket
(if one doesn't already exist) so that we don't forget to fix it.

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: Admin menu not logging in

2009-04-29 Thread Karen Tracey
On Wed, Apr 29, 2009 at 12:34 PM, Jordash  wrote:

>
> Hey All,
>
> I'm really new to Django (have PHP background)
>
> I'm following this tutorial here:
>
> http://docs.djangoproject.com/en/dev/intro/tutorial01/
>
> And for some reason a super user was never created during the process
> and so I can't login to the /admin directory.  How would I go about
> creating a super user?
>

manage.py has a createsuperuser command you can use for this.  See:
http://docs.djangoproject.com/en/dev/ref/django-admin/#createsuperuser

Karen

--~--~-~--~~~---~--~~
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: Login redirect url truncated

2009-04-29 Thread Malcolm Tredinnick

On Wed, 2009-04-29 at 07:43 -0700, Bastien wrote:
> Hi,
> 
> I'm trying to get Django to do the following:
> 
> A user must be logged in to comment on a content. If the user is not
> logged in then I provide a link to the login page and use the 'next'
> function to take her back to the content page where the comment box
> will be waiting for her to fill it.
> 
> It almost works, the only thing is that the comment box can be quite
> far away down the page if there are lots of comments and I would like
> to go to it directly adding a '#comment_form' at the end the 'next'
> url. That's what I do, I call a url that looks like this:
> http://mysite.com/accounts/login/?next=/content/#comment_form but the
> url returned by the login is a stripped down version that doesn't
> contain the trailing part with the '#comment_form'.

You need to do some URL encoding here and/or possibly something extra in
the view. The anchor portion of the URL (the part following the "#") is
not sent to the server when the URL is submitted. This is arguably
somewhat of a flaw in the way HTTP URI's are interpreted by browsers,
but that's the way things work, so we have to work with it. You can send
URLs containing anchor elements from the server to the browser, but
browsers won't send the anchor to the server.

As a first step, try percent-encoding the "#" (%23). That might then
work out of the box. If it doesn't, the next step would be to add a
wrapper around the login view and convert the URL you submit to the URL
you want to redirect to before calling the real login() view and passing
in the true target URL.

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



Admin menu not logging in

2009-04-29 Thread Jordash

Hey All,

I'm really new to Django (have PHP background)

I'm following this tutorial here:

http://docs.djangoproject.com/en/dev/intro/tutorial01/

And for some reason a super user was never created during the process
and so I can't login to the /admin directory.  How would I go about
creating a super user?

Thanks,

Jordan

--~--~-~--~~~---~--~~
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: FileField uploading into an user-specific path

2009-04-29 Thread Julián C . Pérez

thanks...
but...
how can i make that attribute a callable tto work with user-specif
paths??

On 29 abr, 03:18, Kip Parker  wrote:
> upload_to can be a callable 
> -http://docs.djangoproject.com/en/dev/ref/models/fields/#filefield.
>
> On Apr 29, 4:59 am, "Carlos A. Carnero Delgado"
>
>  wrote:
> > Oops, too quick to press reply :o
>
> > On Tue, Apr 28, 2009 at 11:53 PM, Carlos A. Carnero Delgado >
> > destination_file = open('somewhere based on the user', 'wb+')
>
> > >  for chunk in request.FILES['audio_file'].chunks():
> > >      destination_file.write(chunk)
> > >  destination_file.close()
>
> > with this method you are manually handling the file, stepping over
> > Django's FileField. You should make adjustments & corrections to
> > account for that.
>
> > Also note that 'audio_file' is just the name of the field, it should
> > be named with your field name, of course. Remember also to include
> > request.FILES when creating your form object after a POST.
>
> > HTH,
> > Carlos.
--~--~-~--~~~---~--~~
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: help, I want restrict usernames available for registrion.

2009-04-29 Thread Karen Tracey
On Wed, Apr 29, 2009 at 10:01 AM, j0s390  wrote:

>
> I want all usernames to have at most two underscores and the
> underscores not to be consercutive...
> I tried this by creating an ExtraRegForm(models.Model) and putting
> username=models.CharField(min_length=4, max_length=16)
> and tried the validation process by using re.search to see if username
> meets the above standards and I failed.
> Please help me...
>
> from django import forms
> import re
>
> class ExtraRegForm(models.Model)
>   username=models.CharField(min_length=4, max_length=16)
>
>   def clean(self):
> # the check here (by regular expression or other)
>
> Help if you can
>

You would likely get better help if you were a bit more specific about the
trouble you are running into.  Are you unable to get your regex and
re.search to work the way you want?  If so, that's purely a Python thing and
would be better asked about someplace like comp.lang.python.

If, on the other hand, you are having trouble getting your custom form to be
used, then that would be a Django problem to ask about here.  But you'd have
to include a lot more information about what you have done, what software
exactly you are using (your use of the term 'registration' makes me think
you may be using django-registration, but I'm not sure), and where things
seem to be not working.

Karen

--~--~-~--~~~---~--~~
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: url template tag help

2009-04-29 Thread Julián C . Pérez

actually... i don't use underscores into my url or views names...
that 'view_aboutPage' was actually just a made up example name

On 29 abr, 05:17, Christian Berg  wrote:
> it also helps to rename the URL to view-about-page. Dashed do work.
> It seems that URL Namen are bound to slug resitrictions.
>
> On 29 Apr., 03:06, Julián C. Pérez  wrote:
>
> > hi everyone
> > i need some help over here... please!
> > i don't know what it's wrong...
>
> > the url i'm trying to get around is:http://proyName/about/
>
> > the error:
> > "Reverse for 'proyName.view_aboutPage' with arguments '()' and keyword
> > arguments '{}' not found."
>
> > in a template, the dispatcher of the error:
> > # template.html
> > ...
> > a link to the 'about' page
> > ...
>
> > i have a general urls.py file who looks like:
> > # proyName/urls.py
> > ...
> > url(r'^/', include('proyName.package.appName.urls')),
> > ...
> > where appName includes the 'view_aboutPage' view in its views.py
> > 'package' it's just a folder to wrap up all the available apps
>
> > and also i have a urls.py file in appName, and it is:
> > # proyName/package/appName/urls.py
> > ...
> > url(r'^about/$', 'view_aboutPage', name='view_aboutPage'),
> > ...
>
> > please... help!
> > what is it wrong in there??
> > thank u all
> > bye!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Login redirect url truncated

2009-04-29 Thread Bastien

Hi,

I'm trying to get Django to do the following:

A user must be logged in to comment on a content. If the user is not
logged in then I provide a link to the login page and use the 'next'
function to take her back to the content page where the comment box
will be waiting for her to fill it.

It almost works, the only thing is that the comment box can be quite
far away down the page if there are lots of comments and I would like
to go to it directly adding a '#comment_form' at the end the 'next'
url. That's what I do, I call a url that looks like this:
http://mysite.com/accounts/login/?next=/content/#comment_form but the
url returned by the login is a stripped down version that doesn't
contain the trailing part with the '#comment_form'.

Any idea on what I missed?

thanks,
Bastien
--~--~-~--~~~---~--~~
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: Optimistic Locking in the Admin

2009-04-29 Thread Andrew Smith
Hello,

I've recently been tackling almost the same thing. I'm using Google App
Engine and app-engine-patch so I can't help you on the best method for
implementing the optimistic locking at the database level to avoid race
conditions (though I'm even more lost as to how to achieve the same thing
using the datastore)

What has me stumped is what the best method is for hiding the field
containing the timestamp. I'm manually setting the widget for the field on
the form in the admin system to be a HiddenField but it still displays the
label and surrounding divs. I've come up with a workaround but it is pretty
ugly. Am I doing something dumb?

Andy

2009/4/29 PierreR 

>
> Hello,
>
> I have been searching the group on the subject but have not managed to
> pull a satisfactory solution out of it.
>
> How is the recommended way to implement optimistic locking in the
> django admin ?
>
> Let's say I have a version field or timestamp sent to the user-agent
> together with the record (the classic solution). I need to compare the
> value with the database version of it. I probably need to read the db
> value with a "select for update" or to use "update where
> timestamp=:timestamp" to avoid a race condition between the version
> check and the update.
>
> A warning message to the user should be sent if the record has been
> concurrently updated (with the data previouly sent). Where do I code
> the following ? (I am not planning to implement any merging
> functionnaly)
>
> I have started with a pre_save signal but it is probably not the best
> way to "decorate" the save process (is it ?). I probably want to
> change the save() into an "update where" or at least cancel it.
>
> Is it safer/useful to use
> django.middleware.transaction.TransactionMiddleware together with Form
> in that context ? Where are the hooks ?
>
> In short how to I plumb this together ?
>
> Thanks so much for your advices.
>
> >
>

--~--~-~--~~~---~--~~
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 form and template rendering

2009-04-29 Thread MarcoS

Hi all,
   I post a problem, hoping someone can help me:

I want to render a dynamic form which many rows how the number of
entries from a database table
(something similar at the list in the "change_list.html" template in
admin)

This is the model:

class Book(models.Model):
title = models.CharField(max_length=100)
quantity = models.IntegerField()
price = models.DecimalField(max_digits=5, decimal_places=2)

So, I've create this forms.py:

class choose_book_form(forms.Form):
def __init__(self, *args, **kwargs):
CHOICES = (("1", "1"), ("2", "2"), ("3", "3"))
super(choose_book_form, self).__init__(*args, **kwargs)
books = Book.objects.all()
for item in books:
checkbox = 'checkbox_%s' % item.pk
self.fields[checkbox] = forms.BooleanField()
quantity = 'quantity_%s' % item.pk
self.fields[faild] = forms.CharField(max_length=3,
widget=forms.Select(choices=CHOICES))

The template will have to show rows with this data
 "checkbox" - "book title" - "select-option" - "book price"
this is my template



SelectTitleQuantityPrice

{% for item in books %}

 {{ form.checkbox_??? }} 
 {{ item.title }} 
 {{ form.quantity_??? }} 
 {{ item.price }} 

{% endfor %}




The problem is that I can't figure how access the correct pk value
for  {{ form.checkbox_ }} and {{ form.quantity_ }}
--~--~-~--~~~---~--~~
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 templating workaround needed

2009-04-29 Thread Kai Kuehne

Hi,

On Wed, Apr 29, 2009 at 3:50 PM, deostroll  wrote:
>
> Hi,
>
> I cannot render a template written like this:
>
[code]
>
> Please suggest a work around, thanx in advance.

Try {% instead of (%.

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



help, I want restrict usernames available for registrion.

2009-04-29 Thread j0s390

I want all usernames to have at most two underscores and the
underscores not to be consercutive...
I tried this by creating an ExtraRegForm(models.Model) and putting
username=models.CharField(min_length=4, max_length=16)
and tried the validation process by using re.search to see if username
meets the above standards and I failed.
Please help me...

from django import forms
import re

class ExtraRegForm(models.Model)
   username=models.CharField(min_length=4, max_length=16)

   def clean(self):
 # the check here (by regular expression or other)

Help if you can

--~--~-~--~~~---~--~~
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 templating workaround needed

2009-04-29 Thread deostroll

Hi,

I cannot render a template written like this:



Name
Phone
Group

(% for x in contacts %}

{{ x.ContactName }}


{{ x.ContactPhone }}

{{ x.ContactGroup }}

(% endfor %}


Please suggest a work around, thanx in advance.

--deostroll
PS: trying to get this work in google appengine.

--~--~-~--~~~---~--~~
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: ForeignKey Select List Filter

2009-04-29 Thread cfiles

Let me try to explain this a little more. Here are some example models

class Account(models.Model):
user = models.ForeignKey(User)
name= models.CharField('Name on Account', max_length=100)
description = models.CharField(max_length=100)
date_added  = models.DateField(auto_now_add=True, blank=True)

class Payment(models.Model):
account = models.ForeignKey(Account)
date_paid   = models.DateField(auto_now_add=True, blank=True)
amount  = models.DecimalField(max_digits=10, decimal_places=2)

When I display the form for a Payment I get all of the Account
objects. I want to limit the list to accounts that the user owns. How
is this done? I have looked an I am unable to find the documentation
for it.

On Apr 27, 1:27 pm, cfiles  wrote:
> I have a model with a ForeignKeyto another model. Is it possible to filter 
> the HTML select list for the foreign object from a view?
--~--~-~--~~~---~--~~
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: Decoding django user password

2009-04-29 Thread Miguel
thank you guys!

Miguel
Sent from Madrid, Spain

On Wed, Apr 29, 2009 at 2:22 PM, Ned Batchelder wrote:

>
> If you want to login as a user, don't bother with their password (which
> can't be decoded anyway).  Build another authorization mechanism into
> your app so that you can log in as them without a password.  For
> example, you can accept a user name with a password of (superuser name,
> superuser password) and then log the user in.  More details here:
>
> http://stackoverflow.com/questions/263367/how-do-you-support-a-web-app-with-hashed-or-encrypted-passwords
>
> --Ned.
> http://nedbatchelder.com
>
> Miguel wrote:
> > Hello,
> >
> > is there any way to decode the passwords that django keeps the the
> > auth_user table? It would be really interesting to see if there is any
> > problems in the users part of the web when new information and tasks
> > are added via admin web.
> >
> > regards,
> >
> >
> >
> > Miguel
> > Sent from Madrid, Spain
> > >
>
> --
> Ned Batchelder, http://nedbatchelder.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
-~--~~~~--~~--~--~---



Sequence number generation

2009-04-29 Thread mettwoch

Hi,

I'm rather new to Django (and webapp development) and I'd appreciate
any advice on the following problem.

I've a model named 'document' that can hold any kind of documents like
customer invoices, supplier invoices, goods returned, ..., but I've to
ensure that the customer invoices be numbered in sequence regardless
of the fact that there may be one customer invoice entered in the
system and then some supplier invoices and then again some customer
invoices. I've also a model holding the 'document type'. That model
could hold an Integer Field that is incremented at the creation of
every document type separately, but that has to be done in a
transaction together with the document creation:

begin-transaction
document_type['customer invoice'].number += 1
d = document(number = document_type['customer invoice'].number,
document_type = 'customer invoice', ...
...
end-transaction

Is that kind of mechanism working? Do you have any other suggestion?

Kind regards
Marc
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



TypeError: coercing to Unicode: need string or buffer, ImageWithThumbnailsFieldFile found

2009-04-29 Thread joker

i am using sorl.thumbnail. i wanna use templatetags for my home page.
i wanna show my special products on home page. i write templatetags

# -*- coding: utf-8-*-
from django.template import Library, Node
from kent.emlak.models import Emlaklar

register = Library()

def vitrin_menu():
vitrinlistesi = Emlaklar.objects.all()
vitrinmenu = ''
for i in range(len(vitrinlistesi)):
if vitrinlistesi[i].vitrineekle:
vitrinmenu += ''+''+vitrinlistesi[i].ilanadi+''+'Metrekare:'+vitrinlistesi[i].image1+''

return vitrinmenu

register.simple_tag(vitrin_menu)

but when i add product and open home page i have this error

TypeError: coercing to Unicode: need string or buffer,
ImageWithThumbnailsFieldFile found

--~--~-~--~~~---~--~~
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 model field assignments

2009-04-29 Thread Dennis Schmidt

thanks, that was just what I was looking for :-)
never used this**thing before

On 29 Apr., 14:02, Daniel Roseman 
wrote:
> On Apr 29, 12:09 pm, Dennis Schmidt 
> wrote:
>
>
>
>
>
> > Hi Mike,
>
> > thanks a lot but that was unfortunately not what I ment. Your
> > assignmements are static in
>
> > In [2]: n = TestFun(name="mike", description="Testing is always
> > fun.")
>
> > but I need them to be dynamic. So in the above case NAME wouldn't be
> > hardcoded but come from a dictionary. {'name': 'mike'} like this.
> > I just found at least some way:
>
> > newCustomer = Customer()
> >     for key, value in params.iteritems():
> >         newCustomer.__setattr__(key, value)
>
> > where PARAMS is my dictionary. It works but I don't think this is
> > really elegant...
>
> You can just do this:
> newCustomer = Customer.objects.create(**params)
> --
> 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: Decoding django user password

2009-04-29 Thread Ned Batchelder

If you want to login as a user, don't bother with their password (which 
can't be decoded anyway).  Build another authorization mechanism into 
your app so that you can log in as them without a password.  For 
example, you can accept a user name with a password of (superuser name, 
superuser password) and then log the user in.  More details here: 
http://stackoverflow.com/questions/263367/how-do-you-support-a-web-app-with-hashed-or-encrypted-passwords

--Ned.
http://nedbatchelder.com

Miguel wrote:
> Hello,
>
> is there any way to decode the passwords that django keeps the the 
> auth_user table? It would be really interesting to see if there is any 
> problems in the users part of the web when new information and tasks 
> are added via admin web.
>
> regards,
>
>
>
> Miguel
> Sent from Madrid, Spain
> >

-- 
Ned Batchelder, http://nedbatchelder.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: annotation and grouping

2009-04-29 Thread Russell Keith-Magee

On Wed, Apr 29, 2009 at 4:08 PM, omat  wrote:
>
> Hi all,
>
> I would like to fetch the latest entries for each user from a model
> like:
>
> class Entry(models.Model):
>    user = models.ForeignKey(User)
>    entry = models.TextField()
>    date = models.DateTimeField(auto_now_add=True)
>
> Is it possible with the current API with a single query?

Not easily. You can get the date of the most recent entry for each user:

Entry.objects.values('user').annotate(Max('date'))

but you can't get the full entry object for each date without using
extra() or doing some other join gymnastics.

> I.e., wouldn't it be great to have something like:
>
> Entry.objects.annotate(Max('added'), group_by=['user']).filter
> (date=date__max)

And what does this mean in SQL? Once you've posed your original
question in SQL, you may see why your proposal isn't really viable.

If you're a MySQL user, I'm sure your initial suggestion will be something like:

SELECT id, user_id, entry, MAX("date") FROM entries GROUP BY user_id

The problem is that while this is legal for MySQL (and SQLite), this
isn't legal SQL on other backends (notably Postgres; I'm pretty sure
Oracle is in the same boat). The problem is that Postgres requires
that every field that isn't an aggregate be part of the GROUP BY
clause. This is for a very good reason - which value for id and entry
should be included in the result set?

If the problem isn't clear, consider the following slightly modified query:

SELECT id, user_id, entry, MAX("date"), MIN("date") FROM entries GROUP
BY user_id

Now - which entry and ID should be included in the results? The one
corresponding to the MAX or the MIN?

The problem here is that SQLite and MySQL are lax when it comes to the
relational algebra. For simple cases, this laxness may not matter, but
for non-trivial cases it matters a great deal.

To address the group_by suggestion specifically - we deliberately
avoided adding explicit support for group_by. Django's ORM attempts to
look like a collection of Objects, not a wrapper around SQL. GROUP BY
is a very SQL heavy concept that doesn't have much meaning with other
backends.

In order to do this in a purely relational sense, you need to use an
inner query to build the table of userid-max date, then join this
result with the original entries to select the rows where the user ids
and dates match. However, queries like this aren't easy to compose in
using pure Django ORM syntax.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
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: Decoding django user password

2009-04-29 Thread Kenneth Gonsalves

On Wednesday 29 April 2009 17:17:42 Miguel wrote:
> is there any way to decode the passwords that django keeps the the
> auth_user table?

afaik it is one way only
-- 
regards
kg
http://lawgon.livejournal.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: Decoding django user password

2009-04-29 Thread Karen Tracey
On Wed, Apr 29, 2009 at 7:47 AM, Miguel  wrote:

> Hello,
>
> is there any way to decode the passwords that django keeps the the
> auth_user table? It would be really interesting to see if there is any
> problems in the users part of the web when new information and tasks are
> added via admin web.
>

No.  For more information search the list and you'll find, for example, this
thread:

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

which details why and why that is a good thing.

If you want to test things out as they would be seen by a non-staff,
non-superuser user, why not just define one (or more) for testing purposes
and use them?  It shouldn't be necessary to actually log in as one of your
real users for testing purposes.

Karen

--~--~-~--~~~---~--~~
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: Decoding django user password

2009-04-29 Thread Masklinn

On 29 Apr 2009, at 13:47 , Miguel wrote:
> Hello,
>
> is there any way to decode the passwords that django keeps the the  
> auth_user
> table?
No. The passwords are stored salted hashes 
(http://en.wikipedia.org/wiki/Salted_hash 
), you can try brute-forcing them if you have *a lot* of time (and cpu  
time) to waste.


--~--~-~--~~~---~--~~
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 model field assignments

2009-04-29 Thread Karen Tracey
On Wed, Apr 29, 2009 at 7:09 AM, Dennis Schmidt
wrote:

>
> Hi Mike,
>
> thanks a lot but that was unfortunately not what I ment. Your
> assignmements are static in
>
> In [2]: n = TestFun(name="mike", description="Testing is always
> fun.")
>
> but I need them to be dynamic. So in the above case NAME wouldn't be
> hardcoded but come from a dictionary. {'name': 'mike'} like this.


You can pass a dictionary instead of keyword arguments. This is a standard
Python, and works in general, there's nothing specific about the Django
model creation routines here:

>>> a1 = 'name'
>>> a2 = 'description'
>>> d = { a1:'mike', a2:'Testing is always fun'}
>>> tf = TestFun(**d)
>>> tf.save()
>>> TestFun.objects.all()
[]
>>> d[a1] = 'Sue'
>>> TestFun.objects.create(**d)

>>> TestFun.objects.all()
[, ]
>>>

Karen

--~--~-~--~~~---~--~~
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 change list filters as select boxes?

2009-04-29 Thread kurak

I have an application that needs lots of filters for object list in
Admin app.
The filters currently take up quite a lot of space (~1400px ) I'd like
to change them to select boxes and my best idea to modify DOM with
some javascript or to patch django (that I'd prefer not to) but I
wonder if it is possible to change it in a more clear manner? I
consider patching too messy and JS too unreliable.

Cheers,
kurak
--~--~-~--~~~---~--~~
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 model field assignments

2009-04-29 Thread Daniel Roseman

On Apr 29, 12:09 pm, Dennis Schmidt 
wrote:
> Hi Mike,
>
> thanks a lot but that was unfortunately not what I ment. Your
> assignmements are static in
>
> In [2]: n = TestFun(name="mike", description="Testing is always
> fun.")
>
> but I need them to be dynamic. So in the above case NAME wouldn't be
> hardcoded but come from a dictionary. {'name': 'mike'} like this.
> I just found at least some way:
>
> newCustomer = Customer()
>     for key, value in params.iteritems():
>         newCustomer.__setattr__(key, value)
>
> where PARAMS is my dictionary. It works but I don't think this is
> really elegant...

You can just do this:
newCustomer = Customer.objects.create(**params)
--
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
-~--~~~~--~~--~--~---



Decoding django user password

2009-04-29 Thread Miguel
Hello,

is there any way to decode the passwords that django keeps the the auth_user
table? It would be really interesting to see if there is any problems in the
users part of the web when new information and tasks are added via admin
web.

regards,



Miguel
Sent from Madrid, Spain

--~--~-~--~~~---~--~~
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 model field assignments

2009-04-29 Thread Dennis Schmidt

Hi Mike,

thanks a lot but that was unfortunately not what I ment. Your
assignmements are static in

In [2]: n = TestFun(name="mike", description="Testing is always
fun.")

but I need them to be dynamic. So in the above case NAME wouldn't be
hardcoded but come from a dictionary. {'name': 'mike'} like this.
I just found at least some way:

newCustomer = Customer()
for key, value in params.iteritems():
newCustomer.__setattr__(key, value)

where PARAMS is my dictionary. It works but I don't think this is
really elegant...


On 29 Apr., 13:00, Mike Ramirez  wrote:
> On Wednesday 29 April 2009 03:24:48 am Dennis Schmidt wrote:
>
>
>
>
>
> > Hi there,
>
> > this might be a trivial question but my search within the django
> > documentation and google didn't give me any helpful results.
> > In Ruby on Rails you can simply do this
>
> > x = Model.new({:param_x => 'x', :param_y => 'y'})
>
> > where the params are some model fields. The hash you can provide there
> > can be created on the fly. How can I do this in django??? I don't know
> > which fields I will set at a certain point and for all the fields I
> > don't set there I want the model-field's default value to be used. But
> > since I can only hardcode which attributes / fields I will assign this
> > is not really possible.
>
> > But I guess there MUST be a way to this. Only how?
>
> > thanks in advance, Dennis
>
> Is this what you want:
>
> Sample Model:
>
> class TestFun(models.Model):
>         name = models.CharField(max_length=50)
>         url = models.URLField(blank=True, null=True)
>         description = models.TextField()
>         new = models.BooleanField(default=True)
>
>         def __unicode__(self):
>                 return "%s" %(self.name)
>
> Shell creating a new object with only the name and description parameters:
>
> In [1]: from testfun.models import TestFun
>
> In [2]: n = TestFun(name="mike", description="Testing is always fun.")
>
> In [3]: n.save()
>
> In [4]: objs = TestFun.objects.get(name__exact="mike")
>
> In [5]: objs.new
>
> Out[5]: True
>
> In [6]: objs.url
>
> In [7]: objs.description
>
> Out[7]: u'Testing is always fun.'
>
> In [8]: objs.name
>
> Out[8]: u'mike'
>
> As you can see, I instiated my model "TestFun" with only the name and
> description parameters, then saved it.  The new field was set with the
> default setting of true, url I didn't have to enter, since it was set
> null=True (blank is for forms and allowing this field to be blank during
> validation).
>
> I could have easily done TestFun(name="mike", description="Testing is always
> fun.", new=False) to use a non default value for the 'new' parameter.
>
> To sum it up models are treated like normal python classes.[1]
>
> there is also two shortcuts, Model.objects.create() which returns a bound
> model instance, which is already saved for you [2]
>
> In addition to that there is a Model.objects.get_or_create() which returns a
> set of the bound model and a bool for saying if it was created or not.
> get_or_create follows create() in the docs, see [2].
>
> Mike
>
> [1]http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddo...
>
> [2]http://docs.djangoproject.com/en/dev/ref/models/querysets/#create-kwargs
>
> --
> It is said that the lonely eagle flies to the mountain peaks while the lowly
> ant crawls the ground, but cannot the soul of the ant soar as high as the
> eagle?
>
>  signature.asc
> < 1 KBAnzeigenHerunterladen
--~--~-~--~~~---~--~~
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 on Amazon EC2

2009-04-29 Thread Jörn Paessler

Hi Joshua,

we have been hosting our django sites on EC2 for about 9 months now.

We are quite happy with it but there are some things you have to take  
care of:
- we recently had a downtime, because the host system crashed. We had  
a new instance up and running pretty fast but you have to keep in  
mind: there is no self-healing mechanism to e.g. broken HDD on EC2.  
You need to have a backup plan. An Amazon support employeee send me  
this reply afterwards:
"Instances depend on the health of the underlying host. The component  
that breaks most often are hard disks, so if the instance had any data  
stored on the disk, it may not be recoverable if there was a fatal  
failure, so moving an instance is not easily possible. In general, we  
recommend that you architect your system in a way so that a single  
instance failure does not disrupt the overall operation of your  
system. We also recommend keeping current backups."
- For planning your infrastructure this blogentry might be quite  
helpful:
   "Experiences deploying a large-scale infrastructure in Amazon EC2 "
   

- we do manage every ressource with SVN. Even the SQL-dumps are  
periodically persisted via SVN. For our sites (90% corporate websites)  
this is a possible solution. I wouldn't recommend this for community  
websites.
- On the high traffic sites we serve the media with Cloudfront. Runs  
very smooth.
- Site data, logs and config-files are located on a mounted EBS.
- The best deal for the buck is a medium instance, find more  
information here:

"Our conclusion of these tests is that we will mostly use the  
“c1.medium” instances (”High CPU Medium Instance”) for webhosting and  
other performance-relevant uses because it offers 150-300% more  
performance (for CPU, disk and memory) than “m1.small” instances while  
only costing 100% more."

Hope that information helps!

Have a great day!

Best
Joern

---
beyond content GmbH
Dipl.-Ing. Jörn Paessler
Geschäftsführer
Burgschmietstr. 10
90419 Nürnberg, Germany
E-Mail: joern.paess...@beyond-content.de
Web: www.beyond-content.de
Fon: +49 (0)911 977 98162
Fax:  +49-(0)911 787 2525
Geschäftsführer: Dipl.-Ing. Jörn Paessler
Sitz der Gesellschaft: Nürnberg
Handelsregister: Amtsgericht Nürnberg HRB 23740
USt-IdNr.: DE247571538

Am 29.04.2009 um 05:41 schrieb Joshua Partogi:

>
> Dear all,
>
> In favor of choosing Google app engine to run our Django apps, we are
> also considering Amazon EC2 because from what we've read we  are  not
> tightly locked into Google API. Has anyone here had any experience on
> deploying django apps on Amazon EC2 that would like to share their
> experience?
>
> Thank you very much for sharing. We really appreciate it.
>
> -- 
> If you can't believe in God the chances are your God is too small.
>
> Read my blog: http://joshuajava.wordpress.com/
> Follow us on twitter: http://twitter.com/scrum8
>
> >


--~--~-~--~~~---~--~~
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: HTML Forms and Sessions - Help!

2009-04-29 Thread Alfonso

Daniel,

Thanks.. point taken

I'm still a bit of a n00b so bear with me:

So I'm trying to store the form fields in sessions , user navigates
to /search/ and can then use the search form there to search/refine
the results.

http://dpaste.com/hold/39182/

thats the main form

and the code in Django:

http://dpaste.com/hold/39184/

Tried creating the session data (if field is in request.GET, add to
session data) then deleting it from the session once I've passed that
checkbox True/False to the template.

in the template I'm checking to see whether that default has passed
through then setting the checkbox state on that

Al

On 29 Apr, 11:07, Daniel Roseman 
wrote:
> On Apr 29, 10:15 am, Alfonso  wrote:
>
> > Hi,
>
> > Leading on from a post I made a few days ago I'm having real trouble
> > dealing with sessions to preserve form state and the standard HTML for
> > I placed in the template.  I can't seem to get to the session data for
> > the form once submitted (via GET) and I'm wondering is that due to the
> > fact it's a standard HTML form, not a django form?
>
> > Its a search form that allows users to refine results so I figured
> > setting it up as a POST was going to be overkill but now I wonder if
> > POST and sessions are connected?  Am I going to save time if I rewrite
> > the form as a django form (want to avoid that if I can)
>
> > Thanks anyone
>
> What do you mean by 'the session data for the form'? Django's sessions
> framework only saves data if you tell it to. There's no automatic
> session data associated with a Django form.
>
> Perhaps if you post some code showing what you have done so far and
> what you are trying to do, we can help you more.
> --
> 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: dynamic model field assignments

2009-04-29 Thread Mike Ramirez
On Wednesday 29 April 2009 03:24:48 am Dennis Schmidt wrote:
> Hi there,
>
> this might be a trivial question but my search within the django
> documentation and google didn't give me any helpful results.
> In Ruby on Rails you can simply do this
>
> x = Model.new({:param_x => 'x', :param_y => 'y'})
>
> where the params are some model fields. The hash you can provide there
> can be created on the fly. How can I do this in django??? I don't know
> which fields I will set at a certain point and for all the fields I
> don't set there I want the model-field's default value to be used. But
> since I can only hardcode which attributes / fields I will assign this
> is not really possible.
>
> But I guess there MUST be a way to this. Only how?
>
> thanks in advance, Dennis

Is this what you want:

Sample Model:

class TestFun(models.Model):
name = models.CharField(max_length=50)
url = models.URLField(blank=True, null=True)
description = models.TextField()
new = models.BooleanField(default=True)

def __unicode__(self):
return "%s" %(self.name)

Shell creating a new object with only the name and description parameters:

In [1]: from testfun.models import TestFun

In [2]: n = TestFun(name="mike", description="Testing is always fun.")

In [3]: n.save()

In [4]: objs = TestFun.objects.get(name__exact="mike")

In [5]: objs.new

Out[5]: True

In [6]: objs.url

In [7]: objs.description

Out[7]: u'Testing is always fun.'

In [8]: objs.name

Out[8]: u'mike'


As you can see, I instiated my model "TestFun" with only the name and 
description parameters, then saved it.  The new field was set with the 
default setting of true, url I didn't have to enter, since it was set 
null=True (blank is for forms and allowing this field to be blank during 
validation).

I could have easily done TestFun(name="mike", description="Testing is always 
fun.", new=False) to use a non default value for the 'new' parameter.

To sum it up models are treated like normal python classes.[1]

there is also two shortcuts, Model.objects.create() which returns a bound 
model instance, which is already saved for you [2]

In addition to that there is a Model.objects.get_or_create() which returns a 
set of the bound model and a bool for saying if it was created or not. 
get_or_create follows create() in the docs, see [2].

Mike

[1]
http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#creating-objects

[2]
http://docs.djangoproject.com/en/dev/ref/models/querysets/#create-kwargs

-- 
It is said that the lonely eagle flies to the mountain peaks while the lowly
ant crawls the ground, but cannot the soul of the ant soar as high as the 
eagle?


signature.asc
Description: This is a digitally signed message part.


Re: Trying to figure out "featured for month" view

2009-04-29 Thread Christian Berg

i would do it the other way around.

I would create a featured_object model containig a DateField and an
ForeignKey to the Featured Thing.
This should be more performant for a big directory like dmoz,
sourceforge, freshmeat, happy penguin

You could also add more Info this way. For Example you could add an
Text why this Thing is featured.

an example Query could look like this:

smurf_of_the_month = FeaturedSmurf.objects.filter(date__year=2009 +
date__month=05)


--~--~-~--~~~---~--~~
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 model field assignments

2009-04-29 Thread Dennis Schmidt

Hi there,

this might be a trivial question but my search within the django
documentation and google didn't give me any helpful results.
In Ruby on Rails you can simply do this

x = Model.new({:param_x => 'x', :param_y => 'y'})

where the params are some model fields. The hash you can provide there
can be created on the fly. How can I do this in django??? I don't know
which fields I will set at a certain point and for all the fields I
don't set there I want the model-field's default value to be used. But
since I can only hardcode which attributes / fields I will assign this
is not really possible.

But I guess there MUST be a way to this. Only how?

thanks in advance, Dennis
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



attributes in a model class

2009-04-29 Thread Waruna de Silva
Hi All,

I'm new to python and django. Is there any method or way to
get attributes in django.model class.

Lets say i have django model called

class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
address = models.CharField(max_length=50)


How can i get all attributes in that class

Regards,
Waruna

--~--~-~--~~~---~--~~
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: url template tag help

2009-04-29 Thread Christian Berg

it also helps to rename the URL to view-about-page. Dashed do work.
It seems that URL Namen are bound to slug resitrictions.



On 29 Apr., 03:06, Julián C. Pérez  wrote:
> hi everyone
> i need some help over here... please!
> i don't know what it's wrong...
>
> the url i'm trying to get around is:http://proyName/about/
>
> the error:
> "Reverse for 'proyName.view_aboutPage' with arguments '()' and keyword
> arguments '{}' not found."
>
> in a template, the dispatcher of the error:
> # template.html
> ...
> a link to the 'about' page
> ...
>
> i have a general urls.py file who looks like:
> # proyName/urls.py
> ...
> url(r'^/', include('proyName.package.appName.urls')),
> ...
> where appName includes the 'view_aboutPage' view in its views.py
> 'package' it's just a folder to wrap up all the available apps
>
> and also i have a urls.py file in appName, and it is:
> # proyName/package/appName/urls.py
> ...
> url(r'^about/$', 'view_aboutPage', name='view_aboutPage'),
> ...
>
> please... help!
> what is it wrong in there??
> thank u all
> bye!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: HTML Forms and Sessions - Help!

2009-04-29 Thread Daniel Roseman

On Apr 29, 10:15 am, Alfonso  wrote:
> Hi,
>
> Leading on from a post I made a few days ago I'm having real trouble
> dealing with sessions to preserve form state and the standard HTML for
> I placed in the template.  I can't seem to get to the session data for
> the form once submitted (via GET) and I'm wondering is that due to the
> fact it's a standard HTML form, not a django form?
>
> Its a search form that allows users to refine results so I figured
> setting it up as a POST was going to be overkill but now I wonder if
> POST and sessions are connected?  Am I going to save time if I rewrite
> the form as a django form (want to avoid that if I can)
>
> Thanks anyone

What do you mean by 'the session data for the form'? Django's sessions
framework only saves data if you tell it to. There's no automatic
session data associated with a Django form.

Perhaps if you post some code showing what you have done so far and
what you are trying to do, we can help you more.
--
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
-~--~~~~--~~--~--~---



Making First name/Last name required in User

2009-04-29 Thread Filip Gruszczyński

I would like to make First name and Last name to be required in User
class from auth package. I believe enough would be to make forms in
admin invalid, when name wasn't provided. Is it somehow possible to
achieve, without changing Django code?

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



HTML Forms and Sessions - Help!

2009-04-29 Thread Alfonso

Hi,

Leading on from a post I made a few days ago I'm having real trouble
dealing with sessions to preserve form state and the standard HTML for
I placed in the template.  I can't seem to get to the session data for
the form once submitted (via GET) and I'm wondering is that due to the
fact it's a standard HTML form, not a django form?

Its a search form that allows users to refine results so I figured
setting it up as a POST was going to be overkill but now I wonder if
POST and sessions are connected?  Am I going to save time if I rewrite
the form as a django form (want to avoid that if I can)

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



Optimistic Locking in the Admin

2009-04-29 Thread PierreR

Hello,

I have been searching the group on the subject but have not managed to
pull a satisfactory solution out of it.

How is the recommended way to implement optimistic locking in the
django admin ?

Let's say I have a version field or timestamp sent to the user-agent
together with the record (the classic solution). I need to compare the
value with the database version of it. I probably need to read the db
value with a "select for update" or to use "update where
timestamp=:timestamp" to avoid a race condition between the version
check and the update.

A warning message to the user should be sent if the record has been
concurrently updated (with the data previouly sent). Where do I code
the following ? (I am not planning to implement any merging
functionnaly)

I have started with a pre_save signal but it is probably not the best
way to "decorate" the save process (is it ?). I probably want to
change the save() into an "update where" or at least cancel it.

Is it safer/useful to use
django.middleware.transaction.TransactionMiddleware together with Form
in that context ? Where are the hooks ?

In short how to I plumb this together ?

Thanks so much for your advices.

--~--~-~--~~~---~--~~
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 to deal with problem about ForeignKey

2009-04-29 Thread Margie

I had a post on this recently that you would probably find relevant,
see:

http://groups.google.com/group/django-users/browse_frm/thread/582f21486c1073eb/8af00e9c0577a5e6?lnk=gst=margie#8af00e9c0577a5e6

Or search for "deletion of distant related objects" in this group.

I'm still somewhat confused on how to deal with this at a high level,
in an environment where one has apps that are written separately from
each other.  For example, suppose developer A writes an app called
"BookStore" that contains a Book model.  Now suppose developer B
integrates BookStore into his/her own "Book Club", and has a Reader
model that references the Book model through a foreign key.  It seems
to me that if the BookStore app provides a ui for deleting books, that
this has the very negative consequence of deleting Readers, which
probably isn't what the Book Club developer wants.

In my other post Malcolm gave me some pointers for finding all of the
fields that reference a particular key.  IE, if the the BookStore app
wants to provide a ui for deleting Books, it could find all fields
that reference Books through a foreign key, and set those foreign keys
to null prior to deleting the Books.  This would work, however it
makes certain very nice parts of Django unusable -  namely the
formsets.  Suppose I have a formet of books and want to use the Delete
funcionality of the formset.  It's not clear to me if/how I can set
all fields that reference Books through a foreign key to null, prior
to the automatic delete getting called.  Perhaps I just have to
sacrifice the automatic delete and have my own delete checkbox in the
formset forms, and when I see that I set all the foreign keys to null.

I am just now going into production with my app, and trying to figure
out what model to present to my users.  Currently I have a bunch of
formsets but have told my users "Don't use Delete!" (Of course I can
remove the Delete checkbox - and I will).  But I'm curious what the
plan going forward is for all of this.  I have seen disucssion on the
developers group about it but it is not clear to me if there is a plan
or if it has been tabled or if it is still in discussion.

Would love to hear a summary of where this might be going from any
developers!  I realize it is a tough problem - not complaining here.
Just trying to get a grip on what do do in my own app and whether
there are any changes coming and if so, what they would be and what
the timeframe might be.

Margie



On Apr 28, 10:57 pm, Vincent  wrote:
> Hi,
> I got a problem like this:
>
> class A(models.Model):
>     id = models.AutoField(primary_key=True)
>     field1 = models.TextField()
>
> class B(models.Model):
>     a = models.ForeignKey(A)
>     field1 = models.TextField()
>
> then there are some records of A/B,
> how can i delete records of A and do not delete records of B which have
> foreignkey on A
>
> Maybe i could change 'a = models.ForeignKey(A)'  to ' a =
> models.IntegerField("A") '.
>
> Is it a suitable way for this problem?
>
> Thanks for your suggestion.
--~--~-~--~~~---~--~~
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: FileField uploading into an user-specific path

2009-04-29 Thread Kip Parker

upload_to can be a callable - 
http://docs.djangoproject.com/en/dev/ref/models/fields/#filefield.

On Apr 29, 4:59 am, "Carlos A. Carnero Delgado"
 wrote:
> Oops, too quick to press reply :o
>
> On Tue, Apr 28, 2009 at 11:53 PM, Carlos A. Carnero Delgado >
> destination_file = open('somewhere based on the user', 'wb+')
>
> >  for chunk in request.FILES['audio_file'].chunks():
> >      destination_file.write(chunk)
> >  destination_file.close()
>
> with this method you are manually handling the file, stepping over
> Django's FileField. You should make adjustments & corrections to
> account for that.
>
> Also note that 'audio_file' is just the name of the field, it should
> be named with your field name, of course. Remember also to include
> request.FILES when creating your form object after a POST.
>
> HTH,
> Carlos.
--~--~-~--~~~---~--~~
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 to deal with problem about ForeignKey

2009-04-29 Thread James Bennett

On Wed, Apr 29, 2009 at 3:59 AM, Daniel Roseman
 wrote:
> You could try defining the foreign key with null=True.
>    a = models.ForeignKey(A, null=True)

Not really, since there's no support whatsoever for ON DELETE triggers
in the ORM.


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



annotation and grouping

2009-04-29 Thread omat

Hi all,

I would like to fetch the latest entries for each user from a model
like:

class Entry(models.Model):
user = models.ForeignKey(User)
entry = models.TextField()
date = models.DateTimeField(auto_now_add=True)

Is it possible with the current API with a single query?

I.e., wouldn't it be great to have something like:

Entry.objects.annotate(Max('added'), group_by=['user']).filter
(date=date__max)


Thanks,
oMat

--~--~-~--~~~---~--~~
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 to deal with problem about ForeignKey

2009-04-29 Thread Daniel Roseman

On Apr 29, 8:06 am, Vincent  wrote:
> No, i did not mean this.
> The situation is, i have model A and model B, B has a foreignkey point to
> A,.
>
> now i find that i wanna delete records of A without deleting records of B
> which pointing to A.
> i think i could reset the B's foreignkey field to integerfield.
>
> But i consider it is not the best answer, because there are a lot of similar
> problems, and some of which should be delete, the others should not be
> delete.
>
> is there any suggestion.
>

You could try defining the foreign key with null=True.
a = models.ForeignKey(A, null=True)
--
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: Django on Amazon EC2

2009-04-29 Thread creecode

Hello Joshua,

I don't have any detail or tips.  You just need to get to grips with
using EC2 and then install Django on your instance.  I've been using
Django on an EC2 instance since late last year and they work fine
together.  I use S3 as my main media server via S3Storage.

On Apr 28, 8:41 pm, Joshua Partogi  wrote:

> Has anyone here had any experience on
> deploying django apps on Amazon EC2 that would like to share their
> experience?

Toodle-lo..
creecode
--~--~-~--~~~---~--~~
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 to deal with problem about ForeignKey

2009-04-29 Thread Vincent
No, i did not mean this.
The situation is, i have model A and model B, B has a foreignkey point to
A,.

now i find that i wanna delete records of A without deleting records of B
which pointing to A.
i think i could reset the B's foreignkey field to integerfield.

But i consider it is not the best answer, because there are a lot of similar
problems, and some of which should be delete, the others should not be
delete.

is there any suggestion.

2009/4/29 Marcelo Ramos 

>
> On Wed, Apr 29, 2009 at 2:57 AM, Vincent  wrote:
> > Hi,
> > I got a problem like this:
> > class A(models.Model):
> > id = models.AutoField(primary_key=True)
> > field1 = models.TextField()
> > class B(models.Model):
> > a = models.ForeignKey(A)
> > field1 = models.TextField()
> > then there are some records of A/B,
> > how can i delete records of A and do not delete records of B which have
> > foreignkey on A
>
> Did you mean how to delete records of A for which there are no records
> in B pointing to them through the foreign key "a", right?
>
> --
> Marcelo Ramos
> Django/Python developer
>
> >
>

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

2009-04-29 Thread Matias Surdi

tdelam escribió:
> Hi Guys,
> 
> This might get lengthy but I am trying to get some insight on the best
> way to generate some dynamic forms in a template. The project is a
> survey. Here is my questions model:
> 
> class Question(models.Model):
>   TRUEFALSE = 1 # a radio button yes/no question
>   MULTIPLEANSWER = 2 # checkbox question
>   SINGLEANSWER = 3 # radio button answer
>   COMMENT = 4 # textarea box for comments
> 
>   QUESTION_CHOICES = (
>   (TRUEFALSE, 'Yes/No question'),
>   (MULTIPLEANSWER, 'Multiple answer question'),
>   (SINGLEANSWER, 'Single answer'),
>   (COMMENT, 'Comment box')
>   )
> 
>   question_type = models.IntegerField(choices=QUESTION_CHOICES,
> default=TRUEFALSE)
>   survey = models.ForeignKey(Survey)
>   title = models.CharField(max_length=250)
> 
>   def __unicode__(self):
>   return self.title
> 
> Questions are built using the django admin and they can select the
> type of question it will be via the QUESTION_CHOICES. In my template I
> am testing for the type of question but I want to display the proper
> form fields for this question. So, a True/False will be radio widget,
> multiple answer will be checkbox and so on, I will need to do this
> dynamically of course so i can show the question with the widget type
> from the constants in my model. How can I do this?
> 
> Currently I have something somewhat working...  :
> 
> class TrueFalseForm(forms.Form):
>   def __init__(self, questions, *args, **kwargs):
>   super(TrueFalseForm, self).__init__(*args, **kwargs)
>   for i, question in enumerate(questions):
>   self.fields['answer'] = 
> forms.ChoiceField(widget=forms.RadioSelect
> (), choices=[['%d % i', question]], label=question)
> 
> 
> Any suggestions would be much appreciated.
> > 
> 


Have you already read this?

http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/




--~--~-~--~~~---~--~~
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 to deal with problem about ForeignKey

2009-04-29 Thread Marcelo Ramos

On Wed, Apr 29, 2009 at 2:57 AM, Vincent  wrote:
> Hi,
> I got a problem like this:
> class A(models.Model):
>     id = models.AutoField(primary_key=True)
>     field1 = models.TextField()
> class B(models.Model):
>     a = models.ForeignKey(A)
>     field1 = models.TextField()
> then there are some records of A/B,
> how can i delete records of A and do not delete records of B which have
> foreignkey on A

Did you mean how to delete records of A for which there are no records
in B pointing to them through the foreign key "a", right?

-- 
Marcelo Ramos
Django/Python developer

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