Re: Unicode and django/db/backends/util.py

2006-10-03 Thread Malcolm Tredinnick

On Tue, 2006-10-03 at 22:26 -0700, Beau Hartshorne wrote:
> On 3-Oct-06, at 7:36 PM, Malcolm Tredinnick wrote:
> 
> > So this is the value that the string has right at the moment the
> > exception occurs? Can you paste the traceback you see, please (and
> > preferably the value of 'sql' and 'params' at that point as well).
> >
> > I'm a bit in the dark about what is happening right now, since
> > subsituting a UTF-8 string into a Python string should work easily.
> >
>  s = unicode('Djang\xc3\xa9', 'utf-8')
>  print "update foo set blah = '%s'" % s
> > update foo set blah = 'Djangé'
> >
> > is an example of what should be happening. I suspect there is  
> > something
> > else important about what you are doing. Not accusing you of
> > deliberately misleading or anything -- I have no idea what the  
> > important
> > thing is yet, either.
> 
> Actually, this is what I get:
> 
>  >>> import sys
>  >>> print sys.version
> 2.4.3 (#1, Mar 30 2006, 11:02:16)
> [GCC 4.0.1 (Apple Computer, Inc. build 5250)]
> 
>  >>> s = unicode('Djang\xc3\xa9', 'utf-8')
>  >>> print "update foo set blah = '%s'" % s
> Traceback (most recent call last):
>File "", line 1, in ?
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in  
> position 28: ordinal not in range(128)
> 
> But, if I do this:
> 
>  >>> s = 'Djang\xc3\xa9'
>  >>> print "update foo set blah = '%s'" % s
> update foo set blah = 'Djangé'
> 
> I haven't played with the default encoding at all.

Oh sod :-( It's also an environment locale thing. My system typically
runs in en_AU.UTF-8 (so UTF-8 by default). If I run in the "C" or "en"
locales, I get the same thing.

So, yeah, it looks like you have to run s.encode('utf-8') on your
strings before trying to work with them in that case.

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Unicode and django/db/backends/util.py

2006-10-03 Thread Beau Hartshorne

On 3-Oct-06, at 7:36 PM, Malcolm Tredinnick wrote:

> So this is the value that the string has right at the moment the
> exception occurs? Can you paste the traceback you see, please (and
> preferably the value of 'sql' and 'params' at that point as well).
>
> I'm a bit in the dark about what is happening right now, since
> subsituting a UTF-8 string into a Python string should work easily.
>
 s = unicode('Djang\xc3\xa9', 'utf-8')
 print "update foo set blah = '%s'" % s
> update foo set blah = 'Djangé'
>
> is an example of what should be happening. I suspect there is  
> something
> else important about what you are doing. Not accusing you of
> deliberately misleading or anything -- I have no idea what the  
> important
> thing is yet, either.

Actually, this is what I get:

 >>> import sys
 >>> print sys.version
2.4.3 (#1, Mar 30 2006, 11:02:16)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)]

 >>> s = unicode('Djang\xc3\xa9', 'utf-8')
 >>> print "update foo set blah = '%s'" % s
Traceback (most recent call last):
   File "", line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in  
position 28: ordinal not in range(128)

But, if I do this:

 >>> s = 'Djang\xc3\xa9'
 >>> print "update foo set blah = '%s'" % s
update foo set blah = 'Djangé'

I haven't played with the default encoding at all.

Thanks,
Beau
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: User object available in base template

2006-10-03 Thread Alan Green

On 10/4/06, Patrick J. Anderson <[EMAIL PROTECTED]> wrote:
...
> def main(request):
>  posts = Post.objects.filter(is_approved =
> True).order_by('-time_added')[:5]
>  t = loader.get_template('homepage.html')
>  c = RequestContext({
>  'latest_posts': posts,
>  })


That's it there, I think. RequestContext takes a request object as its
first parameter. Try

  c = RequestContext(request, {
  'latest_posts': posts,
  })

Cheers,

Alan

-- 
Alan Green
[EMAIL PROTECTED] - http://bright-green.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: User object available in base template

2006-10-03 Thread Don Arbow

On Oct 3, 2006, at 9:30 PM, Patrick J. Anderson wrote:
>
> def main(request):
>  posts = Post.objects.filter(is_approved =
> True).order_by('-time_added')[:5]
>  t = loader.get_template('homepage.html')
>  c = RequestContext({
>  'latest_posts': posts,
>  })
>  return HttpResponse(t.render(c))
>
> What am I doing wrong?



You have to pass the request object into the RequestContext  
constructor. Then the user object will show up in your templates.

c= RequestContext(request, { ... })

Don



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: User object available in base template

2006-10-03 Thread Patrick J. Anderson

Forgot to add my specific error:

Exception Type: AttributeError
Exception Value:'dict' object has no attribute 'user'
Exception Location: 
/usr/lib/python2.4/site-packages/django/core/context_processors.py in 
auth, line 17

Patrick J. Anderson



Patrick J. Anderson wrote:
> In my project, I have a root template called base.html, which all other 
> templates extend.
> 
> I'd like to create a simple navigation with user information, which I 
> want to write once and put in the base template to be shown on every page.
> 
> I'm not sure what the best way of retrieving information from User 
> object at the template root level is. I've read about RequestContext 
> object and template processors, but the docs are not very clear to me 
> and leave a lot to be guessed. I've followed the guides, but still I 
> can't get User object in my template. But then again, perhaps the 
> solution is simple, and I'm just too dense to see it.
> 
> Below is the very simple view code I'm testing:
> 
> from django.template import RequestContext, loader
> from django.http import HttpResponse
> from myproject.apps.journal.models import Post
> 
> 
> def main(request):
>  posts = Post.objects.filter(is_approved = 
> True).order_by('-time_added')[:5]
>  t = loader.get_template('homepage.html')
>  c = RequestContext({
>  'latest_posts': posts,
>  })
>  return HttpResponse(t.render(c))
> 
> 
> And here's a piece of template from "homepage.html":
> 
> {% block user_nav %}
> 
> {% if user %}
>   {{ user.first_name 
> }}
> {% else %}
>   Anonymous
> {% endif %}
> 
> {% endblock %}
> 
> 
> What am I doing wrong?
> 
> 
> > 
> 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



User object available in base template

2006-10-03 Thread Patrick J. Anderson

In my project, I have a root template called base.html, which all other 
templates extend.

I'd like to create a simple navigation with user information, which I 
want to write once and put in the base template to be shown on every page.

I'm not sure what the best way of retrieving information from User 
object at the template root level is. I've read about RequestContext 
object and template processors, but the docs are not very clear to me 
and leave a lot to be guessed. I've followed the guides, but still I 
can't get User object in my template. But then again, perhaps the 
solution is simple, and I'm just too dense to see it.

Below is the very simple view code I'm testing:

from django.template import RequestContext, loader
from django.http import HttpResponse
from myproject.apps.journal.models import Post


def main(request):
 posts = Post.objects.filter(is_approved = 
True).order_by('-time_added')[:5]
 t = loader.get_template('homepage.html')
 c = RequestContext({
 'latest_posts': posts,
 })
 return HttpResponse(t.render(c))


And here's a piece of template from "homepage.html":

{% block user_nav %}

{% if user %}
{{ user.first_name 
}}
{% else %}
Anonymous
{% endif %}

{% endblock %}


What am I doing wrong?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



slug field and generic create view

2006-10-03 Thread Patrick J. Anderson

Is there a simple way to add the slug field to a custom form template?

I'm using django.views.generic.create_update.create_object and my model 
has a slug field. Whenever I try to add a new item to database, I 
receive error saying that my "title" is similar to the on existing in 
the database, so I suspect it has to do with the slug field not being 
populated.

I looked at the source code of admin pages and I see urlify.js script in 
the head of the document, but how should I include it in my own template?

Patrick J.Anderson


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: If drop the database (dropdb ) and rmdir the directory, is that it?

2006-10-03 Thread Malcolm Tredinnick

On Tue, 2006-10-03 at 19:34 -0700, carlwenrich wrote:
> In other words, is there anything else I need to do to remove a project?

Did you modify the web server configuration file anywhere?

Otherwise, that should be all you need to do.

Regards,
Malcolm

> 
> 
> > 



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Unicode and django/db/backends/util.py

2006-10-03 Thread Malcolm Tredinnick

On Tue, 2006-10-03 at 19:27 -0700, Beau Hartshorne wrote:
> On 3-Oct-06, at 6:56 PM, Malcolm Tredinnick wrote:
> 
> > This probably isn't going to solve your problem, but it might help  
> > track
> > down what is really happening...
> >
> > UnicodeDecodeError usually means that you are trying to use unicode
> > strings that haven't been converted to UTF-8 when they needed to be.
> > Django mostly "just works" if you pass around UTF-8 strings as strings
> > of bytes. It doesn't work entirely with native unicode objects
> > internally.
> >
> > So, I would check that you are really using UTF-8 bytes at that point.
> >
> > Could you maybe post the contents of "sql" and "params" when you  
> > get the
> > above error (post "params" in repr() format, not as a printed string,
> > since it's important to see the encoding, not just the output
> > character).
> 
> Hi Malcolm,
> 
> A repr() of 'Djangé' (from browser input) is 'Djang\xc3\xa9'.
> 
> I've checked that everything is set to UTF-8 (database defaults,  
> database tables, charset, html meta, django default). Should I  
> be .encode('utf8') any string I pass around, or am I doing something  
> else wrong?

So this is the value that the string has right at the moment the
exception occurs? Can you paste the traceback you see, please (and
preferably the value of 'sql' and 'params' at that point as well).

I'm a bit in the dark about what is happening right now, since
subsituting a UTF-8 string into a Python string should work easily.

>>> s = unicode('Djang\xc3\xa9', 'utf-8')
>>> print "update foo set blah = '%s'" % s
update foo set blah = 'Djangé'

is an example of what should be happening. I suspect there is something
else important about what you are doing. Not accusing you of
deliberately misleading or anything -- I have no idea what the important
thing is yet, either.

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



If drop the database (dropdb ) and rmdir the directory, is that it?

2006-10-03 Thread carlwenrich

In other words, is there anything else I need to do to remove a project?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: SET TIME ZONE Error

2006-10-03 Thread Malcolm Tredinnick

On Wed, 2006-10-04 at 00:41 +, gkelly wrote:
> I am getting the following error when trying to call model.save() from
> a custom Manipulator
> 
> Traceback (most recent call last):
[...]
> ProgrammingError: ERROR:  current transaction is aborted, commands
> ignored until end of transaction block
> 
> SET TIME ZONE 'GMT'
> --- end Error ---
> 
> Any ideas?

Often this indicates there was actually an error on the previous
statement and it is only detected/reported on the next query.

To try and track this down, have a look at the contents of
django.db.connection.queries (it's a list) just before the statement
that throws the error (or even print it out inside
django/db/backend/util.py (in CursorDebugWrapper.execute()) each time.

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Unicode and django/db/backends/util.py

2006-10-03 Thread Beau Hartshorne

On 3-Oct-06, at 6:56 PM, Malcolm Tredinnick wrote:

> This probably isn't going to solve your problem, but it might help  
> track
> down what is really happening...
>
> UnicodeDecodeError usually means that you are trying to use unicode
> strings that haven't been converted to UTF-8 when they needed to be.
> Django mostly "just works" if you pass around UTF-8 strings as strings
> of bytes. It doesn't work entirely with native unicode objects
> internally.
>
> So, I would check that you are really using UTF-8 bytes at that point.
>
> Could you maybe post the contents of "sql" and "params" when you  
> get the
> above error (post "params" in repr() format, not as a printed string,
> since it's important to see the encoding, not just the output
> character).

Hi Malcolm,

A repr() of 'Djangé' (from browser input) is 'Djang\xc3\xa9'.

I've checked that everything is set to UTF-8 (database defaults,  
database tables, charset, html meta, django default). Should I  
be .encode('utf8') any string I pass around, or am I doing something  
else wrong?

Thanks!
Beau


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Handling phone extensions?

2006-10-03 Thread Malcolm Tredinnick

On Tue, 2006-10-03 at 18:09 -0400, Fast, Adam wrote:
> I’m working on an app and need a Phone number/extension.  I’m using a
> PhoneNumberField(), but was curious if there was a way to make an
> extension field appear to the side.  Is that part of the definition or
> is there an easy way to get this accomplished?

You'll need to write your own form field(s). The rendering of the HTML
elements is done by the render() method in the class, so you can
subclass the thing you want to change or override it's render method.

However, if you want to different form elements to be combined into a
single field, you are going to need to do some of the work there
yourself, since they will be submitted as different form elements.

Hmm ... (thinking out loud about something untested here) ... you could
have the render() method of your new field render both HTML elements and
then write a prepare() method to convert them back into a single data
element. See CheckboxSelectMultipleField for an example of a prepare()
method at work (in fact, the only example in django/forms/__init__.py).

Best wishes,
Malcolm

> 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: order admin list view

2006-10-03 Thread Malcolm Tredinnick

On Tue, 2006-10-03 at 19:38 +, David S. wrote:
> The docs say that, "regardless of how many fields are in ordering, the admin
> site uses only the first field."  To overcome this, I overrode the default
> manager to return a queryset ordered by the fields I want.  It works fine in
> code (interactively), but not in the admin view.  Should it?  Is there a
> workaround besides implementing the admin interface for this class myself?

Difficult to answer a question like this without details. What did you
do when you "overrode the default manager"? Replaced the "objects"
attribute in your model?

I'm not sure I'm going to be able to answer the question in any case,
but some details would increase your chances.

Cheers,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Implementing entity relationships that use compound keys in a Django application

2006-10-03 Thread Malcolm Tredinnick

On Tue, 2006-10-03 at 17:41 +0100, Sam Morris wrote:
> Hello everyone! I am new to Django and am currently learning how to use
> the model API. I am trying to construct a set of models to represent a
> number of people (characters in a game), who can be members of one or
> more organisations. Each person in an organisation has a rank in that
> organisation. My original sketch of how I would do this directly in a
> database looks like this:
> 
> Person
> Organisation
> Rank (*organisation, *rank, name)
> Membership (*person, *organisation, rank)
> 
> Membership.person -> Person
> Membership.(organisation + rank) -> Rank
> 
> Asterisks denote primary keys; where more than one field has an asterisk
> then the primary key is a compound key.
> 
> My problem is that Membership.(organisation + rank) is a compound
> foreign key, which Django does not support. My current implementation of
> the relationship uses a linkage model:
> 
> class OrgMembership (models.Model):
>   person = models.ForeignKey (person)
>   organisation = models.ForeignKey (Organisation)
>   rank = models.ForeignKey (Rank)
> 
>   class Meta:
>   unique_together = [['person', 'organisation']]
> 
> This allows OrgMembership.rank to be set to any possible rank, but I
> only want to allow OrgMemberships where Rank.organisation ==
> OrgMembership.organisation.
> 
> The solutions I have come up with so far are:
> 
>   * Forget the relationship between Membership.rank and Rank -- turn
> OrgMembership.rank into a simple integer
>   * Create a database constraint to enforce the restriction, and
> somehow alter the admin page to only allow legal values (using
> limit_choices_to?)
>   * Give the OrgMembership model a custom validation rule
> (presumably complemented by a manually-created database
> constraint)
>   * Decompose the relationship somehow
> 
> By 'decompose' I mean changing the schema to something like this:
> 
> Rank (level, name)
> OrgRank (organisation, rank)
> OrgMembership (person, org_rank)
> 
> The final option is probably the best one, but I thought I would post
> anyway to see if any more experienced users could confirm/deny, and to
> see if there are any other approaches that I have missed.

Looks to me like you have thought this through fairly carefully and all
of your options are not unreasonable (although I'm not entirely clear on
what the first one is).

The natural Django way here would be the third option, since Django
doesn't handle composite primary keys, but does give you a default
surrogate primary key on every table (the implicit "id" attribute, if
you don't explicitly set up a primary key). So you already have a
surrogate single field to point to in your relations.

Your second option would be the DBA way of thinking about this and isn't
entirely crazy, either. Django is set up to encourage thinking at the
Python model level, rather than the database level, but leaky
abstractions are in play here just as everywhere else and you end up
being aware of the database anyway. So if you want to install a CHECK()
constraint on your database table, you can do it as part of the initial
SQL when setting up the models (see the last section in the model API
documentation). As you have noted, you also then have to do something
with limit_choices_to and possibly a validator to enforce this at the
Python and form validation level, but it's shouldn't be too bad.

I've been thinking about this problem a little bit on and off lately as
part of putting in support for multi-column primary keys (getting the
relation API tweaked accordingly is the only really tricky part). I
haven't solved it yet, because working out how to express you second
option neatly and somehow automatically at the Django model level is not
completely obvious to me yet. So all I can say is that I think both your
latter two solutions (at leat) would work and the third one is the more
natural approach at the moment.

Regards,
Malcolm

> 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Unicode and django/db/backends/util.py

2006-10-03 Thread Malcolm Tredinnick

On Tue, 2006-10-03 at 08:15 -0700, Beau Hartshorne wrote:
> On database updates, utf-8 strings like ’ raise an UnicodeDecodeError  
> exception on line 19 of util.py (version 0.9.5). I can get around  
> this by commenting out this code in util.py, but is there something  
> else I could do?
> 
> self.db.queries.append({
>  'sql': sql % tuple(params),
>  'time': "%.3f" % (stop - start),
> })

This probably isn't going to solve your problem, but it might help track
down what is really happening...

UnicodeDecodeError usually means that you are trying to use unicode
strings that haven't been converted to UTF-8 when they needed to be.
Django mostly "just works" if you pass around UTF-8 strings as strings
of bytes. It doesn't work entirely with native unicode objects
internally.

So, I would check that you are really using UTF-8 bytes at that point.

Could you maybe post the contents of "sql" and "params" when you get the
above error (post "params" in repr() format, not as a printed string,
since it's important to see the encoding, not just the output
character).

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: migration from php and java

2006-10-03 Thread Malcolm Tredinnick

On Tue, 2006-10-03 at 15:35 +0200, Aljosa Mohorovic wrote:
> After some time with django i started porting current php/java
> applications i use to django.
> Please keep in mind that for duration of porting coexistence of
> php/java/django is required.
> That said, any help with current issue (sharing users, auth. system,
> with php and java) is appreciated.
> 
> I like admin interface for django and have strong believe i can push
> it in company i work for so i would like to transfer current
> authorization from php/java to django but enable php/java to
> authorize. i noticed that password field starts with sha1$something
> and i guess that i could use sha1() in php and MessageDigest in java.
> 
> this is my guess for password field format, please correct:
> password_field = "sha1$(output of php/java sha1 function)"
> 
> any notes on this subject or anything related would be appreciated.
> thanks

There are two sides to this problem that you need to solve:

(1) Authentication -- determining who the user is.

For this piece, you need a way to send username + password to
Django and get back a pass/fail response as to whether the user
is "real" or not. If you wanted to do that authentication
directly from Java and/or PHP, you could have those applications
query the database to get out the hashed password string and
username and do the validation themself.

(2) Authorisation -- access control based on the authenticated identity.

This is where it may get a little interesting. After
authentication, Django sets up the user's session to indicate
that they are logged in. Then we can query the users permissions
on a per-user and per-group basis.

For integration with your other applications, you are going to
need to do whatever session setup they require in order to have
seamless authorisation on subsequent requests. If you are using
session cookies in those applications as well, you need to set
multiple cookies (sharing the session cookies would require
modifications to Django core and be quite fiddly, I suspect --
without having actually done the work to test this).

Django stores the password hash as a SHA1 hash with salt of the user's
password. So converting the incoming password to the necessary hash for
comparison should be relatively simple in all languages, as you suspect.

There is no "standard way" to share pieces between Java and PHP and
Django, since the possibilities for set ups, particularly in the first
two cases, are practically endless. Assumptions will be made by all of
your apps about what is contained in the User information and what is
required for authorisation purposes. I would start by mapping out that
information and working out how to pass it back from the Django database
(or retrieve it directly) to the PHP and Java apps when required.

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: unique objects in list

2006-10-03 Thread Malcolm Tredinnick

On Tue, 2006-10-03 at 18:21 +0400, Grigory Fateyev wrote:
> Hello James Bennett!
> On Tue, 3 Oct 2006 08:28:02 -0500 you wrote:
> 
> > 
> > On 10/3/06, Grigory Fateyev <[EMAIL PROTECTED]> wrote:
> > > I have a list of ip in table, but this ip repeats many times. I
> > > need to show each ip only once with some statistic. How to do this?
> > 
> > http://www.djangoproject.com/documentation/db_api/#distinct
> 
> I don't get it, Blog.objects.all().distinct() is't working like sql
> query: select distinct column from blog;?

In both SQL and Django, "distinct" means "select distinct rows". So if
you run Blog.objects.all().distinct(), you will have every row returned,
since each row has a distinct value in the primary key column and thus
is not identical to any other row.

Something like Blog.objects.values('ip').distinct() will extract all the
distinct values from the "ip" column, however, as Rajesh points out,
elsewhere, if you also want to collect other statistics, you are going
to need to use custom SQL.

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: ManyToManyFields are not syncdb'able

2006-10-03 Thread seemant

Andy,

Duh on me :(  Thanks for all your help with this -- it works
beautifully now.  My next challenge is date based generic views, but
I'll open a new thread on that for archival's sake.

Thanks again!

Seemant


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: 1-Many Display in the Admin Area .

2006-10-03 Thread Malcolm Tredinnick

On Tue, 2006-10-03 at 06:37 -0700, MerMer wrote:
> Alan,
> 
> Thanks for helping out - but I'm more confused than ever.  If Django
> fields are required by default why use core=True at all?   What do I
> enter into the parameter so a field is NOT required.   I tried null =
> True and this didn't work (and as an aside it made the red highlights
> on the core=true fields disappear!).

There are two attributes that are useful here: blank = True indicates
that the field is not required to have a value and null=True means that
blank values will be stored as NULL in the database (except for string
fields).

So, to make a field optional, pass in blank=True when you construct it.

The "core" attribute serves a slightly different purpose: it indicates
which fields should be used as an indicator for when to delete this
object when edited inline via another object. You can have "core=True"
set on non-required fields and that is useful in some circumstances.

> edit_inline= models.TABULAR does not work.   Hopefully this explanation
> will make it clear.   When I click on a specific Promoter I want to
> display a list of all their related promotions.
> 
> Prometer Name
> ---
> Promotion Name 1-  Date Published
> Promotion Name 2 - Date Published
> Promotion Name 3 - Date Published
> 
> Then I want to be able to simply click the name to bring up the
> underlying record for editing.

You cannot do that directly with the Admin interface. It is set up to
work as a way to edit individual models directly (with some inline
editing support).

If you want to put in a slightly customised screen flow, it is not
impossible, but it would require customising portions of the code.

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: 1-Many Display in the Admin Area .

2006-10-03 Thread Malcolm Tredinnick

On Tue, 2006-10-03 at 08:26 -0400, Alan Johnson wrote:
> 1.  The objects are being displayed in the Admin area as
> "Promoters" 
> and "Promotionss" - note the added "s".
> 
> In Django it's convention to name models as singular nouns, not as
> plural nouns. Change Promotions to Promotion and you'll get what
> you're expecting. 

Since that is not always possible (e.g. a model called Mouse), there are
also the verbose_name and verbose_name_plural attributes that can be set
on the inner Meta class of a mdoel. See
http://www.djangoproject.com/documentation/model_api/#verbose-name .

Regards,
Malcolm




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: class with a ForeignKey and ManyToManyField, empty sql IN () clause after admin save

2006-10-03 Thread Russell Keith-Magee

On 10/4/06, L. Liddell <[EMAIL PROTECTED]> wrote:
>
> Any ideas?

This is a known problem:

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

I believe that this is one of many tickets that will be addressed by
Malcolm Treddinick's refactoring of the query system.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



SET TIME ZONE Error

2006-10-03 Thread gkelly

I am getting the following error when trying to call model.save() from
a custom Manipulator

Traceback (most recent call last):

  File
"/usr/local/lib/python2.4/site-packages/django/core/servers/basehttp.py",
line 272, in run
self.result = application(self.environ, self.start_response)

  File
"/usr/local/lib/python2.4/site-packages/django/core/servers/basehttp.py",
line 614, in __call__
return self.application(environ, start_response)

  File
"/usr/local/lib/python2.4/site-packages/django/core/handlers/wsgi.py",
line 189, in __call__
response = middleware_method(request, response)

  File
"/usr/local/lib/python2.4/site-packages/django/contrib/sessions/middleware.py",
line 89, in process_response
datetime.datetime.now() +
datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE))

  File
"/usr/local/lib/python2.4/site-packages/django/contrib/sessions/models.py",
line 29, in save
s.save()

  File
"/usr/local/lib/python2.4/site-packages/django/db/models/base.py", line
166, in save
cursor = connection.cursor()

  File
"/usr/local/lib/python2.4/site-packages/django/db/backends/postgresql/base.py",
line 46, in cursor
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])

