Can't override the default form field for my custom Field type. Help?

2010-02-12 Thread Kevin Audleman
Django 1.2

I'm attempting to write my first custom Field Type. Eventually it will
do something more complicated, but for now I am simply sub-classing
the CharField. The first thing I'm doing is trying to change the
default form field to be a MultipleChoiceField.

I followed the directions here:
http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#specifying-the-form-field-for-a-model-field

...but I keep getting a single select drop-down instead of a multiple
select.

Here's my custom field:
-

class KevinsCharField(models.CharField):

description = "Kevins char field"
__metaclass__ = models.SubfieldBase

def formfield(self, **kwargs):
defaults = {'form_class' : forms.MultipleChoiceField}
defaults.update(kwargs)
return super(KevinsCharField, self).formfield(**defaults)

And here's where I define an instance of my field in a model
-

favorite_days = KevinsCharField(
"My favorite days",
max_length=200,
choices=WEEKDAYS,
blank=True)

Can anyone help me figure out what I'm missing?

Thanks,
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Need help storing/retrieving values from a form.MultipleChoiceField

2010-02-11 Thread Kevin Audleman
This must be a fairly common need so I'd love some help figuring out
why I've made it so complicated.

I've got a CharField "days_available" with choices set to a tuple of
weekdays (e.g. Monday, Tuesday, etc.).

In my form I am representing this field as a forms.MultipleChoiceField
so that multiple days can be selected.

When it comes time to save, if I don't do anything then an exception
gets thrown because the  form field returns a list [u'Monday',
u'Tuesday']. I found a way to get around this, namely write a clean
function for that field that joins the values with a comma into a
string:

def clean_days_available(self):
return ",".join(self.cleaned_data['days_available'])

However this also means that when I load the form I have to convert
that string back into a list. I haven't found a good place to do that
yet so I'm doing it in my view.

First question: is there a convenient Django function I'm missing that
would be the preferred place to do this?

Second question: Am I overcomplicating this?

Thanks,
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Error trying to add a new user in the admin site

2009-06-21 Thread Kevin Audleman

I discovered the problem: I had added settings to my settings.py to
print out the variable name if the variable didn't exist. These are
the values:

TEMPLATE_DEBUG = DEBUG
TEMPLATE_STRING_IF_INVALID = '%s'

Some of the admin templates make use of variables that don't actually
exist. If the value is simply blank, the page will work. If, however
the name of the variable is printed it won't work. See this ticket for
more info:

http://code.djangoproject.com/ticket/3579

The solution was to comment out those two settings and like magic it
works.

Kevin


On Jun 8, 6:32 pm, Kevin Audleman  wrote:
> I go into the admin section of my site, click on Users, then on the
> 'Add User' button. It takes me to a screen that asks me to put in a
> username and password and click 'Save'. At this point I get an error:
>
> ValueError at /admin/auth/user/add/form_url
>
> invalid literal for int() with base 10: 'add/form_url'
>
> I wondered if it might have to do with any of the changes I had made
> though defining an admin.py in my app, so I removed it and went back
> to the stock admin site. The error persists. The full trace is below.
>
> Any help greatly appreciated!
>
> Kevin
> ---
> ---
>
> Environment:
>
> Request Method: POST
> Request URL:http://localhost:8001/admin/auth/user/add/form_url
> Django Version: 1.0.2 final
> Python Version: 2.5.1
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'django.contrib.admin',
>  'registration',
>  'profiles',
>  'CasaCasa.customprofile',
>  'django.contrib.humanize']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> Traceback:
> File "/Library/Python/2.5/site-packages/django/core/handlers/base.py"
> in get_response
>   86.                 response = callback(request, *callback_args,
> **callback_kwargs)
> File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py"
> in root
>   157.                 return self.model_page(request, *url.split('/',
> 2))
> File "/Library/Python/2.5/site-packages/django/views/decorators/
> cache.py" in _wrapped_view_func
>   44.         response = view_func(request, *args, **kwargs)
> File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py"
> in model_page
>   176.         return admin_obj(request, rest_of_url)
> File "/Library/Python/2.5/site-packages/django/contrib/auth/admin.py"
> in __call__
>   42.         return super(UserAdmin, self).__call__(request, url)
> File "/Library/Python/2.5/site-packages/django/contrib/admin/
> options.py" in __call__
>   197.             return self.change_view(request, unquote(url))
> File "/Library/Python/2.5/site-packages/django/db/transaction.py" in
> _commit_on_success
>   238.                 res = func(*args, **kw)
> File "/Library/Python/2.5/site-packages/django/contrib/admin/
> options.py" in change_view
>   548.             obj = model._default_manager.get(pk=object_id)
> File "/Library/Python/2.5/site-packages/django/db/models/manager.py"
> in get
>   93.         return self.get_query_set().get(*args, **kwargs)
> File "/Library/Python/2.5/site-packages/django/db/models/query.py" in
> get
>   303.         clone = self.filter(*args, **kwargs)
> File "/Library/Python/2.5/site-packages/django/db/models/query.py" in
> filter
>   489.         return self._filter_or_exclude(False, *args, **kwargs)
> File "/Library/Python/2.5/site-packages/django/db/models/query.py" in
> _filter_or_exclude
>   507.             clone.query.add_q(Q(*args, **kwargs))
> File "/Library/Python/2.5/site-packages/django/db/models/sql/query.py"
> in add_q
>   1258.                             can_reuse=used_aliases)
> File "/Library/Python/2.5/site-packages/django/db/models/sql/query.py"
> in add_filter
>   1201.         self.where.add((alias, col, field, lookup_type,
> value), connector)
> File "/Library/Python/2.5/site-packages/django/db/models/sql/where.py"
> in add
>   48.                 params = field.get_db_prep_lookup(lookup_type,
> value)
> File "/Library/Python/2.5/site-

Error trying to add a new user in the admin site

2009-06-08 Thread Kevin Audleman

I go into the admin section of my site, click on Users, then on the
'Add User' button. It takes me to a screen that asks me to put in a
username and password and click 'Save'. At this point I get an error:

ValueError at /admin/auth/user/add/form_url

invalid literal for int() with base 10: 'add/form_url'

I wondered if it might have to do with any of the changes I had made
though defining an admin.py in my app, so I removed it and went back
to the stock admin site. The error persists. The full trace is below.

Any help greatly appreciated!

Kevin
---
---

Environment:

Request Method: POST
Request URL: http://localhost:8001/admin/auth/user/add/form_url
Django Version: 1.0.2 final
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'registration',
 'profiles',
 'CasaCasa.customprofile',
 'django.contrib.humanize']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/Library/Python/2.5/site-packages/django/core/handlers/base.py"
in get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py"
in root
  157. return self.model_page(request, *url.split('/',
2))
File "/Library/Python/2.5/site-packages/django/views/decorators/
cache.py" in _wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py"
in model_page
  176. return admin_obj(request, rest_of_url)
File "/Library/Python/2.5/site-packages/django/contrib/auth/admin.py"
in __call__
  42. return super(UserAdmin, self).__call__(request, url)
File "/Library/Python/2.5/site-packages/django/contrib/admin/
options.py" in __call__
  197. return self.change_view(request, unquote(url))
File "/Library/Python/2.5/site-packages/django/db/transaction.py" in
_commit_on_success
  238. res = func(*args, **kw)
File "/Library/Python/2.5/site-packages/django/contrib/admin/
options.py" in change_view
  548. obj = model._default_manager.get(pk=object_id)
File "/Library/Python/2.5/site-packages/django/db/models/manager.py"
in get
  93. return self.get_query_set().get(*args, **kwargs)
File "/Library/Python/2.5/site-packages/django/db/models/query.py" in
get
  303. clone = self.filter(*args, **kwargs)
File "/Library/Python/2.5/site-packages/django/db/models/query.py" in
filter
  489. return self._filter_or_exclude(False, *args, **kwargs)
File "/Library/Python/2.5/site-packages/django/db/models/query.py" in
_filter_or_exclude
  507. clone.query.add_q(Q(*args, **kwargs))
File "/Library/Python/2.5/site-packages/django/db/models/sql/query.py"
in add_q
  1258. can_reuse=used_aliases)
File "/Library/Python/2.5/site-packages/django/db/models/sql/query.py"
in add_filter
  1201. self.where.add((alias, col, field, lookup_type,
value), connector)
File "/Library/Python/2.5/site-packages/django/db/models/sql/where.py"
in add
  48. params = field.get_db_prep_lookup(lookup_type,
value)
File "/Library/Python/2.5/site-packages/django/db/models/fields/
__init__.py" in get_db_prep_lookup
  202. return [self.get_db_prep_value(value)]
File "/Library/Python/2.5/site-packages/django/db/models/fields/
__init__.py" in get_db_prep_value
  353. return int(value)

Exception Type: ValueError at /admin/auth/user/add/form_url
Exception Value: invalid literal for int() with base 10: 'add/
form_url'

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



Bug in admin related to django.root

2009-06-03 Thread Kevin Audleman

Hi gang,

I am serving my django website out of a sub-folder, e.g.
http://www.mydomain.com/directory. My hosting provider is WebFaction
and they've set things up so that the /directory part is stripped from
the URL before it reaches my django app (so my app sees "/"). In order
to get django to properly include the /directory to urls it generates,
I have added the django.root setting to my http.conf. Full file here:


PythonHandler django.core.handlers.modpython
PythonPath "['/home/casacasa/webapps/django', '/home/casacasa/
webapps/django/lib/python2.5'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE CasaCasa.settings
SetHandler python-program
#PythonOption SCRIPT_NAME
PythonOption django.root "/directory"


This works fine for all of the urls I generate through the reverse
function. However it doesn't work in the admin section for edit pages.
I can click on a model to see a list of its records, I can click on a
record to edit it, but when I click Save it takes me to a URL that is
missing the django.root (of course the page doesn't exist on the
server so I get a 404).

This seems like a django bug to me; does anybody know what I can do
about it?

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: Need help with URL rewrites

2009-06-01 Thread Kevin Audleman

Partial solution: I added the following settings variable:

PythonOption django.root "/directory"


The /directory part is now successfully added to all front-end pages.
However saving models within the admin is broken. When I click save,
the URL it tries to go to (which would be the list view for that
model) is missing the /directory part. Is this a bug in django?

At this point my http.conf looks like this:


PythonHandler django.core.handlers.modpython
PythonPath "['/home/casacasa/webapps/django', '/home/casacasa/
webapps/django/lib/python2.5'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE CasaCasa.settings
SetHandler python-program
PythonOption SCRIPT_NAME
PythonOption django.root "/directory"




On May 25, 1:02 pm, Kevin Audleman  wrote:
> Hi Alex,
>
> I did exactly as you suggested with no luck. Any other suggestions?
>
> Kevin
>
> On May 25, 12:27 pm, Alex Koshelev  wrote:
>
> > Hi, Kevin.
>
> > You can try to set FORCE_SCRIPT_NAME = '/directory' [1] settings
> > variable. Or setup your web server to provide valid SCRIPT_NAME
> > environment variable.
>
> > [1]:http://docs.djangoproject.com/en/dev/ref/settings/#force-script-name
>
> > ---
> > Alex Koshelev
>
> > On Mon, May 25, 2009 at 10:52 PM, KevinAudleman
>
> >  wrote:
>
> > > My web host set up a django instance for me that can be accessed at
> > >http://www.mysite.com/directory/. They've set up an Apache rule (or
> > > something) that strips out the /directory/ before passing it on to
> > > django, so as a result that url gets resolved by my url pattern "^$".
>
> > > This is nice, the only problem is that the url's I generate from my
> > > django app are missing the /directory/ part. For example, I've got a
> > > page called
>
> > >http://www.mysite.com/directory/register/
>
> > > ...but django's url function creates this:
>
> > >http://www.mysite.com/register/
>
> > > Is there a way to get django to append a /directory/ to the beginning
> > > of each url it creates?
>
> > > 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: Need help with URL rewrites

2009-05-25 Thread Kevin Audleman

Hi Alex,

I did exactly as you suggested with no luck. Any other suggestions?

Kevin

On May 25, 12:27 pm, Alex Koshelev  wrote:
> Hi, Kevin.
>
> You can try to set FORCE_SCRIPT_NAME = '/directory' [1] settings
> variable. Or setup your web server to provide valid SCRIPT_NAME
> environment variable.
>
> [1]:http://docs.djangoproject.com/en/dev/ref/settings/#force-script-name
>
> ---
> Alex Koshelev
>
> On Mon, May 25, 2009 at 10:52 PM, Kevin Audleman
>
>  wrote:
>
> > My web host set up a django instance for me that can be accessed at
> >http://www.mysite.com/directory/. They've set up an Apache rule (or
> > something) that strips out the /directory/ before passing it on to
> > django, so as a result that url gets resolved by my url pattern "^$".
>
> > This is nice, the only problem is that the url's I generate from my
> > django app are missing the /directory/ part. For example, I've got a
> > page called
>
> >http://www.mysite.com/directory/register/
>
> > ...but django's url function creates this:
>
> >http://www.mysite.com/register/
>
> > Is there a way to get django to append a /directory/ to the beginning
> > of each url it creates?
>
> > 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
-~--~~~~--~~--~--~---



Need help with URL rewrites

2009-05-25 Thread Kevin Audleman

My web host set up a django instance for me that can be accessed at
http://www.mysite.com/directory/. They've set up an Apache rule (or
something) that strips out the /directory/ before passing it on to
django, so as a result that url gets resolved by my url pattern "^$".

This is nice, the only problem is that the url's I generate from my
django app are missing the /directory/ part. For example, I've got a
page called

http://www.mysite.com/directory/register/

...but django's url function creates this:

http://www.mysite.com/register/

Is there a way to get django to append a /directory/ to the beginning
of each url it creates?

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: User Profile in Admin

2009-05-01 Thread Kevin Audleman

Can't answer your question directly, but it looks as if you are trying
to extend the field list for a user. In this case you should check out
the proper way of doing it using AUTH_PROFILE_MODULE:

http://docs.djangoproject.com/en/dev/topics/auth/?from=olddocs#storing-additional-information-about-users

Kevin


On May 1, 8:20 am, CrabbyPete  wrote:
> I created the following:
>
> class Profile(models.Model):
>     user        = models.ForeignKey(User, unique=True)
>     phone       = models.CharField(max_length=15,  blank = True, null
> = True, unique = True)
>
>    def __unicode__(self):
>         return self.user.username
>
> But when I look at it in the Admin. It shows  the Profile and that I
> have 2 users, but does not display the username to select. Help?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: url template tag help

2009-05-01 Thread Kevin Audleman

Malcom,

Cheers to that.

It's always hard to figure out what attitude you are conveying when
you post to a message board so I don't know how I sound in this
thread. Forgive me if I sound whiny or complainy, that is certainly
not my intent. Quite the contrary, my overall attitude toward Django
is that of pure awe. I've never worked with a framework that is so
logical, consistent, and powerful. I picked up the basics in a week
and suddenly feel empowered to create full-fledged web apps that can
do complex queries, handle form submission with full input validation
and cleaning, have a working security/permissions framework, etc.
Three cheers, mate!

I meant what I said about working with reverse url: complicated but
worth the effort. What's going on behind the scenes is no doubt
extremely complex, but the fact that I never have to hard-code a url
is huge. I take it as a challenge to put all the pieces together
myself.

Kevin