ProgrammingError: ERROR:  current transaction is aborted, commands
ignored until end of transaction block

SET TIME ZONE 'GMT'
--- end Error ---

Any ideas?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



2 ways to render HTML snippet, which is preferred?

2006-10-03 Thread Rob Hudson

I'm working on a way to allow our content creators to put certain form
elements on pages based on question types (open text, radio, checkbox,
likert scale, etc).  I can see 2 ways of accomplishing what I'm trying
to do.

As pretext, I have 2 models: Question and Option.  Option has a
ForeignKey relationship to Question.

My goal is to specify the HTML for each question type once and not in
various templates.

1) Use inclusion tags.

So I'd create a method that takes a context which contains my question
object and also pass in a question id.  The method would return a data
structure with the question values and option values like this:

return {
'qtitle': question.title,
'options': question.option_set.all().order_by('sequence')
}

I'm pretty sure I can iterate over the internal options list just fine
in the template context.  The inclusion tag would render the HTML which
would be included in the main template.

2) Simply use template.render(context) and build the same context as
above.  I'd be adding the raw HTML to the main template context to
output rather than calling an inclusion tag to return the HTML.  This
would probably work just fine as well.

Is one more efficient?  Is one more preferred?  I'm leaning towards #1
since it seems like its purpose.  In some ways #2 seems like less code
and keeps more in the views.py file rather than #1 requiring
templatetags.

Thoughts?

Thanks,
Rob


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



User generated reports

2006-10-03 Thread Jaikumar

Hi  All
  I am using Django and python to build a web based framework. My
backend database is MySQL. So the users of this framework would like to
create and use customizable reports.

ex: If one of the tables in the MySQL DB is the results of a test plan
execution, then the users would like to create reports which would
summarize the results.

Is there any module / plugin available so that I could minimize the
effort involved ? I do NOT want to bypass Django and directly access
the database.

Thanks
Jaikumar


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Handling phone extensions?

2006-10-03 Thread Fast, Adam








I’m working on an app and need a Phone
number/extension.  I’m using a PhoneNumberField(), but was curious if
there was a way to make an extension field appear to the side.  Is that part of
the definition or is there an easy way to get this accomplished?

 

Adam




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django users" group.  To post to this group, send email to django-users@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/django-users  -~--~~~~--~~--~--~---






class with a ForeignKey and ManyToManyField, empty sql IN () clause after admin save

2006-10-03 Thread L. Liddell

Here's a simplified version of what I need to accomplish:

  1 from django.db import models
  2
  3 class Category(models.Model):
  4 name = models.CharField(maxlength=255)
  5 def __str__(self):
  6 return self.name
  7 class Admin: pass
  8
  9 class Listing(models.Model):
 10 name = models.CharField(maxlength=255)
 11 def __str__(self):
 12 return self.name
 13 class Admin: pass
 14
 15 class Location(models.Model):
 16 name = models.CharField(maxlength=255,core=True)
 17 listing = models.ForeignKey(Listing,
edit_inline=models.STACKED, num_in_admin=1)
 18 categories = models.ManyToManyField(Category, blank=True,
null=True)
 19 def __str__(self):
 20 return self.name
 21 class Meta:
 22 ordering = ['listing','id']