On May 1, 11:28 am, Malcolm Tredinnick 
wrote:
> On Fri, 2009-05-01 at 11:13 -0700, Kevin Audleman wrote:
>
> > > I can't explain any of this, but I've been thinking about your
> > > question since you posted it beause I know this type of error happens
> > > to me a lot (and indeed has been hard to debug), but I couldn't put my
> > > finger on remembering what my solution was.  It just happened, I fixed
> > > my syntax error, but still got reverseMatch error message.  Restarted
> > > the server, and it was gone.
>
> > Truly, Margie, this is the most inexplicable part of Django for me
> > too. I'll code up a template with a bunch of {% url app.view %}
> > statements which will work just fine. Then at some point I make some
> > change and *bam* I've got a reverse url lookup error. The solution is
> > not always obvious either. As I wrote earlier in this thread, at one
> > point I suddenly had to append the app name to the names of my url's
> > in urls.py. They had been working just fine, then something I changed
> > made them not work.
>
> At which point, working out "what changed" would be useful so that (a)
> you can avoid it next time and (b) if it's some kind of problem in
> Django, we can fix it. There is almost no magic going on in these sorts
> of situations.
>
> Certainly the error reporting from some of the URL resolving is a little
> weak and that's something we're going to fix at some point. Hopefully
> before 1.1 comes out. So bear with us for a little while longer on that
> front and, in the interim
>
>
>
> > I agree that restarting the server is crucial. Don't know why, but it
> > clears these types of things up.
>
> Because there's a lot of internal caching going on. In particular, files
> are imported once and then not imported again (since that would be
> blindingly inefficient). URL configuration files are read once by each
> process and the reverse lookups -- which take quite a bit of effort to
> determine -- are cached so that we don't have to do the work every
> single time.
>
> It's fairly logical that if you change something you will have to tell
> the code using that information that the on-disk versions have changed.
> Sure, you don't have to worry about the "compile" part of a normal
> development cycle when using Python very often, but there is some text
> -> bytecode compilation going on, whether converting to .pyc files or
> simply on the import into memory and there is other in-memory storage
> taking place. The development server spoils people a bit in this
> respect, in that it tries to detect a certain, fairly large class of
> changes, but it cannot detect everything and isn't really a useful use
> of development effort to make it do so.
>
>
>
> > Oh well, every powerful mechanism is bound to be difficult to work
> > with. I figure one of these days I'll *really* understand the
> > structure of a Django app and these reverse url's will no longer
> > plague me.
>
> Definitely the right attitude! :-)
>
> The more you persist, the better you get.
>
> The primary audience for Django, although not very clearly defined, is
> pretty much experienced programmers and web designers trying to get
> things done quickly and are familiar with using it. It's a productivity
> tool and time saver for doing things that you already understood. People
> coming to Django as a new framework and a new programming language
> (Python) and learning about HTML / Javascript / CSS and databases and
> sysadmin and all the other bits and pieces are going to find there's a
> lot to learn. That's only because there's a lot to learn. It's
> practical

Re: url template tag help

2009-05-01 Thread Kevin Audleman


> I can't explain any of this, but I've been thinking about your
> question since you posted it beause I know this type of error happens
> to me a lot (and indeed has been hard to debug), but I couldn't put my
> finger on remembering what my solution was.  It just happened, I fixed
> my syntax error, but still got reverseMatch error message.  Restarted
> the server, and it was gone.
>

Truly, Margie, this is the most inexplicable part of Django for me
too. I'll code up a template with a bunch of {% url app.view %}
statements which will work just fine. Then at some point I make some
change and *bam* I've got a reverse url lookup error. The solution is
not always obvious either. As I wrote earlier in this thread, at one
point I suddenly had to append the app name to the names of my url's
in urls.py. They had been working just fine, then something I changed
made them not work.

I agree that restarting the server is crucial. Don't know why, but it
clears these types of things up.

Oh well, every powerful mechanism is bound to be difficult to work
with. I figure one of these days I'll *really* understand the
structure of a Django app and these reverse url's will no longer
plague me.

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: Configuration help. Multiple projects.

2009-04-30 Thread Kevin Audleman

Your needs are a bit vague, but here's a thought:

I would think that you would want one project which would conceptually
encompass everything your company does. Within that project you would
create multiple apps: one for training and one for project XYZ (if I'm
reading your requirements correctly). This way the logic for each
"project" would be contained in its own directory complete with views,
models, etc. They will live in the same Django project and share a
settings.py file, urls.py file and can easily talk to each other.

Kevin

On Apr 30, 7:47 am, "eric.frederich"  wrote:
> So, I have been tasked with creating a new website within my company
> for a new project.  Lets call the project XYZ (because just calling it
> 'the project' is confusing since Django already has a concept of
> projects).
>
> The website will be your run of the mill project page with
> announcements, newsletters, presentations etc.
> One other thing they wanted was to be able to manage and track
> training for XYZ.
>
> We have been looking to change the way we track other training
> (currently in a spreadsheet) for a while now.  I took the opportunity
> and created a Django application for all training, not just for XYZ.
> I'd like it to live athttp://someserver/training/.  From there they
> could find training on AutoCad, Visio, MathCad, as well as XYZ.
>
> For the XYZ project page, I'd like it to live athttp://someserver/XYZ/.
>
> So now here's the question.  Should the training site and the XYZ site
> both be projects?  If they're both projects, how could I get a list of
> all XYZ training courses from the XYZ project page?  That would
> involve 1 project pulling data from the other.
>
> I could just have one Django project at '/' instead of one at '/
> training' and one at '/XYZ'.  Doing that, getting a list of XYZ
> training courses up on the XYZ project page would be easy.  Now is
> having a single Django project hogging up '/' going to prevent me from
> running other things like a MediaWiki or BugZilla?  Do I need to use
> "http://someserver/django/training"; and "http://someserver/django/
> XYZ"?
>
> So I need some help deciding what to do.  Multiple projects or a
> single project?  If I do multiple, how can I access models across
> projects.  If I do a single project how do I configure Apache in a way
> that won't mess things up down the road?
>
> What would you do?
>
> Thanks in advance.
> ~Eric
--~--~-~--~~~---~--~~
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-30 Thread Kevin Audleman

The other thing is that if there is anything else wrong with your
views.py file it can cause Django to throw up this error. See if the
error is occurring on the first occurence of {% url %} that gets
called for the page you are requesting. That would be a good
indication that your error is somewhere else.

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: 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: Can I use the django test server for this?

2009-04-21 Thread Kevin Audleman

I've been moving forward with the django server option and have come
across an oddity: while I can access my site on the resident machine
via http://localhost:8000, if I try to access it from another machine
on the network via http://10.0.0.66:8000 I get an error in my browser:

Failed to Connect
Though the site seems valid, the browser was unable to establish a
connection.

If I can get this problem resolved, then I've found my lowest barrier
solution. Any thoughts? Is there something baked into the django
server that prevents one from accessing it via a remote machine?

If I can't find a solution, I'll look into lighthttpd.

Cheers,
Kevin


On Apr 21, 12:46 pm, Oli Warner  wrote:
> You could, but as you say you would have to script it to daemonise.
>
> If resources are what's putting you off running something like Apache, you
> should know there are plenty of lightweight servers that are simple to get
> up and running, even on desktop machines.
>
> Just to state my position: I would find it easier to install something like
> Lighttpd, Nginx or Cherokee but that's because I have experience with all of
> them. If you can get the dev server to auto-load, I can't see any real
> reason stopping you from going that route. It's not a bad server and I doubt
> you'd see any performance/resource issues for fewer than 10 people using it.
>
> And of course, there's nothing stopping you from starting off on the dev
> server and moving up if you find you need to. It only takes a couple of
> well-crafted googles, a little reading and a few keystrokes to get a real
> server running yout site.
>
> On Tue, Apr 21, 2009 at 8:18 PM, Kevin Audleman 
> wrote:
>
>
>
> > I'm building a tool for a client that synchs email addresses between
> > systems and decided to use the excellent django framework because it
> > gives me a quick and powerful connection to a database back-end and
> > the ability to provide a web front-end for the users. I'm trying to
> > decide if it's worth going through the trouble of setting up Apache to
> > serve the program or if I can safely get away with using django's
> > server.  Here are the details.
>
> > This program will reside on an in-house server and will not be
> > accessible by the public. There will only be one user at a time. The
> > program will likely run once or twice a day, at which point it will do
> > some light interaction with MySQL. It will also be available at all
> > times to staff via their web browser (and an internal IP address)
> > should they wish to check a log of previous transactions.
>
> > My instincts tell me I can get away with using the test server, as
> > what I'm doing is hardly a web application that needs to deal with
> > thousands of transactions. I imagine I could just set up a startup
> > script in OS X to launch the django server at startup and leave it
> > running.
>
> > Any advice -- either saying yes this is a good idea or no there are
> > serious drawbacks to this approach -- greatly appreciated!
>
> > 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
-~--~~~~--~~--~--~---