Now I have no problem using this model at all from the command line.
However, when I try to save a Listing and Location (the inline FK) with
the categories (M2MField) left BLANK, I get an empty SQL IN () clause
in my error on the POST:

Exception Value:ERROR: syntax error at or near ")" at character 113
SELECT "vendor_category"."id","vendor_category"."name" FROM
"vendor_category" WHERE ("vendor_category"."id" IN ())

The data is saved fine and I can refresh the page with a GET that
returns proper page. If a value is selected for the categories
(M2MField), then this does not occur.

I had this working in a previous revision of Django 0.95, but it broke
when I updated the revision I'm using.

Any ideas?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: contrib comment system

2006-10-03 Thread Rob Hudson

I just worked on this last night.  Actually, I copied the comments
system to my project app folder and hacked it apart to support what I
wanted it to do.  I did that thinking that I'd leave the upgrade path
open.  Plus, I learned a lot about how comments work.

I found this wiki page a good resource:
http://code.djangoproject.com/wiki/UsingFreeComment

As well as the code to the Django website:
http://code.djangoproject.com/browser/djangoproject.com/django_website/templates/comments

-Rob


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: menu submenu system

2006-10-03 Thread Rob Hudson

I did something like this recently on a project.

The way I approached it was to come up with a dataset that represented
the menu at the template level with the various bits I needed to know
in order to open another level, etc.  Something like this:

menu = [
  {'title': title, 'url': url, 'active': active, 'level': level},
  ...
}

In the view you'd query the database using the db api and gather the
data however you need to then build that data structure.  Once built,
add the data structure to the template context so it's available to the
template.  The template then uses the template API to iterate over the
menu list and output the menu.

I'm leaving out a lot of the details but that's a good summary, I think.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



order admin list view

2006-10-03 Thread David S .

The docs say that, "regardless of how many fields are in ordering, the admin
site uses only the first field."  To overcome this, I overrode the default
manager to return a queryset ordered by the fields I want.  It works fine in
code (interactively), but not in the admin view.  Should it?  Is there a
workaround besides implementing the admin interface for this class myself?

Peace,
David S.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Localizing dynamic content through the admin interface

2006-10-03 Thread Dirk Eschler

Am Dienstag, 3. Oktober 2006 19:32 schrieb Steven Armstrong:
> On 10/03/06 19:14, Dirk Eschler wrote:
> > Hello,
> >
> > please let me first point out that i'm new to Django. I have experience
> > with gettext, but only in non-webapp environments.
> >
> > I've read through the i18n doc and am quite impressed about the gettext
> > support. I just wonder how you usually handle dynamic content.
> > Clients/Users often want to localize the content they add right in the
> > admin interface. Are there any hooks in Django that make it easier?
> >
> > The simplest way i see, is to use separate columns for each language
> > (e.g. title_en, title_de) in my models. Is there a better approach?
>
> Not a complete solution, but maybe gets you started.
>
> http://djangoutils.python-hosting.com/wiki/TranslationService

Thank you, looks interesting. I will give it a try...

By the way, it seems that the project has been moved to another location:
http://trac.studioquattro.biz/djangoutils/wiki/TranslationService

Best Regards,
Dirk Eschler

-- 
Dirk Eschler 
http://www.krusader.org

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: contrib comment system

2006-10-03 Thread Waylan Limberg

I was going to point you to the official docs [1], but that says it's
not yet documented. That said, James Bennet did a nice writeup [2]
that should get you going.

[1]: http://www.djangoproject.com/documentation/add_ons/
[2]: http://www.b-list.org/weblog/2006/07/16/django-tips-hacking-freecomment

On 10/3/06, Onno Timmerman <[EMAIL PROTECTED]> wrote:
>
> Is there somewhere some docs on the comment system in the contrib.
>
> Onno
>


-- 

Waylan Limberg
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: contrib comment system

2006-10-03 Thread Adrian Holovaty

On 10/3/06, Onno Timmerman <[EMAIL PROTECTED]> wrote:
> Is there somewhere some docs on the comment system in the contrib.

Hi Onno,

The comment system is undocumented at this point. As such, that means
there's no guarantee it will stay in its current form.

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Re: Cannot get Many to Many Relationship To work - "name" not defined error message

2006-10-03 Thread Waylan Limberg

On 10/3/06, James Bennett <[EMAIL PROTECTED]> wrote:
>
> I think maybe one thing we could do is build up a list of Python
> tutorials and docs that we recommend people work through, either
> before they start playing with Django or as they go.
>

+1

This seems to come up from time to time on the list. Of course, this
page [1] already provides a decent list, but perhaps a list more
specific to the skills needed for Django would be helpful as well.
Although, is there really any difference in the skills needed? Maybe
not.

[1]: http://www.python.org/doc/

-- 

Waylan Limberg
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Localizing dynamic content through the admin interface

2006-10-03 Thread Steven Armstrong

On 10/03/06 19:14, Dirk Eschler wrote:
> Hello,
> 
> please let me first point out that i'm new to Django. I have experience with 
> gettext, but only in non-webapp environments.
> 
> I've read through the i18n doc and am quite impressed about the gettext 
> support. I just wonder how you usually handle dynamic content. Clients/Users 
> often want to localize the content they add right in the admin interface. Are 
> there any hooks in Django that make it easier?
> 
> The simplest way i see, is to use separate columns for each language (e.g. 
> title_en, title_de) in my models. Is there a better approach?

Not a complete solution, but maybe gets you started.

http://djangoutils.python-hosting.com/wiki/TranslationService

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Mile-high view of Django

2006-10-03 Thread Tim Chase

>> http://simon.incutio.com/archive/2005/08/15/request
> 
> For the detail-oriented folks, I also maintain a more in-depth version:
> 
> http://www.b-list.org/weblog/2006/06/13/how-django-processes-request

Yes, these were exactly the sort of thing I was hunting 
for--particularly the detailed process-flow described in the 
second link helps pull together those bits that have been laying 
around disorganized in my head.

Thanks!

-tkc





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Filter types in Admin index view alterable?

2006-10-03 Thread mauiblu

Does anyone know if the filters available for the Admin index interface
can be changed to select lists, for example? Or where these filter
types are actually defined and what options are available?

Thanks!

JIm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Localizing dynamic content through the admin interface

2006-10-03 Thread Dirk Eschler

Hello,

please let me first point out that i'm new to Django. I have experience with 
gettext, but only in non-webapp environments.

I've read through the i18n doc and am quite impressed about the gettext 
support. I just wonder how you usually handle dynamic content. Clients/Users 
often want to localize the content they add right in the admin interface. Are 
there any hooks in Django that make it easier?

The simplest way i see, is to use separate columns for each language (e.g. 
title_en, title_de) in my models. Is there a better approach?

Best Regards,
Dirk Eschler

-- 
Dirk Eschler 
http://www.krusader.org

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



contrib comment system

2006-10-03 Thread Onno Timmerman

Is there somewhere some docs on the comment system in the contrib.

Onno

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Implementing entity relationships that use compound keys in a Django application

2006-10-03 Thread Sam Morris
Hello everyone! I am new to Django and am currently learning how to use
the model API. I am trying to construct a set of models to represent a
number of people (characters in a game), who can be members of one or
more organisations. Each person in an organisation has a rank in that
organisation. My original sketch of how I would do this directly in a
database looks like this:

Person
Organisation
Rank (*organisation, *rank, name)
Membership (*person, *organisation, rank)

Membership.person -> Person
Membership.(organisation + rank) -> Rank

Asterisks denote primary keys; where more than one field has an asterisk
then the primary key is a compound key.

My problem is that Membership.(organisation + rank) is a compound
foreign key, which Django does not support. My current implementation of
the relationship uses a linkage model:

class OrgMembership (models.Model):
person = models.ForeignKey (person)
organisation = models.ForeignKey (Organisation)
rank = models.ForeignKey (Rank)

class Meta:
unique_together = [['person', 'organisation']]

This allows OrgMembership.rank to be set to any possible rank, but I
only want to allow OrgMemberships where Rank.organisation ==
OrgMembership.organisation.

The solutions I have come up with so far are:

  * Forget the relationship between Membership.rank and Rank -- turn
OrgMembership.rank into a simple integer
  * Create a database constraint to enforce the restriction, and
somehow alter the admin page to only allow legal values (using
limit_choices_to?)
  * Give the OrgMembership model a custom validation rule
(presumably complemented by a manually-created database
constraint)
  * Decompose the relationship somehow

By 'decompose' I mean changing the schema to something like this:

Rank (level, name)
OrgRank (organisation, rank)
OrgMembership (person, org_rank)

The final option is probably the best one, but I thought I would post
anyway to see if any more experienced users could confirm/deny, and to
see if there are any other approaches that I have missed.

-- 
Sam Morris
http://robots.org.uk/

PGP key id 1024D/5EA01078
3412 EA18 1277 354B 991B  C869 B219 7FDB 5EA0 1078


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


Re: Re: Mile-high view of Django (was "Re: Cannot get Many to Many Relationship To work...")

2006-10-03 Thread James Bennett

On 10/3/06, Guillermo Fernandez Castellanos
<[EMAIL PROTECTED]> wrote:
> This might help:
> http://simon.incutio.com/archive/2005/08/15/request

For the detail-oriented folks, I also maintain a more in-depth version:

http://www.b-list.org/weblog/2006/06/13/how-django-processes-request

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Mile-high view of Django (was "Re: Cannot get Many to Many Relationship To work...")

2006-10-03 Thread Guillermo Fernandez Castellanos

Hi,

This might help:
http://simon.incutio.com/archive/2005/08/15/request

Enjoy,

G

On 10/3/06, Tim Chase <[EMAIL PROTECTED]> wrote:
>
> >> Jay,  I did read the documentation before jumping in - but
> >> it's not all necessarily clear for someone who hasn't alot
> >> of experience in Python of Django.
>
> Are there any good resources where one can find the mile-high
> overview of Django's inner workings?  An "executive summary", if
> you will.  Some place where one can get a feel for how templates,
> manipulators, object-models, ORM, server interface (whether
> self-run or attached via mod_python/fastcgi), etc all tie together.
>
> I keep learning little bits here and there as I encounter them,
> but am having trouble fitting all the pieces together into a
> cohesive big-picture.  Like the person to whose post I'm
> responding, I can read the docs, but extracting the big-picutre
> (which in turn would help in knowing where to look in the docs)
> can be tough.
>
> Thanks,
>
> -tkc
>
>
>
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Mile-high view of Django (was "Re: Cannot get Many to Many Relationship To work...")

2006-10-03 Thread MerMer



> I keep learning little bits here and there as I encounter them,
> but am having trouble fitting all the pieces together into a
> cohesive big-picture.  Like the person to whose post I'm
> responding, I can read the docs, but extracting the big-picutre
> (which in turn would help in knowing where to look in the docs)
> can be tough.
>

Thats' interesting to hear.  As a newbie I'm having a different
experience.  I think the documentation, as a whole, does an excellent
job at giving the bigger picture (though I can see the argument for an
shorter, white document to save).

Where I'm constantly coming unstuck is on the detail.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Mile-high view of Django (was "Re: Cannot get Many to Many Relationship To work...")

2006-10-03 Thread Tim Chase

>> Jay,  I did read the documentation before jumping in - but 
>> it's not all necessarily clear for someone who hasn't alot
>> of experience in Python of Django.

Are there any good resources where one can find the mile-high
overview of Django's inner workings?  An "executive summary", if
you will.  Some place where one can get a feel for how templates,
manipulators, object-models, ORM, server interface (whether
self-run or attached via mod_python/fastcgi), etc all tie together.

I keep learning little bits here and there as I encounter them,
but am having trouble fitting all the pieces together into a
cohesive big-picture.  Like the person to whose post I'm
responding, I can read the docs, but extracting the big-picutre
(which in turn would help in knowing where to look in the docs)
can be tough.

Thanks,

-tkc





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Re: Cannot get Many to Many Relationship To work - "name" not defined error message

2006-10-03 Thread James Bennett

On 10/3/06, MerMer <[EMAIL PROTECTED]> wrote:
> Jay,  I did read the documentation before jumping in - but it's not all
> necessarily clear for someone who hasn't alot of experience in Python
> of Django.

This is a tough problem to deal with, though; at some point we have to
be able to assume a certain level of familiarity with Python or
there's no way we can effectively document Django; we'll spend more
time documenting Python, which would be duplication of the already
pretty-darn-good official Python documentation.