Can I use the django test server for this?

2009-04-21 Thread Kevin Audleman

I'm building a tool for a client that synchs email addresses between
systems and decided to use the excellent django framework because it
gives me a quick and powerful connection to a database back-end and
the ability to provide a web front-end for the users. I'm trying to
decide if it's worth going through the trouble of setting up Apache to
serve the program or if I can safely get away with using django's
server.  Here are the details.

This program will reside on an in-house server and will not be
accessible by the public. There will only be one user at a time. The
program will likely run once or twice a day, at which point it will do
some light interaction with MySQL. It will also be available at all
times to staff via their web browser (and an internal IP address)
should they wish to check a log of previous transactions.

My instincts tell me I can get away with using the test server, as
what I'm doing is hardly a web application that needs to deal with
thousands of transactions. I imagine I could just set up a startup
script in OS X to launch the django server at startup and leave it
running.

Any advice -- either saying yes this is a good idea or no there are
serious drawbacks to this approach -- greatly appreciated!

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: Searching a list of Q

2009-02-25 Thread Kevin Audleman

Ah, gotcha.

Maybe django should include a iin function =)

Kevin

On Feb 25, 10:37 am, Alex Gaynor  wrote:
> On Wed, Feb 25, 2009 at 1:34 PM, Kevin Audleman 
> wrote:
>
>
>
>
>
> > What about the following?
>
> > qset = Q(author__in=[u"Foo", u"Bar"])
>
> > Kevin
>
> > On Feb 25, 10:03 am, Peter Bengtsson  wrote:
> > > This works:
>
> > >  >>> from django.db.models import Q
> > >  >>> qset = Q(author__iexact=u"Foo") | Q(author__iexact=u"Bar")
> > >  >>> Books.objects.filter(qset)
>
> > > But what if the list of things I want to search against is a list.
> > > E.g.
>
> > >  >>> possible_authors = [u"Foo", u"Bar"]
>
> > > ???
>
> > > I have a solution but it's very ugly and feels "clunky":
>
> > >  qset = None
> > >  for each in [u"Foo", u"Bar"]:
> > >      if qset is None:
> > >          qset = Q(author__iexact=each)
> > >      else:
> > >          qset = qset | Q(author__iexact=each)
>
> Kevin, the way IN works at the SQL level basically means that it will be
> doing an exact match against each item, which isn't what he wants, he wants
> an iexact match.
>
> 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: Searching a list of Q

2009-02-25 Thread Kevin Audleman

What about the following?

qset = Q(author__in=[u"Foo", u"Bar"])


Kevin

On Feb 25, 10:03 am, Peter Bengtsson  wrote:
> This works:
>
>  >>> from django.db.models import Q
>  >>> qset = Q(author__iexact=u"Foo") | Q(author__iexact=u"Bar")
>  >>> Books.objects.filter(qset)
>
> But what if the list of things I want to search against is a list.
> E.g.
>
>  >>> possible_authors = [u"Foo", u"Bar"]
>
> ???
>
> I have a solution but it's very ugly and feels "clunky":
>
>  qset = None
>  for each in [u"Foo", u"Bar"]:
>      if qset is None:
>          qset = Q(author__iexact=each)
>      else:
>          qset = qset | Q(author__iexact=each)
--~--~-~--~~~---~--~~
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: optional parameter url

2009-02-25 Thread Kevin Audleman

I think you're missing the trailing slash in your URL's. Should be:

(r'^appname/mainpage/(?P.*)/$', 'django.views.static.serve',
 {'document_root': '/mesa'}),
(r'^appname/mainpage/(?P\d+)/(?P.*)/$',
 'django.views.static.serve', {'document_root': '/mesa'}),

Mind you, I don't know if this will fix anything...

Kevin


On Feb 25, 4:26 am, Adonis  wrote:
> Hello,
> I am having some trouble serving static files when i try to pass an
> optional parameter.
> For url: appname.mainpage/, the static files work fine
> For url: appname.mainpage/10/, the static files are not read.
>
> **
> url.py
>
> (r'^appname/mainpage/(?P.*)$', 'django.views.static.serve',
> {'document_root': '/mesa'}),
> (r'^appname/mainpage/(?P\d+)/(?P.*)$',
> 'django.views.static.serve', {'document_root': '/mesa'}),
>
> views.py
>
> def mainpage(request, xexe=0):
>     print "optional parameter: ", xexe
>     return render_to_response('mesa/blah.html', {...some args...})
> **
>
> Any suggestions my respectful django users?
--~--~-~--~~~---~--~~
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: InlineModelAdmin objects question

2009-02-25 Thread Kevin Audleman

First of all, are you using the AUTH_PROFILE_MODULE methodology? See
the documentation here:
http://docs.djangoproject.com/en/dev/topics/auth/?from=olddocs#storing-additional-information-about-users

If you've defined a foreign key on your People model, I would guess
you're not. This is preferrable over rolling your own as django will
automatically populate request.user with the fields from your profile
module.

The previous response identifies how to get it to show up in the
admin. Namely, you overwrite the User object to display the related
record.

Cheers,
Kevin

On Feb 24, 5:12 pm, Kevin Coyner  wrote:
> I am using the Auth system in django and have a separate app People
> that I'm using to keep more detailed info (i.e. address, phone, etc)
> on my users. I presume from my docs reading that this is the best way.
>
> Question:   Can I use InlineModelAdmin to handle new user input from
> just onepage, preferably my People admin page?
>
> Here's what I've tried in people/admin.py:
>
> from django.contrib import admin
> from django.contrib.auth.models import User
> from local1042.people.models import People
>
> class PeopleInline(admin.TabularInline):
>     model = User
>
> class PeopleAdmin(admin.ModelAdmin):
>     search_fields = ['username__last_name']
>     inlines = [ PeopleInline ]
>
> admin.site.register(People, PeopleAdmin)
> 
>
> But when I try this I get:
>
>  has no ForeignKey to  'local1042.people.models.People'>
>
> But in people/models.py I have:
>
> from django.contrib.auth.models import User
> class People(models.Model):
>     username = models.OneToOneField(User, parent_link=False)
>     address = ... etc
> --
>
> Any pointers would be appreciated.  Thanks.
>
> --
> Kevin Coyner  GnuPG key: 1024D/8CE11941
--~--~-~--~~~---~--~~
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: Simplest way to do this?

2009-02-23 Thread Kevin Audleman

Great idea, I'll do that.

Thanks!

Kevin

On Feb 23, 11:30 am, Daniel Roseman 
wrote:
> On Feb 23, 7:19 pm, Kevin Audleman  wrote:
>
>
>
> > Hello,
>
> > I am using the excellent django-profiles module provided by
> > Ubernostrum which gives my site the following views:
>
> > - list members
> > - view member
> > - edit member
>
> > The module handles all of the views and urls so basically all I had to
> > do was write templates and put a slug into my urls.py.
>
> > The requirements for my site are that all of these pages require a
> > login. However the module only adds the @login_required decorator to
> > the edit page and leaves the list members and edit members views
> > public.
>
> > How do I add a login check to the other two views? A couple of not
> > great options I've though of are:
>
> > 1. Copy and paste the views to my own module and add the decorator
> > myself. Bad because I've overridden core functionality of a module.
> > 2. Handle permissions at the template level. Not ideal because the
> > rest of my site handles it at the view level and I don't want to mix
> > techniques.
>
> > Is there another, simpler way of doing it?
>
> > Thanks,
> > Kevin Audleman
>
> The best way would be to wrap the views in other function in your own
> module. Your views would take the same parameters as the original
> ones, and would simply call the originals and return whatever they
> returned. The URLs would point to your views, rather than the
> originals.
>
> from django_profiles import list_members
>
> @login_required
> def my_list_members(request, params):
>     return list_members(request, params)
>
> Obviously, using the right parameters in each case.
> --
> 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
-~--~~~~--~~--~--~---



Simplest way to do this?

2009-02-23 Thread Kevin Audleman

Hello,

I am using the excellent django-profiles module provided by
Ubernostrum which gives my site the following views:

- list members
- view member
- edit member

The module handles all of the views and urls so basically all I had to
do was write templates and put a slug into my urls.py.

The requirements for my site are that all of these pages require a
login. However the module only adds the @login_required decorator to
the edit page and leaves the list members and edit members views
public.

How do I add a login check to the other two views? A couple of not
great options I've though of are:

1. Copy and paste the views to my own module and add the decorator
myself. Bad because I've overridden core functionality of a module.
2. Handle permissions at the template level. Not ideal because the
rest of my site handles it at the view level and I don't want to mix
techniques.

Is there another, simpler way of doing it?

Thanks,
Kevin Audleman
--~--~-~--~~~---~--~~
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 in django via plone

2009-02-19 Thread Kevin Audleman

Tricky...how do you write a method in Django that can query Plone for
the existence of a user? A couple of thoughs:

1. Design an external method in Plone that takes a username/password
and returns true/false
2. Extend Plone to copy the users to a SQL table that you can then
access natively in Django.

Hopefully somebody out there has a more flushed out idea.

Kevin

On Feb 19, 2:20 am, Alan  wrote:
> Hi There,
>
> We have Plone/Zope site for CMS and users registration. It came before
> django for us. But now we are developing portal applicatons done with django
> (much better to develop and maintain) and we have this question now: how to
> allow a user to login in django portal using his/her login and pass from
> Plone, including new users that would register at Plone and then access to
> django portals automatically.
>
> Any idea here would be very appreciated.
>
> Many thanks in advance.
> Alan
>
> --
> Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
> Department of Biochemistry, University of Cambridge.
> 80 Tennis Court Road, Cambridge CB2 1GA, UK.
>
> >>http://www.bio.cam.ac.uk/~awd28<<
--~--~-~--~~~---~--~~
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: Query that grabs objects before and after object

2009-02-18 Thread Kevin Audleman

When you say "come before this object" and "come after this object",
how is this represented in your data model? Do you have a field called
show_order where you are capturing this information? In that case you
could do something like

current_show = 5 #Presumably you get this in your request
show_range = (current_show - 4, current_show + 4)
shows = Show.objects.filter(show_order__range=show_range)


FYI I haven't tested this and my Python is not good enough that I can
guarantee my syntax.

Kevin Audleman

On Feb 18, 4:06 pm, Sean Brant  wrote:
> Is there a simple way to say get me 4 objects from model that come
> before this object and 4 that come after this object.
>
> So lets say I have a Show. I would like to know which 4 shows come
> before the current show and which 4 come after, however I must limit
> the shows based on a category type. Would slicing work for this?
>
> If this is not sure clear let me know and I will try and clarify more.
--~--~-~--~~~---~--~~
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: Any way to show progress during a short process job?

2009-02-18 Thread Kevin Audleman

Ajax would only be necessary if you want a status bar that reflects
accurately the progress. You can probably get by with something
simpler. I would write some Javascript that is triggered on clicking
the submit button that replaces the button with this graphic:
http://yesmagazine.org/store/images/pleasewait.gif


Your Javascript looks like this:

?>
<!--


function SubmitOrderButton(){
document.getElementById("submitmain").style.display = "none";

if (navigator.appName == "Microsoft Internet Explorer") {
document.getElementById("pleasewait").innerHTML = "";
document.getElementById("pleasewait").style.display = "block";
document.getElementById("pleasewait").innerHTML = "<img src='images/
pleasewait.gif' alt='Please Wait'>";
} else {
document.getElementById("pleasewait").style.display = "block";
    }
}

//-->

And your HTML code looks like this:






   Please wait while your request is being processed...


Cheers,
Kevin Audleman

On Feb 18, 2:52 pm, Malcolm Tredinnick 
wrote:
> On Wed, 2009-02-18 at 12:20 +, Adam Stein wrote:
> > Maybe somebody can suggest how to get the functionality I'm trying to
> > duplicate.  I looked and can't find anything that seemed similiar.
>
> > I have a form with checkboxes.  User selects one or more and submits the
> > form.  The processing currently goes like this:
>
> > 1) Write JavaScript to display moving progress bar
> > 2) Process based on checked boxes (which in my specific example is to
> > copy the specified databases into a sandbox area)
> > 3) Write JavaScript to turn off progress bar
>
> > The database copying is short, up to about 20 seconds.  Short enough to
> > let the user wait, long enough that I want to indicate the computer
> > hasn't frozen :-{}
>
> > It seems that I can only return HTML to be displayed once from a view.
> > Is there a way to get the functionality described above somehow?
>
> It's called AJAX. You have to keep asking the server for an update and
> then updating the page.
>
> 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: Extract values from form fields in templates

2009-02-18 Thread Kevin Audleman

Passing both the form and the object is the solution I use. It may not
be completely DRY, but I can't see how it's bad. You need access to
the data in an object so you pass the object. Much more sensible than
trying to extract those values from a more complicated data
structure.

Kevin

On Feb 18, 5:52 am, koranthala  wrote:
> Hi,
>     I am unable to extract values from form fields inside templates.
>     For example:
>       I have mutiple text fields in which one field says whether the
> second field is X or not and the second field containing the actual
> data. (These are initial values which I send from server to client)
>      Now, in case it is of type X, I want to do something in the
> template.
>
> I tried to do it as follows:
> In template:
> {% ifequal forms.typename "username" %}
>    {{ form.name }} 
> {% else %}
>    {{ form.text }}
>
> Django Code:
> class frm(forms.Form):
>     typename = forms.CharField(widget=forms.TextInput())
>     text = forms.CharField(widget=forms.TextInput())
>     name = forms.CharField(widget=forms.TextInput())
>     img = forms.CharField(widget=forms.TextInput())
>
> I was unable to do it via forms, since I cannot extract the data.
> so I have to have another variable which sends the same data - which
> is against the DRY principle.
>
> Is it possible to extract the text data from the form widgets?
--~--~-~--~~~---~--~~
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: Access extra parameters in forms.py

2009-02-17 Thread Kevin Audleman

You should probably change the order of operations in the
__init__function to call the super classes __init__ function first.

Kevin

On Feb 16, 8:49 am, peterandall  wrote:
> Hi all,
>
> I'm trying to access a list of users in forms.py I'm creating two
> lists and merging them in my view (new_bug) then passing them through
> when i create the form. I was going off answers on these two existing
> topics:http://groups.google.com/group/django-users/browse_thread/thread/9dce...
> andhttp://groups.google.com/group/django-users/browse_thread/thread/809e...
>
> You can see my current code here:
>  http://dpaste.com/121276/
>
> So i'm creating the list of users fine (all_users), passing them to
> the __init__ method, I can access them and print them out fine.
>
> My issue is where i'm trying to build the form and get it to display
> in the template nothing appears, i.e none of the form fields appear,
> but i don't get any error messages. If i move all of the fields out of
> the __init__ method then they display in the template, but the
> 'assigned_to' field can't access the 'all_users' variable from the
> __init__ method.
>
> I guess it comes down to me not fully understanding how to access the
> information in the __init__ method and still have the form be built
> with all the fields.
>
> Any advice would be great, or if you need me to clarify anything give
> me a shout.
>
> Cheers,
>
> Pete.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can I overwrite the ModelAdmin for User

2009-02-17 Thread Kevin Audleman

Hey, that's great! I did indeed discover that the change password page
didn't work but didn't know what to do about it. Thanks for your
excellent and thorough help =)

Kevin

On Feb 16, 6:30 pm, Karen Tracey  wrote:
> On Mon, Feb 16, 2009 at 8:19 PM, Kevin Audleman 
> wrote:
>
>
>
> > Alex,
>
> > I managed to get it to work, and the column is even sortable! Thanks
> > for your help.
>
> > Here's my code for reference for anyone else who comes across this
> > post:
>
> > class UserAdmin(admin.ModelAdmin):
>
> There are some extensions made to the default User ModelAdmin that you are
> going to miss unless you base your customized class off of auth's provided
> default UserAdmin.  See:
>
> http://code.djangoproject.com/ticket/8916#comment:14
>
> That ticket notes that change password, for example, won't work if you base
> your customized class on admin.ModelAdmin, there may also be other such
> things.
>
> 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: Can I overwrite the ModelAdmin for User