I think maybe one thing we could do is build up a list of Python
tutorials and docs that we recommend people work through, either
before they start playing with Django or as they go.

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Sample code for progress bar using patch 2070?

2006-10-03 Thread jacobm

I'm getting desperate and I don't have as much free time to spend on
this as I'd like.  Is anyone willing to share a sample upload app using
the ajax component in exchange for a paypal donation?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Cannot get Many to Many Relationship To work - "name" not defined error message

2006-10-03 Thread MerMer

Jay,  I did read the documentation before jumping in - but it's not all
necessarily clear for someone who hasn't alot of experience in Python
of Django.

Because of my unfamiliarity I had presumed that all the classes in a
single Models.py were immediately visible to each other.   There is
nothing specific in the link you provided to make this explicit in
relation to a ManyToMany relationship.   However, having read Rajesh's
link I can now see that there is a good example of using a string and
that gives a strong hint.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Unicode and django/db/backends/util.py

2006-10-03 Thread Beau Hartshorne

On database updates, utf-8 strings like ’ raise an UnicodeDecodeError  
exception on line 19 of util.py (version 0.9.5). I can get around  
this by commenting out this code in util.py, but is there something  
else I could do?

self.db.queries.append({
 'sql': sql % tuple(params),
 'time': "%.3f" % (stop - start),
})

Thanks,
Beau


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Cannot get Many to Many Relationship To work - "name" not defined error message

2006-10-03 Thread Jay Parlar

On 10/4/06, MerMer <[EMAIL PROTECTED]> wrote:
>
> Thanks Jay and Rajesh,
>
> I've  just discovered this myself by switching the code around.  This
> is a real GOTCHA and not immediately obvious for a newbie like me.  I
> can't see anything in the documentation that mentions this - so I
> presumed it was a bug.

Well, it's a Python thing, really. To use a class, that class has to be defined.

And it *is* in the Django documentation:

http://www.djangoproject.com/documentation/model_api/#many-to-many-relationships

"...and you can refer to as-yet undefined models by using a string
containing the model name."

The Django documentation tends to deal more with the case of reading
it before you dive in, as opposed to using it to debug tracebacks.

Jay P.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Cannot get Many to Many Relationship To work - "name" not defined error message

2006-10-03 Thread RajeshD

Just for posterity, I would like to say that this is indeed mentioned
in the documentation here:

http://www.djangoproject.com/documentation/model_api/#many-to-one-relationships

Excerpt: "If you need to create a relationship on a model that has not
yet been defined, you can use the name of the model, rather than the
model object itself:"


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Cannot get Many to Many Relationship To work - "name" not defined error message

2006-10-03 Thread MerMer

Thanks Jay and Rajesh,

I've  just discovered this myself by switching the code around.  This
is a real GOTCHA and not immediately obvious for a newbie like me.  I
can't see anything in the documentation that mentions this - so I
presumed it was a bug.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: unique objects in list

2006-10-03 Thread Grigory Fateyev

Hello James Bennett!
On Tue, 3 Oct 2006 08:28:02 -0500 you wrote:

> 
> On 10/3/06, Grigory Fateyev <[EMAIL PROTECTED]> wrote:
> > I have a list of ip in table, but this ip repeats many times. I
> > need to show each ip only once with some statistic. How to do this?
> 
> http://www.djangoproject.com/documentation/db_api/#distinct

I don't get it, Blog.objects.all().distinct() is't working like sql
query: select distinct column from blog;?

-- 
÷ÓÅÇÏ ÎÁÉÌÕÞÛÅÇÏ! çÒÉÇÏÒÉÊ
greg [at] anastasia [dot] ru
ðÉÓØÍÏ ÏÔÐÒÁ×ÌÅÎÏ: 2006/10/03 18:19

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: unique objects in list

2006-10-03 Thread RajeshD


> I have a list of ip in table, but this ip repeats many times. I
> need to show each ip only once with some statistic.

You will need some custom SQL to take care of the "statistics" you need
for each distinct IP address. From what I understand of your problem,
you need the result set from a statement like this:

select ip, count(*)
from your_table
group by ip

See this doc for info on how to run such a custom SQL and fetch its
resulting rows:
http://www.djangoproject.com/documentation/model_api/#executing-custom-sql


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Cannot get Many to Many Relationship To work - "name" not defined error message

2006-10-03 Thread Jay Parlar

On 10/4/06, MerMer <[EMAIL PROTECTED]> wrote:
>
> .
> I am trying to create a many to many relationship between two classes
> (Promotion and Category).
>
> When I add "categories = models.ManyToManyField(Category)" to the
> Promotion class I get an errror saying "Category is not defined".
>
> However, when  I add "promotions = models.ManyToManyField(Promotion)"
> to the Category Class it works fine!
>
> This is driving me crazy, as a newbie it's not easy to diagnose where
> the problem lies.  I've been very impressed with the documentation,
> review etc of Django - but after 24 hours of not getting too far, I'm
> getting rather frustrated.
>
> MerMer
>
>
> from django.db import models
> import datetime
>
> class Promotion (models.Model):
> promo_headline = models.CharField(maxlength=400, core=True)
> promo_sbody = models.TextField(help_text="This is for a short
> description about the offer")
> promo_lbody = models.TextField(help_text="This if sfor a long
> description about the offer")
> pub_date = models.DateTimeField()
> categories = models.ManyToManyField(Category)
> start_date = models.DateTimeField(core=True)
> expiry_date = models.DateTimeField()
> promoter_name = models.ForeignKey(Promoter,
> edit_inline=models.TABULAR)
> is_multi_takeup = models.BooleanField(help_text="Tick if the offer
> can be taken up by the same person more than once")
> takeup_url = models.URLField(help_text="URL where the offer will be
> taken up")
> question_email = models.EmailField(core=True, help_text="where
> questions about this offer will be sent")
> terms_conditions = models.TextField(core=True)
> def __str__(self):
> return self.promo_headline
>
> class Category (models.Model):
> category_name = models.CharField(maxlength=400)
> def __str__(self):
> return self.category_name
> class Admin:
> pass
>

The reason the first was didn't work, but the second did, is because
of order in the file. A model has to already be declared before you
can make reference to it. So when you wrote

categories = models.ManyToManyField(Category)

in the Promotion class, you get an error because 'Category' is not
defined yet. The simple solution is to put your Promotion class
*after* the Category class.

Jay P.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Cannot get Many to Many Relationship To work - "name" not defined error message

2006-10-03 Thread RajeshD

You are seeing that error because Category is defined after Promotion
in your model file. In such cases, you can use string lookup instead a
class lookup, like this:

categories = models.ManyToManyField('Category')

Note the Category in quotes instead of without quotes.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: DRY in templates

2006-10-03 Thread Slowness Chen

1. refactor the blocks you want into separate templates , do something
like {%include 'block1.html'%} , {%include 'block2.html'%}. I guess
this is what you want.
or
2. "You can use as many levels of inheritance as needed."

Luis P. Mendes wrote:
> Hi,
>
> I have several applications running and each of them has its own
> template files.  They're working fine.
>
> Then, I decided that I should create another application that would
> merge all data information from each of those separated ones mentioned
> above.
>
> There were two problems to consider:
> 1- regarding data and views
> 2- regarding templates
>
> As for 1, I found a way that follows the DRY principle.  For each
> function that would be requested I joined another field as an argument.
> From: ex:  def viewListA(request):
> To:def viewListA(request, integrated = False):
> Integrated is True when the request is demanded by the global application.
> If Integrated == False, the function returns the html file corresponding
> to it; if True, it returns 'request'.
>
> So far, so good.
>
> Now, for part nr. 2.
>
> I didn't find a way not to repeat the same lines of the partial html
> files in a big global html one, for the application that merges all
> information.  My concern is only about data information that is
> presented mostly in tables.
>
> I am aware of the {% extends ... %} tag, but it can only be used once
> per file.  Otherwise, I could use that tag for each of the partial
> templates and would import the data blocks of each of them.
>
> My question is this one:  Is there a way I don't have to repeat the same
> template coding for the above illustrated example?
> 
> Luis P. Mendes


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Cannot get Many to Many Relationship To work - "name" not defined error message

2006-10-03 Thread MerMer

.
I am trying to create a many to many relationship between two classes
(Promotion and Category).

When I add "categories = models.ManyToManyField(Category)" to the
Promotion class I get an errror saying "Category is not defined".

However, when  I add "promotions = models.ManyToManyField(Promotion)"
to the Category Class it works fine!

This is driving me crazy, as a newbie it's not easy to diagnose where
the problem lies.  I've been very impressed with the documentation,
review etc of Django - but after 24 hours of not getting too far, I'm
getting rather frustrated.

MerMer


from django.db import models
import datetime

class Promotion (models.Model):
promo_headline = models.CharField(maxlength=400, core=True)
promo_sbody = models.TextField(help_text="This is for a short
description about the offer")
promo_lbody = models.TextField(help_text="This if sfor a long
description about the offer")
pub_date = models.DateTimeField()
categories = models.ManyToManyField(Category)
start_date = models.DateTimeField(core=True)
expiry_date = models.DateTimeField()
promoter_name = models.ForeignKey(Promoter,
edit_inline=models.TABULAR)
is_multi_takeup = models.BooleanField(help_text="Tick if the offer
can be taken up by the same person more than once")
takeup_url = models.URLField(help_text="URL where the offer will be
taken up")
question_email = models.EmailField(core=True, help_text="where
questions about this offer will be sent")
terms_conditions = models.TextField(core=True)
def __str__(self):
return self.promo_headline

class Category (models.Model):
category_name = models.CharField(maxlength=400)
def __str__(self):
return self.category_name
class Admin:
pass


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



migration from php and java

2006-10-03 Thread Aljosa Mohorovic

After some time with django i started porting current php/java
applications i use to django.
Please keep in mind that for duration of porting coexistence of
php/java/django is required.
That said, any help with current issue (sharing users, auth. system,
with php and java) is appreciated.

I like admin interface for django and have strong believe i can push
it in company i work for so i would like to transfer current
authorization from php/java to django but enable php/java to
authorize. i noticed that password field starts with sha1$something
and i guess that i could use sha1() in php and MessageDigest in java.

this is my guess for password field format, please correct:
password_field = "sha1$(output of php/java sha1 function)"

any notes on this subject or anything related would be appreciated.
thanks

Aljosa Mohorovic

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: 1-Many Display in the Admin Area .

2006-10-03 Thread MerMer

Alan,

Thanks for helping out - but I'm more confused than ever.  If Django
fields are required by default why use core=True at all?   What do I
enter into the parameter so a field is NOT required.   I tried null =
True and this didn't work (and as an aside it made the red highlights
on the core=true fields disappear!).

edit_inline= models.TABULAR does not work.   Hopefully this explanation
will make it clear.   When I click on a specific Promoter I want to
display a list of all their related promotions.

Prometer Name
---
Promotion Name 1-  Date Published
Promotion Name 2 - Date Published
Promotion Name 3 - Date Published

Then I want to be able to simply click the name to bring up the
underlying record for editing.

At the moment when I click on a promoters name it displays all the
fields and editable regions straightaway. Imagine a  Promotion Table
with 10 text fields and a Promoter hat thas 10 related Promotions. When
I click on that Promoter I currently get a very long list (either
vertically or tabular) because it displays all the records.  Very ugly.
 I have to scroll down (or vertically) a long way to make any changes.

Hope this is clearer.

Cheers

MerMer


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: unique objects in list

2006-10-03 Thread James Bennett

On 10/3/06, Grigory Fateyev <[EMAIL PROTECTED]> wrote:
> I have a list of ip in table, but this ip repeats many times. I
> need to show each ip only once with some statistic. How to do this?

http://www.djangoproject.com/documentation/db_api/#distinct


-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



unique objects in list

2006-10-03 Thread Grigory Fateyev

Hello!

I have a list of ip in table, but this ip repeats many times. I
need to show each ip only once with some statistic. How to do this? In
wich direction I should to look forward? filter, templatetag or
something else? If it possible, share some code for example.

-- 
÷ÓÅÇÏ ÎÁÉÌÕÞÛÅÇÏ! çÒÉÇÏÒÉÊ
greg [at] anastasia [dot] ru
ðÉÓØÍÏ ÏÔÐÒÁ×ÌÅÎÏ: 2006/10/03 17:16

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



DRY in templates

2006-10-03 Thread Luis P. Mendes

Hi,

I have several applications running and each of them has its own
template files.  They're working fine.

Then, I decided that I should create another application that would
merge all data information from each of those separated ones mentioned
above.

There were two problems to consider:
1- regarding data and views
2- regarding templates

As for 1, I found a way that follows the DRY principle.  For each
function that would be requested I joined another field as an argument.
From: ex:  def viewListA(request):
To:def viewListA(request, integrated = False):
Integrated is True when the request is demanded by the global application.
If Integrated == False, the function returns the html file corresponding
to it; if True, it returns 'request'.

So far, so good.

Now, for part nr. 2.

I didn't find a way not to repeat the same lines of the partial html
files in a big global html one, for the application that merges all
information.  My concern is only about data information that is
presented mostly in tables.

I am aware of the {% extends ... %} tag, but it can only be used once
per file.  Otherwise, I could use that tag for each of the partial
templates and would import the data blocks of each of them.

My question is this one:  Is there a way I don't have to repeat the same
template coding for the above illustrated example?

Luis P. Mendes

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Referencing the current URL in a view

2006-10-03 Thread DavidA

I have a number of views where function args (parsed from the URL conf)
and/or query string arguments are used to filter the results that are
displayed in a template. The template includes paging and sorting which
need to use a URL that points back to the view using the same
arguments, but I'm finding the way I'm doing this a little non-elegant.
Here's an example:

A sample url in the browser might look like this:

http://127.0.0.1:8000/data/pos/20060922/dle/?filter=inst__exposure_asset_class:9&page=2

Which maps to this URL conf:

# positions
(r'^pos/(?P\d{8})/(?P.*)/$',
'pfweb.core.views.list_positions'),

And uses this view:

def list_positions(request, date, fund):
positions = Position.objects.filter(
date=date,
account__custodian__portfolio__fund_name=fund)
if request.has_key('filter'):
# account__name:abc,spectrum:123
kwargs = dict([kv.split(':') for kv in
request['filter'].split(',')])
positions = positions.filter(**kwargs)

# HACK post message to django groups to see if there is a better
way...
# get a url suitable for paging by starting with the original
# and stripping off any 'page=' part
nav_base_url = request.META['PATH_INFO'] + '?'
query_string = re.sub(r'[?&]page=\d+', r'',
request.META['QUERY_STRING'])
if query_string:
nav_base_url += query_string + '&'

return object_list(
request,
positions,
paginate_by=30,
extra_context={'nav_base_url':nav_base_url})

Notice that I'm passing back the 'nav_base_url' to the template so I
can setup the previous/next links for paging. I also plan to use that
url for sorting links in column headers.

But its a little nasty. Starting at the HACK comment you can see that
I'm digging into the request meta info to get the url path and query
string, strip off any 'page=nnn' fragment and return a base url that I
can append the 'page=nnn' or 'sort=xxx' in my template, like this:

   {% if has_previous %}
   Prev
   {% endif %}
   {% if has_next %}
   Next
   {% endif %}

It seems this is part of (what I would think would be) a general
problem: building a link in a page back to the same view using the same
args, but optionally adding or replacing certain fields within that
url.

Does anyone see a cleaner, more elegant way to solve this without
manually parsing and building a query string? I'm worried that as this
gets more complex, there will be all sorts of bugs with issues like
getting the '?' and '&' in the right place.

Thanks in advance,
-Dave


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: 1-Many Display in the Admin Area .

2006-10-03 Thread Alan Johnson
1.  The objects are being displayed in the Admin area as "Promoters"
and "Promotionss" - note the added "s".In
Django it's convention to name models as singular nouns, not as plural
nouns. Change Promotions to Promotion and you'll get what you're
expecting.
 2.  I have added a core=True parameter to one of the fields in the
Class Promtions.  However, when I try to add a record via Admin I get
messages asking for every field to be completed.I experienced thesame when I went through the tutorial with the Poll/Choices example.  Iunderstood that core=True only operates on a specific field rather than
a whole record.  If this is true, where am I going wrong?In Django, fields are required by default (null = False on the field by default). Per the documentation at 

http://www.djangoproject.com/documentation/model_api/#core, all required fields should have core set to true. 

Finally,  I would like to click on a Promoter in the Admin area and seea list (rather than the complete record) of all their Promotions, in acollapsed view.  The Promotions table has alot of fields and I've tried

using the edit_inline parameter.  However, when I do this I get thePromoter records at the top and then the complete record of eachpromotions, instead of a simple list of each record.
I'm not totally sure that I understand you here, but I think what you want is edit_inline=
models.TABULAR. Hopefully that helps,Alan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django users" group.  To post to this group, send email to django-users@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/django-users  -~--~~~~--~~--~--~---


1-Many Display in the Admin Area .

2006-10-03 Thread MerMer

As a newbie I'm struggling to get to grips with Django's admin
interface.   I have created two tables (Promoter, Promotions) which
have a straight forward 1-Many relationship.

A couple of unexplained issues:-

1.  The objects are being displayed in the Admin area as "Promoters"
and "Promotionss" - note the added "s".

2.  I have added a core=True parameter to one of the fields in the
Class Promtions.  However, when I try to add a record via Admin I get
messages asking for every field to be completed.I experienced the
same when I went through the tutorial with the Poll/Choices example.  I
understood that core=True only operates on a specific field rather than
a whole record.  If this is true, where am I going wrong?

Finally,  I would like to click on a Promoter in the Admin area and see
a list (rather than the complete record) of all their Promotions, in a
collapsed view.  The Promotions table has alot of fields and I've tried
using the edit_inline parameter.  However, when I do this I get the
Promoter records at the top and then the complete record of each
promotions, instead of a simple list of each record.

Currently, this makes the system ugly and unusable for me as an Admin
function.

MerMer


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: How to join 2 QuerySets? (with QuerySet object in result)

2006-10-03 Thread Laundro

I'm at work now, but have a look at Q().


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Help with related objects

2006-10-03 Thread Carlos Yoder
Just FYI, I cracked it myself.Me gets smarter! =)If anyone googles for this and is in a similar situation, pls let me know.On 10/3/06, Carlos Yoder
 <[EMAIL PROTECTED]> wrote:
Hello all, I'm asking for help again, this time with related objects.I need to do what I think is a very simple task: allow users to edit their own preferences (using a custom 'admin' like interface).Their own preferences are located in an extension of the User model, as follows:
class UserProfile(models.Model):    user = models.ForeignKey (User, core=True, edit_inline=False, max_num_in_admin=1, min_num_in_admin=1, num_in_admin=1, num_extra_on_change=0, unique=True)    receive_new_cars_newsletter = 
models.BooleanField("Subscribed to daily 'new cars' newsletter?", null=False, blank=False, default=True)    receive_modif_cars_newsletter = models.BooleanField("Subscribed to daily 'new cars' newsletter?", null=False, blank=False, default=True)
        def __str__(self):        return ("%s" % self.user)    When users are created by the superadmin (via the normal Admin interface), these related fields are not populated, naturally. So, I'd have to present the users with default values for receive_new_cars_newsletter and receive_modif_cars_newsletter (only a checkbox, as it is), and allow them to set their values.
This is an excruciatingly easy thing to do, but still I can't find my way around generic views, forms, manipulators, related objects, the undocumented 'follow' and the rest of the pie. It's -of course- the first time I tackle this, so I want to do things right, but I'm honestly running out of time. 
I wanted to have a special URL such as /my_data/, that would display
the change form (the proper object_id being inferred from
request.user). That's why  I couldn't do it with generic views.
Could anyone point me into the right place (admin sources is OK) to have a look and borrow what's needed for this?BTW, everything works as expected from the shell, the interface is what I'm not getting. 

Thanks a million, and best regards-- Carlos Yoderhttp://carlitosyoder.blogspot.com


-- Carlos Yoderhttp://blog.argentinaslovenia.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django users" group.  To post to this group, send email to django-users@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/django-users  -~--~~~~--~~--~--~---


Re: shared model relationship question

2006-10-03 Thread Malcolm Tredinnick

On Tue, 2006-10-03 at 18:49 +1000, Benjamin Ward wrote:
> 
> Im very new to this so please forgive if this is an obvious question:
> 
> How do you describe these relationships in a model in Django:
> 
> 1)
> UserProfile extends User. UserProfile has_a Address. Event has_a  
> Address.
> 
> Where Address has a common data-structure shared by Event and  
> UserProfile, but each instance of Address would be unique to it's  
> parent.

If the uniqueness goes both ways, a OneToOneField is what you want. If
only one end is unique (a UserProfile has a single address, but an
address can be shared by many UserProfile instances), a ForeignKey field
on the UserProfile class does the trick. A ForeignKey field is a
one-to-many relationship.

> 2)
> Event can_have_many Tag. Blog can_have_many Tag. Story can_have_many  
> Tags. Product can_have_many Tag.
> 
> Where Tag is a common data-structure that could be used to create a  
> taxonomy of the different models allowing you to group them by their  
> common Tag(s).

Django has a ManyToManyField.

All of these fields (OneToOneField, ManyToManyField and ForeignKey) are
documented at
http://www.djangoproject.com/documentation/model_api/#relationships .

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



shared model relationship question

2006-10-03 Thread Benjamin Ward


Im very new to this so please forgive if this is an obvious question:

How do you describe these relationships in a model in Django:

1)
UserProfile extends User. UserProfile has_a Address. Event has_a  
Address.

Where Address has a common data-structure shared by Event and  
UserProfile, but each instance of Address would be unique to it's  
parent.

2)
Event can_have_many Tag. Blog can_have_many Tag. Story can_have_many  
Tags. Product can_have_many Tag.

Where Tag is a common data-structure that could be used to create a  
taxonomy of the different models allowing you to group them by their  
common Tag(s).



Thanks in advance you lovely people :)


Ben

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Help with related objects

2006-10-03 Thread Carlos Yoder
Hello all, I'm asking for help again, this time with related objects.I need to do what I think is a very simple task: allow users to edit their own preferences (using a custom 'admin' like interface).Their own preferences are located in an extension of the User model, as follows:
class UserProfile(models.Model):    user = models.ForeignKey (User, core=True, edit_inline=False, max_num_in_admin=1, min_num_in_admin=1, num_in_admin=1, num_extra_on_change=0, unique=True)    receive_new_cars_newsletter = 
models.BooleanField("Subscribed to daily 'new cars' newsletter?", null=False, blank=False, default=True)    receive_modif_cars_newsletter = models.BooleanField("Subscribed to daily 'new cars' newsletter?", null=False, blank=False, default=True)
        def __str__(self):        return ("%s" % self.user)    When users are created by the superadmin (via the normal Admin interface), these related fields are not populated, naturally. So, I'd have to present the users with default values for receive_new_cars_newsletter and receive_modif_cars_newsletter (only a checkbox, as it is), and allow them to set their values.
This is an excruciatingly easy thing to do, but still I can't find my way around generic views, forms, manipulators, related objects, the undocumented 'follow' and the rest of the pie. It's -of course- the first time I tackle this, so I want to do things right, but I'm honestly running out of time. 
I wanted to have a special URL such as /my_data/, that would display
the change form (the proper object_id being inferred from
request.user). That's why  I couldn't do it with generic views.
Could anyone point me into the right place (admin sources is OK) to have a look and borrow what's needed for this?BTW, everything works as expected from the shell, the interface is what I'm not getting. 
Thanks a million, and best regards-- Carlos Yoderhttp://carlitosyoder.blogspot.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django users" group.  To post to this group, send email to django-users@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/django-users  -~--~~~~--~~--~--~---


Re: Importing models from each other.

2006-10-03 Thread Gacha

I separated the models. Now I have myproj.extra which contains the
Choice model and all works fine :)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



menu submenu system

2006-10-03 Thread Onno Timmerman

I was wondering how you handle in Django a menu system with submenu's.

For example I give my client the ability to make there own menu's.
level1
level1
level2
level2
level3
level3  
level2
level1
...
...
...


In the database I used table like "id, idSub, menu" and made a class in 
PHP to process the data and order the submenu's in an array and then put 
them where needed in a SELECT or UL list. I wonder how this is done with 
Django.

Thanxs
PS. I'm still a bit confused about frameworks.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---