2009-02-16 Thread Kevin Audleman

Alex,

I managed to get it to work, and the column is even sortable! Thanks
for your help.

Here's my code for reference for anyone else who comes across this
post:

class UserAdmin(admin.ModelAdmin):

def display_profile_status(self, obj):
profile = obj.myprofile_set.all()
if len(profile) > 0:
return "%s" % profile[0].get_status_display()
else:
return "Nada"
display_profile_status.short_description = 'Status'
display_profile_status.allow_tags = True
display_profile_status.admin_order_field = 'myprofile__status'

inlines = [MyProfileInline]
list_display = ('username',
'first_name',
'last_name',
'email',
'is_active',
'display_profile_status',
    )


On Feb 16, 4:15 pm, Alex Gaynor  wrote:
> On Mon, Feb 16, 2009 at 7:13 PM, Kevin Audleman 
> wrote:
>
>
>
>
>
> > Alex,
>
> > I feel like I'm one step closer to getting this to work. From the
> > documentation you sent my way, it seems like what I would do would be
> > to create a method on the User object which will span the relationship
> > and grab the value:,
>
> > def get_payment_status(self):
> >    return self.myprofile_set.all()[0].payment_status
>
> > However I am working with the core User object which I didn't write.
> > Am I SOL, or is there some way I can do this.
>
> > Thanks,
> > Kevin
>
> > On Feb 16, 4:02 pm, Alex Gaynor  wrote:
> > > On Mon, Feb 16, 2009 at 6:59 PM, Kevin Audleman <
> > kevin.audle...@gmail.com>wrote:
>
> > > > Thanks!
>
> > > > I've got my new User display going and another question has come up.
> > > > In the related MyProfile object, I've got a field called
> > > > payment_status. It's important for my client to be able to quickly
> > > > view a list of users with a payment_status of 'Unpaid.' Is there a way
> > > > to add a related field to the list_display or list_filter sets for the
> > > > User object?
>
> > > > Cheers,
> > > > Kevin
>
> > > > On Feb 16, 3:45 pm, Alex Gaynor  wrote:
> > > > > On Mon, Feb 16, 2009 at 6:27 PM, Kevin Audleman <
> > > > kevin.audle...@gmail.com>wrote:
>
> > > > > > I've created a custom profile per the instructions in chapter 12 of
> > > > > > the book to give my user's fields like address1, address2, etc.
> > > > > > Currently when I log in to the admin and want to update a user, I
> > have
> > > > > > to go to two separate pages: the User page to update core user
> > fields,
> > > > > > and the Profile page to update fields in the profiles.
>
> > > > > > I would like to overwrite the ModelAdmin for the User object and
> > > > > > inline the Profile object so that all fields for a user can be
> > edited
> > > > > > from one page. However django is throwing an error when I try to do
> > > > > > so:
>
> > > > > > AlreadyRegistered at /admin/
> > > > > > The model User is already registered
>
> > > > > > Here's the code:
>
> > > > > > class ProfileInline(admin.TabularInline):
> > > > > >    model = MyProfile
>
> > > > > > class UserAdmin(admin.ModelAdmin):
> > > > > >    list_display = ('username', 'email', 'first_name', 'last_name',
> > > > > > 'is_staff')
> > > > > >    list_filter = ('is_staff', 'is_superuser')
> > > > > >    inlines = [ProfileInline]
>
> > > > > > admin.site.register(User, UserAdmin)
>
> > > > > > Is there a way to do this?
>
> > > > > > Thanks,
> > > > > > Kevin Audleman
>
> > > > > Yes just do admin.site.unregister(User) before registering yours.
>
> > > > > 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 can add it to the list_display by creating a method on the model for
> > it(http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-display)
> > and
> > > perhaps use the boolean option to make it more obvious.  Right now you
> > can't
> > > actually use related fields in list_filter:
> >http://code.djangoproject.com/ticket/3400
>
> > > 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 can also just write a method on the ModelAdmin itself, as the examples
> show.
>
> 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: Can I overwrite the ModelAdmin for User

2009-02-16 Thread Kevin Audleman

Alex,

I feel like I'm one step closer to getting this to work. From the
documentation you sent my way, it seems like what I would do would be
to create a method on the User object which will span the relationship
and grab the value:,

def get_payment_status(self):
return self.myprofile_set.all()[0].payment_status

However I am working with the core User object which I didn't write.
Am I SOL, or is there some way I can do this.

Thanks,
Kevin


On Feb 16, 4:02 pm, Alex Gaynor  wrote:
> On Mon, Feb 16, 2009 at 6:59 PM, Kevin Audleman 
> wrote:
>
>
>
>
>
> > Thanks!
>
> > I've got my new User display going and another question has come up.
> > In the related MyProfile object, I've got a field called
> > payment_status. It's important for my client to be able to quickly
> > view a list of users with a payment_status of 'Unpaid.' Is there a way
> > to add a related field to the list_display or list_filter sets for the
> > User object?
>
> > Cheers,
> > Kevin
>
> > On Feb 16, 3:45 pm, Alex Gaynor  wrote:
> > > On Mon, Feb 16, 2009 at 6:27 PM, Kevin Audleman <
> > kevin.audle...@gmail.com>wrote:
>
> > > > I've created a custom profile per the instructions in chapter 12 of
> > > > the book to give my user's fields like address1, address2, etc.
> > > > Currently when I log in to the admin and want to update a user, I have
> > > > to go to two separate pages: the User page to update core user fields,
> > > > and the Profile page to update fields in the profiles.
>
> > > > I would like to overwrite the ModelAdmin for the User object and
> > > > inline the Profile object so that all fields for a user can be edited
> > > > from one page. However django is throwing an error when I try to do
> > > > so:
>
> > > > AlreadyRegistered at /admin/
> > > > The model User is already registered
>
> > > > Here's the code:
>
> > > > class ProfileInline(admin.TabularInline):
> > > >    model = MyProfile
>
> > > > class UserAdmin(admin.ModelAdmin):
> > > >    list_display = ('username', 'email', 'first_name', 'last_name',
> > > > 'is_staff')
> > > >    list_filter = ('is_staff', 'is_superuser')
> > > >    inlines = [ProfileInline]
>
> > > > admin.site.register(User, UserAdmin)
>
> > > > Is there a way to do this?
>
> > > > Thanks,
> > > > Kevin Audleman
>
> > > Yes just do admin.site.unregister(User) before registering yours.
>
> > > 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 can add it to the list_display by creating a method on the model for 
> it(http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-display) and
> perhaps use the boolean option to make it more obvious.  Right now you can't
> actually use related fields in 
> list_filter:http://code.djangoproject.com/ticket/3400
>
> 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: Can I overwrite the ModelAdmin for User

2009-02-16 Thread Kevin Audleman

Thanks!

I've got my new User display going and another question has come up.
In the related MyProfile object, I've got a field called
payment_status. It's important for my client to be able to quickly
view a list of users with a payment_status of 'Unpaid.' Is there a way
to add a related field to the list_display or list_filter sets for the
User object?

Cheers,
Kevin

On Feb 16, 3:45 pm, Alex Gaynor  wrote:
> On Mon, Feb 16, 2009 at 6:27 PM, Kevin Audleman 
> wrote:
>
>
>
>
>
> > I've created a custom profile per the instructions in chapter 12 of
> > the book to give my user's fields like address1, address2, etc.
> > Currently when I log in to the admin and want to update a user, I have
> > to go to two separate pages: the User page to update core user fields,
> > and the Profile page to update fields in the profiles.
>
> > I would like to overwrite the ModelAdmin for the User object and
> > inline the Profile object so that all fields for a user can be edited
> > from one page. However django is throwing an error when I try to do
> > so:
>
> > AlreadyRegistered at /admin/
> > The model User is already registered
>
> > Here's the code:
>
> > class ProfileInline(admin.TabularInline):
> >    model = MyProfile
>
> > class UserAdmin(admin.ModelAdmin):
> >    list_display = ('username', 'email', 'first_name', 'last_name',
> > 'is_staff')
> >    list_filter = ('is_staff', 'is_superuser')
> >    inlines = [ProfileInline]
>
> > admin.site.register(User, UserAdmin)
>
> > Is there a way to do this?
>
> > Thanks,
> > Kevin Audleman
>
> Yes just do admin.site.unregister(User) before registering yours.
>
> 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
-~--~~~~--~~--~--~---



Can I overwrite the ModelAdmin for User

2009-02-16 Thread Kevin Audleman

I've created a custom profile per the instructions in chapter 12 of
the book to give my user's fields like address1, address2, etc.
Currently when I log in to the admin and want to update a user, I have
to go to two separate pages: the User page to update core user fields,
and the Profile page to update fields in the profiles.

I would like to overwrite the ModelAdmin for the User object and
inline the Profile object so that all fields for a user can be edited
from one page. However django is throwing an error when I try to do
so:

AlreadyRegistered at /admin/
The model User is already registered


Here's the code:

class ProfileInline(admin.TabularInline):
model = MyProfile

class UserAdmin(admin.ModelAdmin):
list_display = ('username', 'email', 'first_name', 'last_name',
'is_staff')
list_filter = ('is_staff', 'is_superuser')
inlines = [ProfileInline]

admin.site.register(User, UserAdmin)

Is there a way to do this?

Thanks,
Kevin Audleman
--~--~-~--~~~---~--~~
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: Trying to retrieve dynamically generated session key in template

2009-02-11 Thread Kevin Audleman

I have the same session. Django has been so slick so far I would
imagine it has a way to access session variables from a template. Have
you found the solution?

Kevin

On Jan 17, 1:15 pm, dahpgjgamgan  wrote:
> Hi,
>
> A simple scenario:
>    - A generic object detail view, on which I can vote for the
> displayed object.
>    - vote is handled by custom view which sets a key in session (named
> "vote_) indicating that a vote was made
>    - in the template I want to check for existance of this key, and if
> present, don't display the vote form
>
> Question:
>    - how to get to this key (which value is dependant from object_id
> and thus, only known at runtime) from the template
>
> I know that I could write my own view which could add appropriate
> values to context, but I want to know if i just reached the point
> where generic views are just not enaugh - it seems to me that the
> template can get the required info (it has access to request session).
> I just don't know the syntax.
>
> Thanks for any help.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I display the human readable name of a choice?

2009-02-11 Thread Kevin Audleman

I could've swore I tried that before posting my question and it didn't
work, but I tried it this time and it did. Anyhow, a long winded way
of apologizing for asking a simple question. Thank you for taking the
time to answer!

Kevin

On Feb 10, 3:41 pm, Alex Gaynor  wrote:
> On Tue, Feb 10, 2009 at 6:39 PM, Kevin Audleman 
> wrote:
>
>
>
>
>
> > Thanks Alex, however this is a solution at the View level, and I'm
> > using a view that I didn't write. Is there also a way to do this at
> > the template level?
>
> > Thanks again,
> > Kevin
>
> > On Feb 10, 1:24 pm, Alex Gaynor  wrote:
> > > On Tue, Feb 10, 2009 at 4:23 PM, Kevin Audleman <
> > kevin.audle...@gmail.com>wrote:
>
> > > > Hi everyone,
>
> > > > I've set up a model that has a state field with the input set to a
> > > > list of states,
>
> > > > state = models.CharField(max_length=100, blank=True,
> > > > choices=US_STATE_LIST)
>
> > > > The drop-down on the edit form works great, displaying 'Alabama'  and
> > > > storing AL in the database. However when I view it, I see AL. How do I
> > > > get django to display the human readable name?
>
> > > > I would prefer to do this on the template level, as I'm using a view
> > > > from a contributed app that I can't modify.
>
> > > > Thanks,
> > > > Kevin
>
> > >http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddo...
>
> > > 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
>
> Yes, the same thing works {{ model.get_FIELD_display }}.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I display the human readable name of a choice?

2009-02-10 Thread Kevin Audleman

Thanks Alex, however this is a solution at the View level, and I'm
using a view that I didn't write. Is there also a way to do this at
the template level?

Thanks again,
Kevin

On Feb 10, 1:24 pm, Alex Gaynor  wrote:
> On Tue, Feb 10, 2009 at 4:23 PM, Kevin Audleman 
> wrote:
>
>
>
>
>
> > Hi everyone,
>
> > I've set up a model that has a state field with the input set to a
> > list of states,
>
> > state = models.CharField(max_length=100, blank=True,
> > choices=US_STATE_LIST)
>
> > The drop-down on the edit form works great, displaying 'Alabama'  and
> > storing AL in the database. However when I view it, I see AL. How do I
> > get django to display the human readable name?
>
> > I would prefer to do this on the template level, as I'm using a view
> > from a contributed app that I can't modify.
>
> > Thanks,
> > Kevin
>
> http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddo...
>
> 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
-~--~~~~--~~--~--~---



How do I display the human readable name of a choice?

2009-02-10 Thread Kevin Audleman

Hi everyone,

I've set up a model that has a state field with the input set to a
list of states,

state = models.CharField(max_length=100, blank=True,
choices=US_STATE_LIST)

The drop-down on the edit form works great, displaying 'Alabama'  and
storing AL in the database. However when I view it, I see AL. How do I
get django to display the human readable name?

I would prefer to do this on the template level, as I'm using a view
from a contributed app that I can't modify.

Thanks,
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: Can I do this with django?

2009-02-06 Thread Kevin Audleman

Wow, that is very cool. I implemented it and it works! Django is
definitely a very impressive framework.

Thanks for your help!
Kevin

On Feb 6, 10:31 am, Alex Gaynor  wrote:
> On Fri, Feb 6, 2009 at 12:58 PM, Kevin Audleman 
> wrote:
>
>
>
>
>
> > Thanks Alex!
>
> > My Project class has the field
>
> > client = models.ForeignKey(Client')
>
> > Would I use this in my save() method to reference the parent Client?
> > For instance
>
> > class Project:
> >    def save():
> >        self.hourly_rate = client.hourly_rate
> >        ...
>
> > Or is there some other way of working across the relationship?
>
> > Cheers,
> > Kevin
>
> > On Feb 6, 9:46 am, Alex Gaynor  wrote:
> > > On Fri, Feb 6, 2009 at 12:43 PM, Kevin Audleman <
> > kevin.audle...@gmail.com>wrote:
>
> > > > I'm building a simple time tracker. It has a table Clients and a table
> > > > Projects and there is a one-to-many relationship between them. I  have
> > > > a field called hourly_rate that is in both tables. The reasoning is
> > > > that in general the hourly rate is the same across projects based on
> > > > the client, but if at some point the hourly_rate goes up, I need to
> > > > keep track of the historical rate I charged on Projects. What I would
> > > > like to do is, on creation of a new Project, automatically populate
> > > > its hourly_rate field with the value from Clients. Is this possible to
> > > > set up in django? I'm used to Filemaker where I have the ability to
> > > > auto-populate fields on creation through relationships, but django is
> > > > a new world unto me.
>
> > > > Thanks for your help,
> > > > Kevin Audleman
>
> > > Yep this is possible, basically what you're going to want to do is
> > override
> > > the save() method on a Project so that when it gets created it just
> > copies
> > > it's Clients hourly pay, you can look for other examples of using this
> > > technique to accomplish other things(such as automatically setting the
> > > creation date on a field).
>
> > > 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
>
> It would look something like this:
>
> class Project(models.Model):
>    def save(self, *args, **kwargs):
>        if not self.id:
>            self.hourly_rate = self.client.hourly_rate
>        super(Project, self).save(*args, **kwargs)
>
> that way it only sets the hourly rate the first time you save a project, in
> case you edit it later you don't want the hourly rate to change.
>
> 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: Can I do this with django?

2009-02-06 Thread Kevin Audleman

Thanks Alex!

My Project class has the field

client = models.ForeignKey(Client')

Would I use this in my save() method to reference the parent Client?
For instance

class Project:
def save():
self.hourly_rate = client.hourly_rate
...

Or is there some other way of working across the relationship?

Cheers,
Kevin

On Feb 6, 9:46 am, Alex Gaynor  wrote:
> On Fri, Feb 6, 2009 at 12:43 PM, Kevin Audleman 
> wrote:
>
>
>
>
>
> > I'm building a simple time tracker. It has a table Clients and a table
> > Projects and there is a one-to-many relationship between them. I  have
> > a field called hourly_rate that is in both tables. The reasoning is
> > that in general the hourly rate is the same across projects based on
> > the client, but if at some point the hourly_rate goes up, I need to
> > keep track of the historical rate I charged on Projects. What I would
> > like to do is, on creation of a new Project, automatically populate
> > its hourly_rate field with the value from Clients. Is this possible to
> > set up in django? I'm used to Filemaker where I have the ability to
> > auto-populate fields on creation through relationships, but django is
> > a new world unto me.
>
> > Thanks for your help,
> > Kevin Audleman
>
> Yep this is possible, basically what you're going to want to do is override
> the save() method on a Project so that when it gets created it just copies
> it's Clients hourly pay, you can look for other examples of using this
> technique to accomplish other things(such as automatically setting the
> creation date on a field).
>
> 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
-~--~~~~--~~--~--~---



Can I do this with django?

2009-02-06 Thread Kevin Audleman

I'm building a simple time tracker. It has a table Clients and a table
Projects and there is a one-to-many relationship between them. I  have
a field called hourly_rate that is in both tables. The reasoning is
that in general the hourly rate is the same across projects based on
the client, but if at some point the hourly_rate goes up, I need to
keep track of the historical rate I charged on Projects. What I would
like to do is, on creation of a new Project, automatically populate
its hourly_rate field with the value from Clients. Is this possible to
set up in django? I'm used to Filemaker where I have the ability to
auto-populate fields on creation through relationships, but django is
a new world unto me.

Thanks for your help,
Kevin Audleman
--~--~-~--~~~---~--~~
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: Newbie question: first project can't connect to MySQL

2009-02-04 Thread Kevin Audleman

I found the solution in the archives: I changed DATABASE_HOST to
127.0.0.1 from ''

Kevin

On Feb 4, 9:41 am, Kevin Audleman  wrote:
> Hello everyone,
>
> I am running through the tutorial and setting up my first django
> project. Quite exciting! However I have run into trouble connecting to
> MySQL. My settings.py file looks like this:
>
> DATABASE_ENGINE = 'mysql'           # 'postgresql_psycopg2',
> 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
> DATABASE_NAME = 'test'             # Or path to database file if using
> sqlite3.
> DATABASE_USER = 'root'             # Not used with sqlite3.
> DATABASE_PASSWORD = ''         # Not used with sqlite3.
> DATABASE_HOST = ''             # Set to empty string for localhost.
> Not used with sqlite3.
> DATABASE_PORT = ''             # Set to empty string for default. Not
> used with sqlite3.
>
> Yes, the username is 'root' and there is no password. This is on my
> local machine (OS X 10.5) so it doesn't matter.
>
> When I run...
>
> $ python manage.py syncdb
>
> I get the following...
>
> Traceback (most recent call last):
>   File "manage.py", line 11, in 
>     execute_manager(settings)
>   File "/Library/Python/2.5/site-packages/django/core/management/
> __init__.py", line 340, in execute_manager
>     utility.execute()
>   File "/Library/Python/2.5/site-packages/django/core/management/
> __init__.py", line 295, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "/Library/Python/2.5/site-packages/django/core/management/
> base.py", line 192, in run_from_argv
>     self.execute(*args, **options.__dict__)
>   File "/Library/Python/2.5/site-packages/django/core/management/
> base.py", line 218, in execute
>     self.validate()
>   File "/Library/Python/2.5/site-packages/django/core/management/
> base.py", line 246, in validate
>     num_errors = get_validation_errors(s, app)
>   File "/Library/Python/2.5/site-packages/django/core/management/
> validation.py", line 65, in get_validation_errors
>     connection.validation.validate_field(e, opts, f)
>   File "/Library/Python/2.5/site-packages/django/db/backends/mysql/
> validation.py", line 8, in validate_field
>     db_version = connection.get_server_version()
>   File "/Library/Python/2.5/site-packages/django/db/backends/mysql/
> base.py", line 277, in get_server_version
>     self.cursor()
>   File "/Library/Python/2.5/site-packages/django/db/backends/
> __init__.py", line 56, in cursor
>     cursor = self._cursor(settings)
>   File "/Library/Python/2.5/site-packages/django/db/backends/mysql/
> base.py", line 262, in _cursor
>     self.connection = Database.connect(**kwargs)
>   File "/Users/audleman/django_projects/pollster/__init__.py", line
> 74, in Connect
>
>   File "/Library/Python/2.5/site-packages/MySQL_python-1.2.2-py2.5-
> macosx-10.5-i386.egg/MySQLdb/connections.py", line 170, in __init__
> _mysql_exceptions.OperationalError: (2002, "Can't connect to local
> MySQL server through socket '/tmp/mysql.sock' (2)")
>
> I'm not exactly sure what this socket is or why django can't find it.
> One thought is that I installed LAMP on my machine using XAMPP, which
> puts everything in the /Applications/xampp directory. Poking around, I
> managed to find a mysql.sock file here:
>
> /Applications/xampp/xamppfiles/var/mysql/mysql.sock
>
> Assuming this is the correct socket, how do I tell django where to
> find it?
>
> Thanks,
> 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
-~--~~~~--~~--~--~---



Newbie question: first project can't connect to MySQL

2009-02-04 Thread Kevin Audleman

Hello everyone,

I am running through the tutorial and setting up my first django
project. Quite exciting! However I have run into trouble connecting to
MySQL. My settings.py file looks like this:

DATABASE_ENGINE = 'mysql'   # 'postgresql_psycopg2',
'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'test' # Or path to database file if using
sqlite3.
DATABASE_USER = 'root' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost.
Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not
used with sqlite3.

Yes, the username is 'root' and there is no password. This is on my
local machine (OS X 10.5) so it doesn't matter.

When I run...

$ python manage.py syncdb

I get the following...

Traceback (most recent call last):
  File "manage.py", line 11, in 
execute_manager(settings)
  File "/Library/Python/2.5/site-packages/django/core/management/
__init__.py", line 340, in execute_manager
utility.execute()
  File "/Library/Python/2.5/site-packages/django/core/management/
__init__.py", line 295, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.5/site-packages/django/core/management/
base.py", line 192, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/Library/Python/2.5/site-packages/django/core/management/
base.py", line 218, in execute
self.validate()
  File "/Library/Python/2.5/site-packages/django/core/management/
base.py", line 246, in validate
num_errors = get_validation_errors(s, app)
  File "/Library/Python/2.5/site-packages/django/core/management/
validation.py", line 65, in get_validation_errors
connection.validation.validate_field(e, opts, f)
  File "/Library/Python/2.5/site-packages/django/db/backends/mysql/
validation.py", line 8, in validate_field
db_version = connection.get_server_version()
  File "/Library/Python/2.5/site-packages/django/db/backends/mysql/
base.py", line 277, in get_server_version
self.cursor()
  File "/Library/Python/2.5/site-packages/django/db/backends/
__init__.py", line 56, in cursor
cursor = self._cursor(settings)
  File "/Library/Python/2.5/site-packages/django/db/backends/mysql/
base.py", line 262, in _cursor
self.connection = Database.connect(**kwargs)
  File "/Users/audleman/django_projects/pollster/__init__.py", line
74, in Connect

  File "/Library/Python/2.5/site-packages/MySQL_python-1.2.2-py2.5-
macosx-10.5-i386.egg/MySQLdb/connections.py", line 170, in __init__
_mysql_exceptions.OperationalError: (2002, "Can't connect to local
MySQL server through socket '/tmp/mysql.sock' (2)")


I'm not exactly sure what this socket is or why django can't find it.
One thought is that I installed LAMP on my machine using XAMPP, which
puts everything in the /Applications/xampp directory. Poking around, I
managed to find a mysql.sock file here:

/Applications/xampp/xamppfiles/var/mysql/mysql.sock

Assuming this is the correct socket, how do I tell django where to
find it?

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