Re: Solution to multiple models on one form?

2007-05-23 Thread Michael Radziej

On Sun, May 20, David Priest wrote:

> 
> After bashing at it some more, I had to conclude I was out to lunch.
> 
> It is killing me to wait for newforms.  It's senseless for me to  
> learn old forms, but I'm having a helluva time making heads or tails  
> of newforms.  Some things that I swear must be common as mud -- like  
> a form that sends to several tables (ye olde address vs purchase  
> order scenario) -- seems far, far too difficult.

The problem is not that it's about several tables, but that you have
multiple records (of unknown quantity) for one of the tables. (Or did I get
something wrong?)

This particular quest--a form that sends to several tables, with a
master-detail relationship--is pretty hard and barely documented with
oldforms, either ;-)

> I think I'll just hardcode it all, and deal with improving it when  
> newforms is better documented.

Good luck. When you have multiple "detail" records in your view, it's far
from trivial. I can only reiterate Malcolm's advice.

Michael


-- 
noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg -
Tel +49-911-9352-0 - Fax +49-911-9352-100
http://www.noris.de - The IT-Outsourcing Company
 
Vorstand: Ingo Kraupa (Vorsitzender), Joachim Astel, Hansjochen Klenk - 
Vorsitzender des Aufsichtsrats: Stefan Schnabel - AG Nürnberg HRB 17689

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



Admin page without formatting and looks

2007-05-23 Thread [EMAIL PROTECTED]

i have installed apache2 and django 0.96 with mysql. i have a small
application installed with this setup. now when i start admin page it
shows plain page without any look and feel. i can see it with django
internal server. i read previous article on it and made some changes
but still does not work.  other things are working just fine. my
configuration is as follows:

lines added in httpd.conf file

Alias /media/ "/usr/local/lib/python2.5/site-packages/django/contrib/
admin/media/"


Order Deny,Allow
Allow from all


remaining is same

settings.py and urls.py is set according to django official guide as
things are working with django internal server

access_log shows
127.0.0.1 - - [23/May/2007:07:09:55 -0500] "GET /admin HTTP/1.1" 301
- this line appears only once when i make some change in
httpd.conf
127.0.0.1 - - [23/May/2007:07:09:55 -0500] "GET /admin/ HTTP/1.1" 200
1620
127.0.0.1 - - [23/May/2007:07:09:56 -0500] "GET /media/css/login.css
HTTP/1.1" 404 2647

yes one more thing i would like to add is previous http status code
was of access denied  unauthorized access 401 before i made above
changes to httpd.conf. if it was unauthorized then how come it went
missing after these changes and if i comment above changes it still
shows 404 instead of 401.


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




Re: Displaying data in the admin using list_display

2007-05-23 Thread Greg

Malcolm,
So how do I call a method in my list_display?  Here is my models file

class Manufacturer(models.Model):
name = models.CharField(maxlength=200)
manufacturerslug = models.SlugField(prepopulate_from=["name"])
description = models.TextField(maxlength=1000)

def __str__(self,):
return self.name

class Admin:
pass

class Collection(models.Model):
name = models.CharField(maxlength=200)
collectionslug = models.SlugField(prepopulate_from=["name"])
description = models.TextField(maxlength=1000)
manufacturer = models.ForeignKey(Manufacturer)

def __str__(self,):
return self.name

class Admin:
pass

class Style(models.Model):
name = models.CharField(maxlength=200)
theslug = models.SlugField(prepopulate_from=('name',))
collection = models.ForeignKey(Collection)


class Admin:
search_fields = ['name']
list_display = ('name', 'theslug','collection', rmanu())

def __str__(self,):
return self.name

def rmanu(self,):
return self.collection.manufacturer




Here is what I get when I try to call the method in a python shell

>>> from mysite.rugs.models import Style
>>> s = Style.objects.filter(id=1)
>>> s
[]
>>> s.rmanu()
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'QuerySet' object has no attribute 'rmanu'
>>>

I thought that was how I call a method?

Thanks




On May 23, 5:14 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Wed, 2007-05-23 at 14:33 -0700, Greg wrote:
> > I'm having a problem displaying data in my admin using list_display.
> > I want to be able to show the Manufacturer in the admin from my styles
> > page.  Here are my models:
>
> > class Manufacturer(models.Model):
> >name = models.CharField(maxlength=200)
> >manufacturerslug = models.SlugField(prepopulate_from=["name"])
> >description = models.TextField(maxlength=1000)
>
> > def __str__(self,):
> >return self.name
>
> >class Admin:
> >pass
>
> > class Collection(models.Model):
> >name = models.CharField(maxlength=200)
> >collectionslug = models.SlugField(prepopulate_from=["name"])
> >description = models.TextField(maxlength=1000)
> >manufacturer = models.ForeignKey(Manufacturer)
>
> >def __str__(self,):
> >return self.name
>
> >class Admin:
> >pass
>
> > class Style(models.Model):
> > name = models.CharField(maxlength=200)
> > theslug = models.SlugField(prepopulate_from=('name',))
> > collection = models.ForeignKey(Collection)
>
> > class Admin:
> >search_fields = ['name']
> >list_display = ('name', 'theslug','collection',
> > 'collection.manufacturer')
>
> > def __str__(self,):
> >return self.name
>
> > When I view my style table in the admin I want to be able to display
> > the manufacturer.  However, I don't have a manufacturer field in the
> > Style table.  All I have is a foreign key to collection, which
> > contains a foreignkey to manufacturer.  I have no problem displaying
> > the collection that the style is associated with.  I want to be able
> > to show the manufacturer of the style in the admin.
>
> > I currently do "list_display = ('name', 'theslug', 'collection',
> > 'collection.manufacturer')" However it errors when
> > 'collection.manufacurer'.  Is it possible for me to show the
> > Manufacturer of the style in the admin?
>
> Doing list_display lookups across models like this doesn't work, as
> you've discovered. One day we might even fix that, because it's about a
> four line change to fix.
>
> For the time being, the simplest solution is to create a method that
> returns collection.manufacturer and use that method name in the
> list_display list. You can even make this field sortable using the
> admin_order_field attribute on the function (search the model-api docs
> for more information), I suspect.
>
> Regards,
> Malcolm- Hide quoted text -
>
> - Show quoted text -


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



Re: NEWBIE: joining two tables problem

2007-05-23 Thread [EMAIL PROTECTED]

The second method would probably have worked if you had put:

 {% for photo in emp.photo_set.all %} instead of  {% for photo in
emp.photo_set %}

I always forget the .all at first ;) and have to go back and add it.

On May 23, 3:13 pm, Rogelio <[EMAIL PROTECTED]> wrote:
> On May 23, 3:10 pm, Rogelio <[EMAIL PROTECTED]> wrote:
>
> > Thank you so much!  I was able to get your first method to work.  The
> > second method
> > seemed to be complaining that I was using a for-loop on an empty
> > "photo_set".
> > I'll play around it some more.
>
> > Rogelio
>
> Sorry for the multiple "thanks" -- on my end I was getting a message
> that there
> was an error posting the reply and I should try again later -- which I
> did several
> times.  I guess there was no error after all.


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



Re: conditional block tag

2007-05-23 Thread David Robinson

I'm probably missing something about your question, and please excuse me 
if that's the case, but wouldn't you be able to do this:

{% if header %}

   {% block header %}Page Heading{% endblock %}

{% endif %}

Dave



Trey wrote:
> I have an interesting case that I would like to get some input on,
> perhaps I am just thinking about it incorrectly.
> 
> It seems useful to have a conditional statement which will check to
> see if a child template has populated a block.
> 
>   
> {% block header %}Page Heading{% endblock %}
>   
> 
> If the block header wasn't sent back, I would like to collapse the
> header field. Does this seem like something useful or am I going about
> it the wrong way?

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



Re: user object in templates

2007-05-23 Thread Ben Jones

> it seems like I have no user object in my templates, which is weird,
> as it comes w/ my request object, and I can access it in my views. In
> other words, request.user.is_authenticated evaluates to True in my
> views, but to False in my templates.

See this thread:

http://groups.google.com/group/django-users/browse_thread/thread/84c15332671e02f8?hl=en

I suspect that your missing user object is because of the same reasons
that {{ perms }} was empty in thread above.

--
-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?hl=en
-~--~~~~--~~--~--~---



conditional block tag

2007-05-23 Thread Trey

I have an interesting case that I would like to get some input on,
perhaps I am just thinking about it incorrectly.

It seems useful to have a conditional statement which will check to
see if a child template has populated a block.

  
{% block header %}Page Heading{% endblock %}
  

If the block header wasn't sent back, I would like to collapse the
header field. Does this seem like something useful or am I going about
it the wrong way?


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



Re: Best Place To Start Learning Django/Python

2007-05-23 Thread Doug Van Horn

It's probably a little bit more advanced, and it's certainly not a
tutorial, but the Python Challenge (http://www.pythonchallenge.com/)
is a good way to get familiar with the language and its tools.

I think I made it through 17 or so when I was first learning Python.


doug.


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



Re: {{ perms }} seems to be empty

2007-05-23 Thread Michael Lake

Jeremy Dunck wrote:
> On 5/23/07, Michael Lake <[EMAIL PROTECTED]> wrote:
>>I notice it's a Set object comprising a single list. So I thought I could do 
>>this:
>>
>>{% for item in perms.lab %}
>>{{ item }}
>>{% endfor %}
> 
> 
> Yeah, you can't do attribute access like that for a set.  It's not the
> same as a dictionary.
> I guess you're looking for any permissions that are for the 'lab' app?

Oh I'll probably just be doing stuff like:

{% if perms.lab.add_experiment %}
< a href="something">Click to add experiment.
{% endif %}
{% if perms.lab.delete_experiment %}
< a href="something">Click to delete experiment.
{% endif %}
{% if perms.lab.change_experiment %}
< a href="something">Click to edit experiment.
{% endif %}

Also I should ask:
return render_to_response('lab/user.html', data)

was replaced with:
ctx = RequestContext(request,data)
return render_to_response('lab/user.html', context_instance=ctx)

But why? What's happening in the later case so why did this fix my problem.
I suppose I'm asking for an explanation of the magic under the carpet when I'm 
not 
even a magicians apprentice and will have problems understanding the answer :-)

Mike
-- 
Michael Lake




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



Re: {{ perms }} seems to be empty

2007-05-23 Thread Jeremy Dunck

On 5/23/07, Michael Lake <[EMAIL PROTECTED]> wrote:
...
> I notice it's a Set object comprising a single list. So I thought I could do 
> this:
>
> {% for item in perms.lab %}
> {{ item }}
> {% endfor %}

Yeah, you can't do attribute access like that for a set.  It's not the
same as a dictionary.

I guess you're looking for any permissions that are for the 'lab' app?

Consider moving this into the view or writing a template tag-- There's
not an easy way to do str.startswith in a template, which is what
you'd need here.

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



Re: {{ perms }} seems to be empty

2007-05-23 Thread Michael Lake

Jeremy Dunck wrote:
> Should be:
> 
> from django.template import RequestContext
> ctx = RequestContext(request, data)
> return render_to_response('lab/user.html', context_instance=ctx)

Ah ha :-) Now it works and I get...

perms={% if perms.lab %}
  yes perms {{ perms.lab }}
{% else %}
  no perms
{% endif %}

Now gives...

perms= yes perms
Set(['lab.change_test', 'lab.add_test', 'lab.add_experiment', 
'lab.delete_experiment', 'lab.delete_test', 'lab.change_experiment'])

Thanks Jeremy, Martin & Aidas for your help.

I notice it's a Set object comprising a single list. So I thought I could do 
this:

{% for item in perms.lab %}
{{ item }}
{% endfor %}

But the above just seems to hand the browser and waits and waits...


Mike
-- 
Michael Lake




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



Re: {{ perms }} seems to be empty

2007-05-23 Thread Jeremy Dunck

Arg!

This:

> from django.template import RequestContext
> ctx = RequestContext(request)
> return render_to_response('lab/user.html', context_instance=ctx)

Should be:

from django.template import RequestContext
ctx = RequestContext(request, data)
return render_to_response('lab/user.html', context_instance=ctx)

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



Re: {{ perms }} seems to be empty

2007-05-23 Thread Jeremy Dunck

On 5/23/07, Michael Lake <[EMAIL PROTECTED]> wrote:
...
>  return render_to_response('lab/user.html', data)

Yeah, that's your problem right there.

You want this:

from django.template import RequestContext
ctx = RequestContext(request)
return render_to_response('lab/user.html', context_instance=ctx)

(Style note, you want your imports at the top of the file or callable,
but included just before use here for clarity)

... I imagine this bites a lot of people on the ass.  :(

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



Re: {{ perms }} seems to be empty

2007-05-23 Thread Michael Lake

Hi all

Martin Hsu suggested to make sure that this is included so I now have this in 
settings.py

TEMPLATE_CONTEXT_PROCESSORS=
("django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n")

Still {{ perms }} is empty or at least not displayed.

Jeremy Dunck wrote:
> You must also render the template using RequestContext rather than
> Context in order for TEMPLATE_CONTEXT_PROCESSORS to be run.
> How is 'request' getting into your template context?
> Show us the view. :)

Here is the view:

def user(request):
 ''' Provides information on the currently logged in user. '''

 message = ''

 # This is an object that represents the currently logged-in user.
 # If the user isn't logged in, this will instead be an AnonymousUser object
 user = request.user

 # How to tell if a user is logged in.
 if request.user.is_authenticated():
 # Do something for authenticated users.
 debug = 'User is authenticated.'
 else:
 # Do something for anonymous users.
 debug = 'User is not authenticated.'
 return HttpResponseRedirect("/login/")

 # now user is authenticated, and has name == request.user.username

 message = 'This user '
 if user.has_perm('lab.add_test'):
 message = message + 'can add a lab test.'
 else:
 message = message + 'cannot add any lab tests.'

 if user.is_authenticated():
 permissions = user.get_all_permissions()
 else:
 permissions = ''

 data = {'request': request,
 'user': user,
 # passing through permissions is just for testing.
 # I should just use {{ perms }} in the template
 'permissions': permissions,
 'message': message,
 'debug': debug,
 }

 return render_to_response('lab/user.html', data)


Here is part of the template user.html

Permissions:
{% for permission in permissions %}
 + {{ permission }} 
{% endfor %}


perms={% if perms.lab %}
 yes perms
{% else %}
 no perms
{% endif %}

{{ message }}

-
And here is the output I get:

Permissions:
+ lab.change_test
+ lab.add_test
+ lab.add_experiment
+ lab.delete_experiment
+ lab.delete_test
+ lab.change_experiment
perms= no perms
This user can add a lab test.


I could create a dictionary in the view of all the permission things I'd need 
in a 
template and pass that in but the {{ perms }} seems like it is really what I 
should 
be using as it supposed to be automatically available from the request object.

-- 
Michael Lake




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



Re: Inconsistent SQL generated for ForeignKey fields

2007-05-23 Thread Malcolm Tredinnick

On Wed, 2007-05-23 at 16:29 -0700, Fay wrote:
> Hi,
> 
> 
> I encountered a situation that foreign key constraints were generated
> differently for the same data model.
> 
> Below is my test model that has 2 identical sets of 1-to-many tables.
> When I run django sqlall command, however the foreign key constraints
> were built differently, one used column constraint while the other
> used table constraint. It seems the table names contribute to this
> behavior. Although they function very similarly, I wonder why that
> happened.

The constraint on test_x2 had to be added later because at the time
table test_x2 was created, there was no table test_x1 to reference. When
table test_a2 was created, table test_a1 already existed, so it could
include the constraint inline.

It's not worth doing a topological sort on the table to make sure
everything is a backwards reference (since it's not possible to always
achieve that anyway) as the two ways of specifying the constraint lead
to identical behaviour.

Regards,
Malcolm



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



Re: Best Place To Start Learning Django/Python

2007-05-23 Thread Jeremy Dunck

On 5/23/07, Jeremy Dunck <[EMAIL PROTECTED]> wrote:
> On 5/23/07, Peter Pluta <[EMAIL PROTECTED]> wrote:
> >
> >
> > I don't really have any programming experience outside of hacking up a few
> > lines of php,...

> Working with someone you know that already knows how to code would be
> useful, and, of course, mailing this list is a good start, too.

Oh, and while I think learning to program is a worth-while goal,
perhaps you don't even need to program:
http://www2.jeffcroft.com/blog/2006/may/02/django-non-programmers/

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



Re: Best Place To Start Learning Django/Python

2007-05-23 Thread Jeremy Dunck

On 5/23/07, Peter Pluta <[EMAIL PROTECTED]> wrote:
>
>
> I don't really have any programming experience outside of hacking up a few
> lines of php, but it'd like to start learning python and the django web
> framework. I haven't been able to find too many intuitive guides like those
> for php, so i'd thought i'd ask here. Does anyone have any good suggestions?


Python:
http://docs.python.org/tut/
http://www.ibiblio.org/obp/thinkCSpy/
http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python/Contents

(In order of my preference.)

Django:
http://www.djangoproject.com/documentation/
http://www.djangoproject.com/documentation/tutorial01/
http://www.djangobook.com/en/beta/
http://code.djangoproject.com/wiki/Tutorials

(In no particular order.)

Also, join the IRC channel #django on freenode.
If you're not familiar with IRC, it's worth learning about-- there are
lots of people available to help on a variety of topics, and Django's
channel is especially helpful.  (There are 270 people on the channel
as I write this.)

http://en.wikipedia.org/wiki/Internet_Relay_Chat
IRC clients for:
Firefox: https://addons.mozilla.org/en-US/firefox/addon/16
Mac: http://colloquy.info/
Linux: http://konversation.kde.org/
Windows: http://www.mirc.com/get.html

Working with someone you know that already knows how to code would be
useful, and, of course, mailing this list is a good start, too.

Cheers,
  Jeremy

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



Re: Best Place To Start Learning Django/Python

2007-05-23 Thread Tyson Tate

Learning a bit of Python first helps. I'd start with the official  
Python tutorial:



Then give the official Django tutorial a shot:



Other than that, there's no better way to get started than by getting  
down and dirty and hacking through your own projects.

Regards,
Tyson

On May 23, 2007, at 1:07 PM, Peter Pluta wrote:

> I don't really have any programming experience outside of hacking  
> up a few
> lines of php, but it'd like to start learning python and the django  
> web
> framework. I haven't been able to find too many intuitive guides  
> like those
> for php, so i'd thought i'd ask here. Does anyone have any good  
> suggestions?


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



Re: Inconsistent SQL generated for ForeignKey fields

2007-05-23 Thread Fay

Forgot to mention, I use MySQL 5.1.



On May 23, 4:29 pm, Fay <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I encountered a situation that foreign key constraints were generated
> differently for the same data model.
>
> Below is my test model that has 2 identical sets of 1-to-many tables.
> When I run django sqlall command, however the foreign key constraints
> were built differently, one used column constraint while the other
> used table constraint. It seems the table names contribute to this
> behavior. Although they function very similarly, I wonder why that
> happened.
>
> from django.db import models
>
> class a1(models.Model):
> a1c1 = models.CharField(maxlength=200)
>
> class a2(models.Model):
> a2c1 = models.ForeignKey(a1)
> a2c2 = models.CharField(maxlength=200, core=True)
>
> class x1(models.Model):
> x1c1 = models.CharField(maxlength=200)
>
> class x2(models.Model):
> x2c1 = models.ForeignKey(x1)
> x2c2 = models.CharField(maxlength=200, core=True)
>
> Results from sqlall command:
>
> BEGIN;
> CREATE TABLE `test_a1` (
> `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> `a1c1` varchar(200) NOT NULL
> );
> CREATE TABLE `test_x2` (
> `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> `x2c1_id` integer NOT NULL,
> `x2c2` varchar(200) NOT NULL
> );
> CREATE TABLE `test_x1` (
> `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> `x1c1` varchar(200) NOT NULL
> );
> ALTER TABLE `test_x2` ADD CONSTRAINT x2c1_id_refs_id_11de27b2 FOREIGN
> KEY (`x2c1_id`) REFERENCES `test_x1` (`id`);
> CREATE TABLE `test_a2` (
> `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> `a2c1_id` integer NOT NULL REFERENCES `test_a1` (`id`),
> `a2c2` varchar(200) NOT NULL
> );
> CREATE INDEX `test_x2_x2c1_id` ON `test_x2` (`x2c1_id`);
> CREATE INDEX `test_a2_a2c1_id` ON `test_a2` (`a2c1_id`);
> COMMIT;
>
> Thanks.


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



Inconsistent SQL generated for ForeignKey fields

2007-05-23 Thread Fay

Hi,


I encountered a situation that foreign key constraints were generated
differently for the same data model.

Below is my test model that has 2 identical sets of 1-to-many tables.
When I run django sqlall command, however the foreign key constraints
were built differently, one used column constraint while the other
used table constraint. It seems the table names contribute to this
behavior. Although they function very similarly, I wonder why that
happened.


from django.db import models

class a1(models.Model):
a1c1 = models.CharField(maxlength=200)

class a2(models.Model):
a2c1 = models.ForeignKey(a1)
a2c2 = models.CharField(maxlength=200, core=True)

class x1(models.Model):
x1c1 = models.CharField(maxlength=200)

class x2(models.Model):
x2c1 = models.ForeignKey(x1)
x2c2 = models.CharField(maxlength=200, core=True)


Results from sqlall command:


BEGIN;
CREATE TABLE `test_a1` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`a1c1` varchar(200) NOT NULL
);
CREATE TABLE `test_x2` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`x2c1_id` integer NOT NULL,
`x2c2` varchar(200) NOT NULL
);
CREATE TABLE `test_x1` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`x1c1` varchar(200) NOT NULL
);
ALTER TABLE `test_x2` ADD CONSTRAINT x2c1_id_refs_id_11de27b2 FOREIGN
KEY (`x2c1_id`) REFERENCES `test_x1` (`id`);
CREATE TABLE `test_a2` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`a2c1_id` integer NOT NULL REFERENCES `test_a1` (`id`),
`a2c2` varchar(200) NOT NULL
);
CREATE INDEX `test_x2_x2c1_id` ON `test_x2` (`x2c1_id`);
CREATE INDEX `test_a2_a2c1_id` ON `test_a2` (`a2c1_id`);
COMMIT;


Thanks.


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



Re: How to delete a session

2007-05-23 Thread urielka

just do this:
from django.contrib.sessions.models import Session

Session.objects.filter(session_key=request.session.session_key).delete()

On May 23, 3:26 pm, Ramashish Baranwal <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> How can I delete the session of a request? The docs speak about using
> session as a dict and setting and removing specific keys on that, but
> I want to remove the session itself, something like del request.session
>
> Any ideas?
>
> Thanks in advance,
> Ram


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



Re: subclassing of models

2007-05-23 Thread Atilla

> Given that there is no branch, that statement is incorrect.
>
> Model inheritance is two stations down the line. Unicode gets finished
> first, then query refactor then model inheritance.
>
> Regards,
> Malcolm


Well, I'm certainly  glad to know this. I hadn't checked up on it for
a long time. I'll do my research  better next time.

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



Re: How to define unsigned integer primary keys with auto increment for MySQL

2007-05-23 Thread Malcolm Tredinnick

On Wed, 2007-05-23 at 17:52 +0200, Atilla wrote:
> On 23/05/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> >
> > On Tue, 2007-05-22 at 06:43 -0700, Fay wrote:
> > > I'm using MySQL. The primary key field generated by django uses
> > > integer, not unsigned. I'd like to us unsigned integer instead. I can
> > > explicitly specify PositiveIntegerField with primary_key option, but
> > > that doesn't seem to give me auto increment. Any ideas? Thanks.
> >
> > Write the necessary SQL to alter the table after it's created and put it
> > in the "initial SQL" file for that model. See the model-api docs for
> > more information on initial SQL.
> >
> > Regards,
> > Malcolm
> >
> 
> However, it doesn't make much sense to have signed auto-incremental
> keys, does it?
> 
> I'd say that unsigned should be the default result, instead of having
> to define this yourself. What are the reasons for having them signed
> by default ? Database engines with no support for signed/unsigned
> columns ?

No bigs reason, but it doesn't hurt and it isn't worth changing now. If
the difference between unsigned and signed is a showstopper for a
particular project, then the extra factor of two doesn't really buy you
much safety anyway. You might as well switch to some kind of really huge
field.

One advantage of this setup is that you could manually set the primary
key values yourself and providing you stuck to negative values, there
would be no chance of a clash.

Regards,
Malcolm



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



Re: Displaying data in the admin using list_display

2007-05-23 Thread Malcolm Tredinnick

On Wed, 2007-05-23 at 14:33 -0700, Greg wrote:
> I'm having a problem displaying data in my admin using list_display.
> I want to be able to show the Manufacturer in the admin from my styles
> page.  Here are my models:
> 
> class Manufacturer(models.Model):
>   name = models.CharField(maxlength=200)
>   manufacturerslug = models.SlugField(prepopulate_from=["name"])
>   description = models.TextField(maxlength=1000)
> 
> def __str__(self,):
>   return self.name
> 
>   class Admin:
>   pass
> 
> class Collection(models.Model):
>   name = models.CharField(maxlength=200)
>   collectionslug = models.SlugField(prepopulate_from=["name"])
>   description = models.TextField(maxlength=1000)
>   manufacturer = models.ForeignKey(Manufacturer)
> 
>   def __str__(self,):
>   return self.name
> 
>   class Admin:
>   pass
> 
> 
> class Style(models.Model):
> name = models.CharField(maxlength=200)
> theslug = models.SlugField(prepopulate_from=('name',))
> collection = models.ForeignKey(Collection)
> 
> 
> class Admin:
>   search_fields = ['name']
>   list_display = ('name', 'theslug','collection',
> 'collection.manufacturer')
> 
> 
> def __str__(self,):
>   return self.name
> 
> 
> 
> When I view my style table in the admin I want to be able to display
> the manufacturer.  However, I don't have a manufacturer field in the
> Style table.  All I have is a foreign key to collection, which
> contains a foreignkey to manufacturer.  I have no problem displaying
> the collection that the style is associated with.  I want to be able
> to show the manufacturer of the style in the admin.
> 
> I currently do "list_display = ('name', 'theslug', 'collection',
> 'collection.manufacturer')" However it errors when
> 'collection.manufacurer'.  Is it possible for me to show the
> Manufacturer of the style in the admin?

Doing list_display lookups across models like this doesn't work, as
you've discovered. One day we might even fix that, because it's about a
four line change to fix.

For the time being, the simplest solution is to create a method that
returns collection.manufacturer and use that method name in the
list_display list. You can even make this field sortable using the
admin_order_field attribute on the function (search the model-api docs
for more information), I suspect.

Regards,
Malcolm



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



Re: newforms: how to report multiple cross-field validation errors?

2007-05-23 Thread Malcolm Tredinnick

On Wed, 2007-05-23 at 10:16 -0700, mario wrote:
> I'm using newforms library and it is really a great improvement over
> "oldforms".
> 
> However, how would I report more than a single error when doing cross-
> field validation in the form clean() method?
> 
> I mean, since the errors are reported by raising an exception, on the
> first raised validation error the clean() method stops validating.
> Thus the user will only see the first error in the form. He has to fix
> it and resubmit to see (if any) the next errors.

Your form-level clean method should run through all of its validation,
collecting the errors as it goes and then raise a ValidationError. Note
that ValidationError can take a list of error messages in its
constructor, so just collect all your errors into a list and pass them
all at once to a single ValidationError raiser.

Regards,
Malcolm



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



Re: newforms + testing

2007-05-23 Thread Malcolm Tredinnick

On Wed, 2007-05-23 at 06:01 -0700, [EMAIL PROTECTED] wrote:
> Hello,
> 
> I wrote a newforms form, but I have some problems when I want to test
> the class.  Here's the definition:
> 
> def _users():
> print "calling _users()"
> return [(u.id, u.get_full_name()) for u in
> User.objects.filter(is_active=True)]
> 
> class MemoForm(forms.Form):
> body = forms.CharField(widget=forms.Textarea, required=True)
> recipients = forms.MultipleChoiceField(choices=_users(),
> required=True)
> 
> This works fine, however when I run my tests, _users() is called at
> the very beginning, 

The reason this is happening is because the "recipients" line of code,
including the function call to _users() is executed at *import* time, so
very early in the game.

You could replace choices=_users() with "choices=_users" and change the
_users() function to be an iterable. That will mean it is evaluated the
first time you need the choices (so, as late as possible). It will only
be evaluated once, though, so you can't use this to make the choices act
like a ForeignKey (updated every time you use it).

See
http://www.pointy-stick.com/blog/2007/03/26/django-tips-variable-choice-lists/ 
for a reasonably detailed example.

Regards,
Malcolm



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



Displaying data in the admin using list_display

2007-05-23 Thread Greg

I'm having a problem displaying data in my admin using list_display.
I want to be able to show the Manufacturer in the admin from my styles
page.  Here are my models:

class Manufacturer(models.Model):
name = models.CharField(maxlength=200)
manufacturerslug = models.SlugField(prepopulate_from=["name"])
description = models.TextField(maxlength=1000)

def __str__(self,):
return self.name

class Admin:
pass

class Collection(models.Model):
name = models.CharField(maxlength=200)
collectionslug = models.SlugField(prepopulate_from=["name"])
description = models.TextField(maxlength=1000)
manufacturer = models.ForeignKey(Manufacturer)

def __str__(self,):
return self.name

class Admin:
pass


class Style(models.Model):
name = models.CharField(maxlength=200)
theslug = models.SlugField(prepopulate_from=('name',))
collection = models.ForeignKey(Collection)


class Admin:
search_fields = ['name']
list_display = ('name', 'theslug','collection',
'collection.manufacturer')


def __str__(self,):
return self.name



When I view my style table in the admin I want to be able to display
the manufacturer.  However, I don't have a manufacturer field in the
Style table.  All I have is a foreign key to collection, which
contains a foreignkey to manufacturer.  I have no problem displaying
the collection that the style is associated with.  I want to be able
to show the manufacturer of the style in the admin.

I currently do "list_display = ('name', 'theslug', 'collection',
'collection.manufacturer')" However it errors when
'collection.manufacurer'.  Is it possible for me to show the
Manufacturer of the style in the admin?

Thanks for any help.


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



Re: {{ perms }} seems to be empty

2007-05-23 Thread Jeremy Dunck

On 5/23/07, Aidas Bendoraitis <[EMAIL PROTECTED]> wrote:
>
> Is "django.core.context_processors.auth" set in your
> TEMPLATE_CONTEXT_PROCESSORS? Are those new custom

You must also render the template using RequestContext rather than
Context in order for TEMPLATE_CONTEXT_PROCESSORS to be run.

How is 'request' getting into your template context?

Show us the view. :)

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



Re: {{ perms }} seems to be empty

2007-05-23 Thread Martin J Hsu



> 1. TEMPLATE_CONTEXT_PROCESSORS is not in my settings file. But the docs say 
> that its default is: ("django.core.context_processors.auth", etc...
>
That is correct:
http://www.djangoproject.com/documentation/settings/#template-context-processors

The default isn't explicitly defined in settings.py.  If you really
wanted to be sure it's in there, set it.  For example,

TEMPLATE_CONTEXT_PROCESSORS=
("django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n")

I think it would have been better to have it explicit set in
settings.py.  It would be more clear (as in your case) and easier to
modify (you wouldn't have to go find the documentation and copy/paste
it in).

There is probably a better way to check TEMPLATE_CONTEXT_PROCESSORS,
but setting it will help you eliminate this problem.



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



Re: {{ perms }} seems to be empty

2007-05-23 Thread Martin J Hsu



> 1. TEMPLATE_CONTEXT_PROCESSORS is not in my settings file. But the docs say 
> that its default is: ("django.core.context_processors.auth", etc...
>
That is correct:
http://www.djangoproject.com/documentation/settings/#template-context-processors

The default isn't explicitly defined in settings.py.  If you really
wanted to be sure it's in there, set it.  For example,

TEMPLATE_CONTEXT_PROCESSORS=
("django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n")

I think it would have been better to have it explicit set in
settings.py.  It would be more clear (as in your case) and easier to
modify (you wouldn't have to go find the documentation and copy/paste
it in).

There is probably a better way to check TEMPLATE_CONTEXT_PROCESSORS,
but setting it will help you eliminate this problem.



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



Re: {{ perms }} seems to be empty

2007-05-23 Thread Martin J Hsu



> 1. TEMPLATE_CONTEXT_PROCESSORS is not in my settings file. But the docs say 
> that its default is: ("django.core.context_processors.auth", etc...
>
That is correct:
http://www.djangoproject.com/documentation/settings/#template-context-processors

The default isn't explicitly defined in settings.py.  If you really
wanted to be sure it's in there, set it.  For example,

TEMPLATE_CONTEXT_PROCESSORS=
("django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n")

I think it would have been better to have it explicit set in
settings.py.  It would be more clear (as in your case) and easier to
modify (you wouldn't have to go find the documentation and copy/paste
it in).

There is probably a better way to check TEMPLATE_CONTEXT_PROCESSORS,
but setting it will help you eliminate this problem.



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



Re: How to delete a session

2007-05-23 Thread Joseph Heck

Ah - right. The middleware returns that all wrapped up. You can use
the _session attribute on it to get down to the actual session object
(I think - at least based on a quick glance through the code).

So (I think)

x=request.session._session
x.delete()

-joe

On 5/23/07, Ramashish Baranwal <[EMAIL PROTECTED]> wrote:
>
> > On May 23, 10:18 pm, "Joseph Heck" <[EMAIL PROTECTED]> wrote:
> >
> > > The session is a model in Django - so you can delete it like any other -
> >
> > > x=request.session
> > > x.delete()
> >
> > > There's also the daily_cleanup.py script included with Django that
> > > just goes straight to the 
> > > database:http://code.djangoproject.com/browser/django/trunk/django/bin/daily_c...
> >
> > Thanks Joe, but thats not working. I'm getting the following error-
> >
> > AttributeError
> > 'SessionWrapper' object has no attribute 'delete'
> > Exception Type: AttributeError
> > Exception Value:'SessionWrapper' object has no attribute 'delete'
>
> Sorry for the multiple postings. It was due to some network problem at
> my end.
>
> -Ram
>
>
> >
>

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



Re: newforms + testing

2007-05-23 Thread Doug B

If you put the call to your _users() function in the form __init__() I
think it will be what you are looking for.  initi s called
automatically whenever an instance is created.

class MemoForm(forms.Form):
-snip-
def __init__(self,*args,**kwarg)
super(MemoForm,self).__init__(*args,**kwargs)
self.fields['recipients'].choices = _users()



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



Re: newforms + testing

2007-05-23 Thread Doug B

If you put the call to your _users() function in the form __init__() I
think it will be what you are looking for.  initi s called
automatically whenever an instance is created.

class MemoForm(forms.Form):
-snip-
def __init__(self,*args,**kwarg)
super(MemoForm,self).__init__(*args,**kwargs)
self.fields['recipients'].choices = _users()



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



Re: newforms + testing

2007-05-23 Thread Doug B

If you put the call to your _users() function in the form __init__() I
think it will be what you are looking for.  initi s called
automatically whenever an instance is created.

class MemoForm(forms.Form):
-snip-
def __init__(self,*args,**kwarg)
super(MemoForm,self).__init__(*args,**kwargs)
self.fields['recipients'].choices = _users()



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



Re: Where did you put your homepage view?

2007-05-23 Thread Christian Markwart Hoeppner

> I'm juste curious, where did you put your homepage view when you've
> got a project with a lot of apps? Is there a best practice here?

An extra app? Man... Views do not *have* to reside inside some app.
Whenever I have some view not specific to some app, I create a module
for those in the project root. Same with project-specific middleware and
the such.

For example, I have lately gotten a maintenance-middleware solution from
this list, and it's being implemented in a module called "common_views"
that resides in the project folder.

Remember, you can have your code anywhere, as long as it's on the
pythonpath.

Be adventurous. We coders need to be.

Kind regards,
Chris Hoeppner
www.pixware.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?hl=en
-~--~~~~--~~--~--~---



Re: NEWBIE: joining two tables problem

2007-05-23 Thread Rogelio

On May 23, 3:10 pm, Rogelio <[EMAIL PROTECTED]> wrote:
> Thank you so much!  I was able to get your first method to work.  The
> second method
> seemed to be complaining that I was using a for-loop on an empty
> "photo_set".
> I'll play around it some more.
>
> Rogelio


Sorry for the multiple "thanks" -- on my end I was getting a message
that there
was an error posting the reply and I should try again later -- which I
did several
times.  I guess there was no error after all.


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



Re: NEWBIE: joining two tables problem

2007-05-23 Thread Rogelio

Thank you so much!  I was able to get your first method to work.  The
second method
seemed to be complaining that I was using a for-loop on an empty
"photo_set".
I'll play around it some more.

Rogelio


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



Re: NEWBIE: joining two tables problem

2007-05-23 Thread Rogelio

Thank you so much!  I was able to get your first method to work.  The
second method
seemed to be complaining that I was using a for-loop on an empty
"photo_set".
I'll play around it some more.

Rogelio


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



Re: NEWBIE: joining two tables problem

2007-05-23 Thread Rogelio

Thank you so much!  I was able to get your first method to work.  The
second method
seemed to be complaining that I was using a for-loop on an empty
"photo_set".
I'll play around it some more.

Rogelio


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



RESOLVED: Re: Query Question ...

2007-05-23 Thread ZebZiggle

Took some custom SQL, but this works well:

content = Content.objects \
.filter(approved__isnull = False) \
.extra(where=['id not in (SELECT content_id FROM
relationship WHERE user_id = %d and "hasRead" = TRUE)' % user.id]) \
.order_by('-created')

Phew.

Enjoy,
Sandy


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



Re: need to know to start learn django

2007-05-23 Thread Christian Markwart Hoeppner

El mié, 23-05-2007 a las 11:46 -0500, Tim Chase escribió:
> > What i need to know, except python before i start learn django?

I went onto my first django-powered project without knowing a bit of
python, django, whatever. Actually, I jumped over mid-project! Python is
amazingly easy to learn, and I had a firm background of web-related
stuff anyways, so the learning path was quite amusing.

Want to learn it quick? Start someting you'd like to have, like a blog
or so. Your own passion for it will keep you learning, doing, and
learning again.

Kind regards,
Chris Hoeppner
www.pixware.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?hl=en
-~--~~~~--~~--~--~---



Re: How to delete a session

2007-05-23 Thread Ramashish Baranwal

> On May 23, 10:18 pm, "Joseph Heck" <[EMAIL PROTECTED]> wrote:
>
> > The session is a model in Django - so you can delete it like any other -
>
> > x=request.session
> > x.delete()
>
> > There's also the daily_cleanup.py script included with Django that
> > just goes straight to the 
> > database:http://code.djangoproject.com/browser/django/trunk/django/bin/daily_c...
>
> Thanks Joe, but thats not working. I'm getting the following error-
>
> AttributeError
> 'SessionWrapper' object has no attribute 'delete'
> Exception Type: AttributeError
> Exception Value:'SessionWrapper' object has no attribute 'delete'

Sorry for the multiple postings. It was due to some network problem at
my end.

-Ram


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



Re: How to delete a session

2007-05-23 Thread Ramashish Baranwal

On May 23, 10:18 pm, "Joseph Heck" <[EMAIL PROTECTED]> wrote:
> The session is a model in Django - so you can delete it like any other -
>
> x=request.session
> x.delete()
>
> There's also the daily_cleanup.py script included with Django that
> just goes straight to the 
> database:http://code.djangoproject.com/browser/django/trunk/django/bin/daily_c...
>

Thanks Joe, but thats not working. I'm getting the following error-

AttributeError
'SessionWrapper' object has no attribute 'delete'
Exception Type: AttributeError
Exception Value:'SessionWrapper' object has no attribute 'delete'

-Ram


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



Re: How to delete a session

2007-05-23 Thread Ramashish Baranwal

On May 23, 10:18 pm, "Joseph Heck" <[EMAIL PROTECTED]> wrote:
> The session is a model in Django - so you can delete it like any other -
>
> x=request.session
> x.delete()
>
> There's also the daily_cleanup.py script included with Django that
> just goes straight to the 
> database:http://code.djangoproject.com/browser/django/trunk/django/bin/daily_c...
>

Thanks Joe, but thats not working. I'm getting the following error-

AttributeError
'SessionWrapper' object has no attribute 'delete'
Exception Type: AttributeError
Exception Value:'SessionWrapper' object has no attribute 'delete'

-Ram


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



NEWBIE: joining two tables problem

2007-05-23 Thread Rogelio

Hello.  Newbie to django and first-time poster to this group.

I've got two models (basic structure shown below):

class Employee(models.Model):
 name = models.CharField(maxlength=50)
 office = models.CharField(maxlength=20)
 phone= models.CharField(maxlength=15)

class Photo(models.Model):
 filename = models.CharField(maxlength=50)
 master_photo = models.BooleanField()
 employee = models.ForeignKey(Employee)

In one of my views I'd like to have a table consisting of rows like:



but if I say:

object_list = Employee.objects.order_by('name')

and pass "object_list" to my listing.html template, it doesn't have
the Photo information.

I've resorted to using straight SQL to build the query:

def employee_view_list(self):
 from django.db import connection
 cursor = connection.cursor()
 cursor.execute("select e.id, e.name, e.office, p.filename
from company_employee e, company_photo p where p.employee_id=e.id and
p.master_photo='T'")
 rows = cursor.fetchall()
 return rows

This sort of works and returns  a list-of-lists, but I can't use the
convention {{employee.name}} in the
template since the returned rows do not include the header
information.

Questions:

1) Is there a better way to join these tables using the django model
methods?
2) Is there an better way to use straight SQL and still be able to use
things like {{employee.name}}
in the templates?
3) I tried making the Photo table have a "many2manyfield" on Employee
rather an
a ForeignKey.  I rebuilt the database using syncdb, but when I tried
to enter photo info
via the admin interface, I got an "operational error".  I could edit
the other database tables
fine.  Ideas?  I tried using the latest stable django and the SVN from
today with the same
result.

Thanks in advance.
Rogelio


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



user object in templates

2007-05-23 Thread John

it seems like I have no user object in my templates, which is weird,
as it comes w/ my request object, and I can access it in my views. In
other words, request.user.is_authenticated evaluates to True in my
views, but to False in my templates.

Before you ask, I do have 'django.core.context_processors.auth' in my
TEMPLATE_CONTENTS_PROCESSORS, and AuthenticationMiddleware and
SessionMiddleware in my MIDDLEWARE_CLASES.

I am running the trunk version of django as of today.

Has the sintax for accessing the user object ( {{ user.foo }} )
changed, or am I missing something really, really silly?

Thanks.


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



GeoDjango Admin interface - Invalid HEX given!

2007-05-23 Thread mikeyparker

I'm just moving an application that we were writing over to the
GeoDjango branch and I've come across a small problem that I was
hoping that someone may be able to shed a little light on.

I have a model

class CityArea(models.Model, models.GeoMixin):

name = models.CharField(blank=False, maxlength=100, core=True)
city = models.ForeignKey('City')
poly = models.PolygonField(blank=True)

objects = models.GeoManager()

And I can interact with and create instances of this model using the
shell interface:

ca = CityArea(name='Jesmond', city=c, poly='POLYGON(( 10 10, 10 20, 20
20, 20 15, 10 10))')
ca.save()

This works fine. However I am unable to add a new one using the admin
interface. I can however edit those that are already created. So the
above example becomes available in the admin interface and I can
happily use the interfaces functionality to manipulate it. Like I said
the problem only occurs when attempting to create a new instance. When
ever I try this I get the following error:

Request Method: GET
Request URL:http://0.0.0.0:8000/admin/properties/cityarea/add/
Exception Type: GEOSException
Exception Value:Invalid HEX given!
Exception Location: /sw/lib/python2.5/site-packages/django/contrib/gis/
geos/GEOSGeometry.py in __init__, line 143

Any help would be much appreciated. Thanks

Mike


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



Re: Explicit SQL not working ...

2007-05-23 Thread ZebZiggle

Joseph ... you da man!

Next time your in Halifax, Nova Scotia ... the beer is on me.

I was looking at that method and ignored it since I'm not using
transactions.

THANK YOU!

-Sandy


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



Re: Explicit SQL not working ...

2007-05-23 Thread ZebZiggle

More info ...

I wrote a little program to execute the query directly via psycopg and
it works fine. Even if I take this test code and put it in the running
django code, it continues to work fine.

The SQL is an UPDATE command, like

UPDATE
content
SET
"voteTotal" = "voteTotal" + 1,
"voteCount" = "voteCount" + 1
WHERE
id = 25

It seems like there something about the CursorWrapper or the
DatabaseWrapper that is preventing the execute() from working ...

I'm using 0.96 with DATABASE_ENGINE = 'postgresql' backend. Everything
else about django works fine.

anyone?

-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?hl=en
-~--~~~~--~~--~--~---



Re: Explicit SQL not working ...

2007-05-23 Thread ZebZiggle

More info ...

I wrote a little program to execute the query directly via psycopg and
it works fine. Even if I take this test code and put it in the running
django code, it continues to work fine.

The SQL is an UPDATE command, like

UPDATE
content
SET
"voteTotal" = "voteTotal" + 1,
"voteCount" = "voteCount" + 1
WHERE
id = 25

It seems like there something about the CursorWrapper or the
DatabaseWrapper that is preventing the execute() from working ...

I'm using 0.96 with DATABASE_ENGINE = 'postgresql' backend. Everything
else about django works fine.

anyone?

-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?hl=en
-~--~~~~--~~--~--~---



Re: LIKE '%something%' custom queries

2007-05-23 Thread Ivan Sagalaev

[EMAIL PROTECTED] wrote:
> I'm reimplementing an in-database tree system and I'm using custom SQL
> queries. I want to use % in LIKE but Django doesn't let me.
> 
> The code:
> ##
> def getBranch(table_name, parent_depth, parent_cutLevel, max_depth):
>   cursor = connection.cursor()
>   cursor.execute("SELECT *, INSTR(level,'0')-1 AS depth,
> INSTR(level,'0')-1 - "+ parent_depth +" AS relativeDepth FROM  " +
> table_name + " WHERE level LIKE '"+ parent_cutLevel +"%' AND
> INSTR(level,'0')-1 <= ("+ max_depth +"+"+ parent_depth +") ORDER BY
> level")
>   row = cursor.fetchall()
>   return row
> ##

The error says that Python tries to replace '%' with parameters but 
there aren't any. To escape them duplicate them:

 " WHERE level LIKE '"+ parent_cutLevel +"%%' AND ...

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



Re: Explicit SQL not working ...

2007-05-23 Thread Joseph Heck

When you're done with the command (assuming you're not being explicit
about the transactions), use:

 transaction.commit_unless_managed()

to force the commit.

-joe

On 5/23/07, ZebZiggle <[EMAIL PROTECTED]> wrote:
>
> More info ...
>
> I wrote a little program to execute the query directly via psycopg and
> it works fine. Even if I take this test code and put it in the running
> django code, it continues to work fine.
>
> The SQL is an UPDATE command, like
>
> UPDATE
> content
> SET
> "voteTotal" = "voteTotal" + 1,
> "voteCount" = "voteCount" + 1
> WHERE
> id = 25
>
> It seems like there something about the CursorWrapper or the
> DatabaseWrapper that is preventing the execute() from working ...
>
> I'm using 0.96 with DATABASE_ENGINE = 'postgresql' backend. Everything
> else about django works fine.
>
> anyone?
>
> -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?hl=en
-~--~~~~--~~--~--~---



Re: Explicit SQL not working ...

2007-05-23 Thread ZebZiggle

More info ...

I wrote a little program to execute the query directly via psycopg and
it works fine. Even if I take this test code and put it in the running
django code, it continues to work fine.

The SQL is an UPDATE command, like

UPDATE
content
SET
"voteTotal" = "voteTotal" + 1,
"voteCount" = "voteCount" + 1
WHERE
id = 25

It seems like there something about the CursorWrapper or the
DatabaseWrapper that is preventing the execute() from working ...

I'm using 0.96 with DATABASE_ENGINE = 'postgresql' backend. Everything
else about django works fine.

anyone?

-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?hl=en
-~--~~~~--~~--~--~---



Re: LIKE '%something%' custom queries

2007-05-23 Thread Atilla

On 23/05/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> I'm reimplementing an in-database tree system and I'm using custom SQL
> queries. I want to use % in LIKE but Django doesn't let me.
>
> The code:
> ##
> def getBranch(table_name, parent_depth, parent_cutLevel, max_depth):
> cursor = connection.cursor()
> cursor.execute("SELECT *, INSTR(level,'0')-1 AS depth,
> INSTR(level,'0')-1 - "+ parent_depth +" AS relativeDepth FROM  " +
> table_name + " WHERE level LIKE '"+ parent_cutLevel +"%' AND
> INSTR(level,'0')-1 <= ("+ max_depth +"+"+ parent_depth +") ORDER BY
> level")
> row = cursor.fetchall()
> return row
> ##
>
> The exception:
> ##
> not enough arguments for format string
> Exception Location: /usr/lib64/python2.4/site-packages/django/db/
> backends/util.py in execute, line 19
> ##
> I can "print" the query string, but can't make the query as cursor
> code uses %letters... Is there a solution for this. ( \ doesn't work,
> % in variable also)
>

Umm... the "%" symbol has a special meaning in a string, which is to
interpolate it and fill it with arguments from a provided list. In a
cursor it's a variable placeholder used for prepared (or normal)
queries. If you want it literal, you must escape it properly.

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



Re: Explicit SQL not working ...

2007-05-23 Thread ZebZiggle

More info ...

I wrote a little program to execute the query directly via psycopg and
it works fine. Even if I take this test code and put it in the running
django code, it continues to work fine.

The SQL is an UPDATE command, like

UPDATE
content
SET
"voteTotal" = "voteTotal" + 1,
"voteCount" = "voteCount" + 1
WHERE
id = 25

It seems like there something about the CursorWrapper or the
DatabaseWrapper that is preventing the execute() from working ...

anyone?

-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?hl=en
-~--~~~~--~~--~--~---



Re: Explicit SQL not working ...

2007-05-23 Thread ZebZiggle

More info ...

I wrote a little program to execute the query directly via psycopg and
it works fine. Even if I take this test code and put it in the running
django code, it continues to work fine.

The SQL is an UPDATE command, like

UPDATE
content
SET
"voteTotal" = "voteTotal" + 1,
"voteCount" = "voteCount" + 1
WHERE
id = 25

It seems like there something about the CursorWrapper or the
DatabaseWrapper that is preventing the execute() from working ...

anyone?

-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?hl=en
-~--~~~~--~~--~--~---



Re: LIKE '%something%' custom queries

2007-05-23 Thread Joseph Heck

Don't put the % inside of " characters, or Python will attempt to
evaluate it out. Alternately, escape it so it doesn't eval. I
generally form up my custom SQL strings outside of the execute()
method to make debugging this kind of thing a tad easier.

-joe

On 5/23/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> I'm reimplementing an in-database tree system and I'm using custom SQL
> queries. I want to use % in LIKE but Django doesn't let me.
>
> The code:
> ##
> def getBranch(table_name, parent_depth, parent_cutLevel, max_depth):
> cursor = connection.cursor()
> cursor.execute("SELECT *, INSTR(level,'0')-1 AS depth,
> INSTR(level,'0')-1 - "+ parent_depth +" AS relativeDepth FROM  " +
> table_name + " WHERE level LIKE '"+ parent_cutLevel +"%' AND
> INSTR(level,'0')-1 <= ("+ max_depth +"+"+ parent_depth +") ORDER BY
> level")
> row = cursor.fetchall()
> return row
> ##
>
> The exception:
> ##
> not enough arguments for format string
> Exception Location: /usr/lib64/python2.4/site-packages/django/db/
> backends/util.py in execute, line 19
> ##
> I can "print" the query string, but can't make the query as cursor
> code uses %letters... Is there a solution for this. ( \ doesn't work,
> % in variable also)
>
>
> >
>

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



Re: How to delete a session

2007-05-23 Thread Joseph Heck

The session is a model in Django - so you can delete it like any other -

x=request.session
x.delete()

There's also the daily_cleanup.py script included with Django that
just goes straight to the database:
http://code.djangoproject.com/browser/django/trunk/django/bin/daily_cleanup.py

-joe

On 5/23/07, Ramashish Baranwal <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> How can I delete the session of a request? The docs speak about using
> session as a dict and setting and removing specific keys on that, but
> I want to remove the session itself, something like del request.session
>
> Any ideas?
>
> Thanks in advance,
> Ram
>
>
> >
>

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



newforms: how to report multiple cross-field validation errors?

2007-05-23 Thread mario

I'm using newforms library and it is really a great improvement over
"oldforms".

However, how would I report more than a single error when doing cross-
field validation in the form clean() method?

I mean, since the errors are reported by raising an exception, on the
first raised validation error the clean() method stops validating.
Thus the user will only see the first error in the form. He has to fix
it and resubmit to see (if any) the next errors.

Is there any workaround for this?

Thanks for any help.


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



RE: Displaying my table data

2007-05-23 Thread Chris Brand

> >>> from mysite.rugs.models import Choice, Size, Price
> >>> c = Choice.objects.filter(choice=1)
> >>> c
> [, , ]

You can see here that your queryset maps to three objects.

> >>> c.size.name
> Traceback (most recent call last):
>   File "", line 1, in ?
> AttributeError: 'QuerySet' object has no attribute 'size'

I'd try to get at just one of those three objects first.
Something like
c[0].size.name
except that you might need to use list(c)[0], I can't remember.

Chris




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



LIKE '%something%' custom queries

2007-05-23 Thread [EMAIL PROTECTED]

I'm reimplementing an in-database tree system and I'm using custom SQL
queries. I want to use % in LIKE but Django doesn't let me.

The code:
##
def getBranch(table_name, parent_depth, parent_cutLevel, max_depth):
cursor = connection.cursor()
cursor.execute("SELECT *, INSTR(level,'0')-1 AS depth,
INSTR(level,'0')-1 - "+ parent_depth +" AS relativeDepth FROM  " +
table_name + " WHERE level LIKE '"+ parent_cutLevel +"%' AND
INSTR(level,'0')-1 <= ("+ max_depth +"+"+ parent_depth +") ORDER BY
level")
row = cursor.fetchall()
return row
##

The exception:
##
not enough arguments for format string
Exception Location: /usr/lib64/python2.4/site-packages/django/db/
backends/util.py in execute, line 19
##
I can "print" the query string, but can't make the query as cursor
code uses %letters... Is there a solution for this. ( \ doesn't work,
% in variable also)


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



Re: How do I Sort Years in Template

2007-05-23 Thread Frank Peterson

thanks, I had to use dictsortreversed and that puts them in newest
year first :)


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



Re: need to know to start learn django

2007-05-23 Thread Tim Chase

> What i need to know, except python before i start learn django?

*Need* to know?  Nothing more than Python and HTML--even that, 
you might be able to get by with a point-and-drool GUI editor for 
your HTML editing.

However, the more you know about HTML, HTTP, and SQL, the more 
fewer limitations you'll encounter.  And if you have certain 
requirements, you may need additional knowledge (such as 
interfacing with web services might require knowing something 
about XML; using unit tests, it would help to know about the 
python doctest and unittest modules as well as knowing about 
Django's fixtures & JSON).

You can get by without knowing much at all, but to wow the world, 
you might need a little more than just python and Django.

-tim




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



need to know to start learn django

2007-05-23 Thread Gigs_

What i need to know, except python before i start learn django?


thank you


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



Re: A Few Questions with How to Work With Views

2007-05-23 Thread Tim Chase

>> (1) I'd like to include little snippets from each app on
>> another app's pages.  For instance, a little "widget" in a
>> sidebar of my blog software that has some random pictures
>> from the photo management.  Is there any suggestion on how
>> to do this?
> 
> Template Tags!
> 
> http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-tags

I second David's recommendation.  In particular, I suggest 
skimming down from there to

http://www.djangoproject.com/documentation/templates_python/#inclusion-tags

which makes it fairly easy to separate the presentation (stashed 
in a template, where editing the HTML becomes fairly easy) from 
the data view.

As a side question:
Is there any convention used by the Django overlords for storing 
inclusion-tag templates?  Just toss all the inclusion-tag 
templates in the projname/appname/templates/ with the full page 
templates?  Or cordon them off in a separate sub-directory?  And 
if using a separate sub-directory, is there a preferred naming 
convention (such as "templates/tags/")?  Or shove them in some 
place outside of the projname/appname/templates/ directory?

-tim







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



Re: Where did you put your homepage view?

2007-05-23 Thread afarnham

> I'm juste curious, where did you put your homepage view when you've
> got a project with a lot of apps?

I create a django app called "site" and put my index view in there. I
also put any template tags and filters that will be used across the
project in that app.

~Aaron


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



Re: How to define unsigned integer primary keys with auto increment for MySQL

2007-05-23 Thread Atilla

On 23/05/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>
> On Tue, 2007-05-22 at 06:43 -0700, Fay wrote:
> > I'm using MySQL. The primary key field generated by django uses
> > integer, not unsigned. I'd like to us unsigned integer instead. I can
> > explicitly specify PositiveIntegerField with primary_key option, but
> > that doesn't seem to give me auto increment. Any ideas? Thanks.
>
> Write the necessary SQL to alter the table after it's created and put it
> in the "initial SQL" file for that model. See the model-api docs for
> more information on initial SQL.
>
> Regards,
> Malcolm
>

However, it doesn't make much sense to have signed auto-incremental
keys, does it?

I'd say that unsigned should be the default result, instead of having
to define this yourself. What are the reasons for having them signed
by default ? Database engines with no support for signed/unsigned
columns ?

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



Re: subclassing of models

2007-05-23 Thread Atilla

On 23/05/07, OliverMarchand <[EMAIL PROTECTED]> wrote:
>
> Dear Djangos,
>
> Is it possible to subclass a model? This example somehow doesn't work
> for in the sense that I only see the geography on the admin screen.
>
> 
> from django.db import models
>
> class Geography(models.Model):
> name = models.CharField(maxlength=30)
> def __str__(self):
> return self.name
> class Admin:
> pass
>
> class Continent(Geography):
> pass
>
> class Country(Geography):
> continent = models.ForeignKey(Continent)
> ---
>
> Any ideas?
>
> greetings, Oliver
>

Model Inheritance is, sadly, not supported and the branch that
implements that is stalled (or is it ?).

For now  - one of the ways people prefer to do similar things is to
associate entries in the models, via a relationship. You can search
the mailing list archive for different solutions that people have
tried.

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



Re: A Few Questions with How to Work With Views

2007-05-23 Thread David Reynolds


On 23 May 2007, at 4:23 pm, rockstar_ wrote:



Hi guys-

  I'm not new to Python, or to web development, but I am new to web
development with python and new to Django.  I've been reading about
Django, and been dabbling with it for about six months.  It's about
time I crap or get off the pot.  And, well, Django has been fun so
far, so I'm gonna crap...  :)

  I've been using Django to design a new iteration of my website, and
replace all the third party software I've been using because either I
can't customize that software, or I'm sure I could write something
much better.  So far, I've created two different apps in my project, a
blog software and a photo manager.  I've got all the logic working,
and I'm really liking how it works.  The only problem is, now I've got
to get into how the templates work.  So here are my questions:

  (1) I'd like to include little snippets from each app on another
app's pages.  For instance, a little "widget" in a sidebar of my blog
software that has some random pictures from the photo management.  Is
there any suggestion on how to do this?


Template Tags!

http://www.djangoproject.com/documentation/templates_python/#writing- 
custom-template-tags



  (2) I'd like to create a global header and footer, which will apply
to all pages, and have in abstracted into their own template files.
That way, if I need to add a new javascript file, or make a change to
a meta tag, I can do that without having to write some mad crazy sed
scripts.


You can do this pretty easily using the {% block thing %}{% endblock  
%} tags. There is also the {% include %} tag, if you need it.


http://www.djangoproject.com/documentation/templates/


  (3) I'd like to create a tagging app that allows tags for blog posts
and for photos.  I know how the database model for this might look,
and I've read a bit on the many-to-many relationship in Django, but
does anyone have any pointers here?


Someone has made a fairly generic tagging application:

http://code.google.com/p/django-tagging/

Hope that helps!

Dave
--
David Reynolds
[EMAIL PROTECTED]




smime.p7s
Description: S/MIME cryptographic signature


subclassing of models

2007-05-23 Thread OliverMarchand

Dear Djangos,

Is it possible to subclass a model? This example somehow doesn't work
for in the sense that I only see the geography on the admin screen.


from django.db import models

class Geography(models.Model):
name = models.CharField(maxlength=30)
def __str__(self):
return self.name
class Admin:
pass

class Continent(Geography):
pass

class Country(Geography):
continent = models.ForeignKey(Continent)
---

Any ideas?

greetings, Oliver


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



Explicit SQL not working ...

2007-05-23 Thread ZebZiggle

I'm doing a very simple direct SQL call

cursor = connection.cursor()
cursor.execute(sql)


which works when I issue the SQL directly in the database, but via
django does nothing.

cursor.rowcount returns correctly, but there are no rows to fetch and
the database isn't updated.

Any ideas?

Thx,
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?hl=en
-~--~~~~--~~--~--~---



Re: "showable" but not "editable" field in the Admin screens

2007-05-23 Thread Atilla

On 23/05/07, Brian Rosner <[EMAIL PROTECTED]> wrote:
>
> You may also want to check out http://code.djangoproject.com/ticket/3990.
>
> On May 22, 5:19 am, "Seiji - technics" <[EMAIL PROTECTED]> wrote:
> > Hi all,
> >
> > Is there a way to show as specific field in the admin screens but
> > without permitting to edit it?
> > I want something similar to "editable=False" option but without
> > excluding the field from the screen.
> >
> > Thanks in advance for the help.
> >
> > Seiji

On that note - the name "editable" is a bit misleading. i expected it
to define the field as read-only, not as completely invisible in
generic forms.

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



Re: newforms + testing

2007-05-23 Thread [EMAIL PROTECTED]

I fixed my problem, but it's very much a hack.  If anyone has a better
solution, please post it.

My fix was a simple hack: after every instantiation of my MemoForm
class, I called a method "replace_recipients" where I changed the
value of form_object.base_fields['recipients'].choices.  Like I said,
a hack and not a pretty one, but it works.

Vincent.

On May 23, 9:01 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I wrote a newforms form, but I have some problems when I want to test
> the class.  Here's the definition:
>
> def _users():
> print "calling _users()"
> return [(u.id, u.get_full_name()) for u in
> User.objects.filter(is_active=True)]
>
> class MemoForm(forms.Form):
> body = forms.CharField(widget=forms.Textarea, required=True)
> recipients = forms.MultipleChoiceField(choices=_users(),
> required=True)
>
> This works fine, however when I run my tests, _users() is called at
> the very beginning, so the choices in recipients come from my
> production database, not from the fixtures I wrote.  Does anyone know
> how I could fix this?
>
> Thank you,
>
> Vincent


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



Re: newforms + testing

2007-05-23 Thread [EMAIL PROTECTED]

I fixed my problem, but it's very much a hack.  If anyone has a better
solution, please post it.

My fix was a simple hack: after every instantiation of my MemoForm
class, I called a method "replace_recipients" where I changed the
value of form_object.base_fields['recipients'].choices.  Like I said,
a hack and not a pretty one, but it works.

Vincent.

On May 23, 9:01 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I wrote a newforms form, but I have some problems when I want to test
> the class.  Here's the definition:
>
> def _users():
> print "calling _users()"
> return [(u.id, u.get_full_name()) for u in
> User.objects.filter(is_active=True)]
>
> class MemoForm(forms.Form):
> body = forms.CharField(widget=forms.Textarea, required=True)
> recipients = forms.MultipleChoiceField(choices=_users(),
> required=True)
>
> This works fine, however when I run my tests, _users() is called at
> the very beginning, so the choices in recipients come from my
> production database, not from the fixtures I wrote.  Does anyone know
> how I could fix this?
>
> Thank you,
>
> Vincent


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



Re: newforms + testing

2007-05-23 Thread [EMAIL PROTECTED]

I fixed my problem, but it's very much a hack.  If anyone has a better
solution, please post it.

My fix was a simple hack: after every instantiation of my MemoForm
class, I called a method "replace_recipients" where I changed the
value of form_object.base_fields['recipients'].choices.  Like I said,
a hack and not a pretty one, but it works.

Vincent.

On May 23, 9:01 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I wrote a newforms form, but I have some problems when I want to test
> the class.  Here's the definition:
>
> def _users():
> print "calling _users()"
> return [(u.id, u.get_full_name()) for u in
> User.objects.filter(is_active=True)]
>
> class MemoForm(forms.Form):
> body = forms.CharField(widget=forms.Textarea, required=True)
> recipients = forms.MultipleChoiceField(choices=_users(),
> required=True)
>
> This works fine, however when I run my tests, _users() is called at
> the very beginning, so the choices in recipients come from my
> production database, not from the fixtures I wrote.  Does anyone know
> how I could fix this?
>
> Thank you,
>
> Vincent


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



Re: newforms + testing

2007-05-23 Thread [EMAIL PROTECTED]

I fixed my problem, but it's very much a hack.  If anyone has a better
solution, please post it.

My fix was a simple hack: after every instantiation of my MemoForm
class, I called a method "replace_recipients" where I changed the
value of form_object.base_fields['recipients'].choices.  Like I said,
a hack and not a pretty one, but it works.

Vincent.

On May 23, 9:01 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I wrote a newforms form, but I have some problems when I want to test
> the class.  Here's the definition:
>
> def _users():
> print "calling _users()"
> return [(u.id, u.get_full_name()) for u in
> User.objects.filter(is_active=True)]
>
> class MemoForm(forms.Form):
> body = forms.CharField(widget=forms.Textarea, required=True)
> recipients = forms.MultipleChoiceField(choices=_users(),
> required=True)
>
> This works fine, however when I run my tests, _users() is called at
> the very beginning, so the choices in recipients come from my
> production database, not from the fixtures I wrote.  Does anyone know
> how I could fix this?
>
> Thank you,
>
> Vincent


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



A Few Questions with How to Work With Views

2007-05-23 Thread rockstar_

Hi guys-

  I'm not new to Python, or to web development, but I am new to web
development with python and new to Django.  I've been reading about
Django, and been dabbling with it for about six months.  It's about
time I crap or get off the pot.  And, well, Django has been fun so
far, so I'm gonna crap...  :)

  I've been using Django to design a new iteration of my website, and
replace all the third party software I've been using because either I
can't customize that software, or I'm sure I could write something
much better.  So far, I've created two different apps in my project, a
blog software and a photo manager.  I've got all the logic working,
and I'm really liking how it works.  The only problem is, now I've got
to get into how the templates work.  So here are my questions:

  (1) I'd like to include little snippets from each app on another
app's pages.  For instance, a little "widget" in a sidebar of my blog
software that has some random pictures from the photo management.  Is
there any suggestion on how to do this?
  (2) I'd like to create a global header and footer, which will apply
to all pages, and have in abstracted into their own template files.
That way, if I need to add a new javascript file, or make a change to
a meta tag, I can do that without having to write some mad crazy sed
scripts.
  (3) I'd like to create a tagging app that allows tags for blog posts
and for photos.  I know how the database model for this might look,
and I've read a bit on the many-to-many relationship in Django, but
does anyone have any pointers here?

  I'm excited to actually finish and deploy some Django code!

rockstar_


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



Re: Displaying my table data

2007-05-23 Thread Greg

Carole,
I've tried what you suggeted and it still didn't work.  I haven't
changed my db structure.  Here is what I get when I do it in the
command prompt

>>> from mysite.rugs.models import Choice, Size, Price
>>> c = Choice.objects.filter(choice=1)
>>> c
[, , ]
>>> c.size.name
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'QuerySet' object has no attribute 'size'

I still can't access the size and price's tied to style number 89b.  I
thought that c.size.name would work (guess not),

Thanks for any help





On May 23, 8:24 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Ok...then it would be soemthing like this:
>
> choices = Choice.objects.filter(choice=1)
> for choice in choices:   # you used filter, not get so I'm assuming
> this is not the primary key and you are getting multiple objects back
>   a.size.name
>   a.price.name
>
> However...if your size/price tables all just contain one field...maybe
> you should have a model something like this..where you don't have
> separate tables for size/price:
>
> class Style(models.Model):
> name = models.CharField(maxlength=200)
> theslug = models.SlugField(prepopulate_from=('name',))
>
> class Admin:
> search_fields = ['name']
>
> def __str__(self,):
> return self.name
>
> class Choice(models.Model):
> choice = models.ForeignKey(Style,
> edit_inline=models.TABULAR,num_in_admin=5)
> size = models.IntegerField(size)
> price = models..FloatField(null=True, max_digits=12,
> decimal_places=2, blank=True)
>
> def __str__(self,):
> return str(self.choice)
>
> On May 23, 1:54 am, Greg <[EMAIL PROTECTED]> wrote:
>
>
>
> > Yea, I'm not sure why I used choice as the field name.  I probably
> > should of used style.  Anyway, here are all my models
>
> > class Size(models.Model):
> > name = models.CharField(maxlength=100)
>
> > def __str__(self,):
> > return self.name
>
> > class Admin:
> > pass
>
> > class Price(models.Model):
> > name = models.IntegerField()
>
> > def __str__(self,):
> > return str(self.name)
>
> > class Admin:
> > pass
>
> > class Style(models.Model):
> > name = models.CharField(maxlength=200)
> > theslug = models.SlugField(prepopulate_from=('name',))
>
> > class Admin:
> > search_fields = ['name']
>
> > def __str__(self,):
> > return self.name
>
> > class Choice(models.Model):
> > choice = models.ForeignKey(Style, edit_inline=models.TABULAR,
> > num_in_admin=5)
> > size = models.ForeignKey(Size, core=True)
> > price = models.ForeignKey(Price, core=True)
>
> > def __str__(self,):
> > return str(self.choice)
>
> > Again my problem is i want to know how to view all the sizes and
> > prices for a paticular rug.  In my python shell I do the following.
> > I currently have 3 sizes and prices
> > associated with style 89b, but I can't seem to figure out how to
> > access them.  a.size, a[size], etc
>
> > >>> a = Choice.objects.filter(choice=1)
> > >>> a
>
> > [, , ]
>
> > Thanks for any help
>
> > On May 22, 11:06 pm, "[EMAIL PROTECTED]"
>
> > <[EMAIL PROTECTED]> wrote:
> > > What does the model code look like for Size,Price?
>
> > > Also,
>
> > > choice = models.ForeignKey(Style,
> > > edit_inline=models.TABULAR,num_in_admin=5)
>
> > > Did you mean for that to be:
>
> > > style = models.ForeignKey(Style,
> > > edit_inline=models.TABULAR,num_in_admin=5)
>
> > > Just curious..as then it would be consistent with the other objects.
>
> > > On May 22, 12:43 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > > > Vance,
> > > > Ok...that worked.  However, I have a new problem.  I'm not sure how to
> > > > display all the sizes and colors of a particular rug.  In my shell
> > > > python I do the following
>
> > > > >>> a = Choice.objects.filter(choice=1)
> > > > >>> a
>
> > > > [, , ]
>
> > > > What do I need to type into the shell prompt to get all the sizes and
> > > > colors associated with style 89b.  I currently have 3 sizes and colors
> > > > associated with style 89b, but I can't seem to figure out how to
> > > > access them.  a.size, a[size], etc
>
> > > > Here are my model files.
>
> > > > class Style(models.Model):
> > > > name = models.CharField(maxlength=200)
> > > > theslug = models.SlugField(prepopulate_from=('name',))
>
> > > > class Admin:
> > > > search_fields = ['name']
>
> > > > def __str__(self,):
> > > > return self.name
>
> > > > class Choice(models.Model):
> > > > choice = models.ForeignKey(Style, edit_inline=models.TABULAR,
> > > > num_in_admin=5)
> > > > size = models.ForeignKey(Size, core=True)
> > > > price = models.ForeignKey(Price, core=True)
>
> > > > def __str__(self,):
> > > > return str(self.choice)
>
> > > > Thanks
>
> > > > On May 22, 2:41 am, "Vance Dubberly" <[EMAIL PROTECTED]> wrote:
>
> > > > > My bet would be that 

Re: Where did you put your homepage view?

2007-05-23 Thread Kyle Fox

> I usually make a home controller.  Then I typically use an index
> action for the home page view.

This is normally what I do as well, I just define a view called
'index' somewhere and point r'^$' at it.

But this seems like a good place for me to ask a related question I've
often puzzled over: in what module or py file does everyone else place
this view function?


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



Re: Where did you put your homepage view?

2007-05-23 Thread Kyle Fox

> I usually make a home controller.  Then I typically use an index
> action for the home page view.

This is normally what I do as well, I just define a view called
'index' somewhere and point r'^$' at it.

But this seems like a good place for me to ask a related question I've
often puzzled over: in what module or py file does everyone else place
this view function?


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



Re: Where did you put your homepage view?

2007-05-23 Thread Kyle Fox

> I usually make a home controller.  Then I typically use an index
> action for the home page view.

This is normally what I do as well, I just define a view called
'index' somewhere and point r'^$' at it.

But this seems like a good place for me to ask a related question I've
often puzzled over: in what module or py file does everyone else place
this view function?


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



Re: Generell Questions on Django

2007-05-23 Thread Jacob Kaplan-Moss

Hi Oliver --

http://en.wikipedia.org/wiki/FUD :)

Seriously, though... None of your colleagues' statements display any
actual investigation of their claims; they're all almost completely
wrong.

On 5/23/07, OliverMarchand <[EMAIL PROTECTED]> wrote:
> a) that's for websites, not serious applications

If you can explain the difference between a "website" and a "serious
application" I'll be impressed.  Django's used for external
applications by companies as large as AOL, the Washington Post and
Scripps; it's also used within corporate firewalls by Google, AMD, and
many others.

There's nothing in the tools that dictate how they're used; the level
of "seriousness" only comes from the skills of the developers.

> b) it will be slow, ORMs are always slow

WIthout benchmarks this is a meaningless claim. Yes, there's an
overhead, but I'd it's negligible compared to all the other things a
system under load needs to do. In practice, the bottleneck in a Django
site is the speed of the underlying database (and its IO systems).

Take the time you save not having to write and maintain messy SQL
queries and spend it tuning your database :)

> c) those HTML forms are too limiting

I'm not quite sure how to respond to that... This seems to be an
argument against web applications in general; Django in no way limits
your use of HTML, so if HTML is too limiting for you then stick to
desktop apps.

... but learn how to work around the limitations of HTML. Programmers
who can't develop web apps aren't going to be very employable in the
near future.

Good luck selling Django at your company; I hope my answers help.

Jacob

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



Re: Generell Questions on Django

2007-05-23 Thread Atilla

On 23/05/07, OliverMarchand <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I am new to Django (4+years Python experience) and would like to
> evaluate for my financial company whether Django may be a good
> solution to our problem of designing our applications all a-z from
> scratch. Now my colleagues first reaction was very defensive:
> a) that's for websites, not serious applications
> b) it will be slow, ORMs are always slow
> c) those HTML forms are too limiting
>
> I have the feeling that all of the above do have some truth ion them,
> but weighed against all of the beneficial factors it seems that a
> Django solution would overall be a very good idea.
>
> Now I know that my statements are very generell. I have looked at the
> list of sites and some of them are imressive enough to show some of
> what I would like to point out. But do you have any quick comments on
> these issues?
>
> thanks, Oliver

It all depends on what do you want to do. Maybe you can give us some
details - django is good, but it's not good for Everything.

a - I thought websites should be serious applications.

b - That statement is weak, many things are "slow" compared to lower
level implementation, but are a lot better in other ways. With the
hardware that "serious applications" will be running on, "slow" is a
term that does not apply. The amount of requests per second I can get
out of my django-based systems is impressive.

c - noone is forcing you to use them in the way they're defined. You
can make your own, or not use them at all, if you don't need them.

Again, it only depends on what are you trying to write.

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



Generell Questions on Django

2007-05-23 Thread OliverMarchand

Hi,

I am new to Django (4+years Python experience) and would like to
evaluate for my financial company whether Django may be a good
solution to our problem of designing our applications all a-z from
scratch. Now my colleagues first reaction was very defensive:
a) that's for websites, not serious applications
b) it will be slow, ORMs are always slow
c) those HTML forms are too limiting

I have the feeling that all of the above do have some truth ion them,
but weighed against all of the beneficial factors it seems that a
Django solution would overall be a very good idea.

Now I know that my statements are very generell. I have looked at the
list of sites and some of them are imressive enough to show some of
what I would like to point out. But do you have any quick comments on
these issues?

thanks, Oliver


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



Re: Where did you put your homepage view?

2007-05-23 Thread Greg Donald

On 5/23/07, David Larlet <[EMAIL PROTECTED]> wrote:
> I'm juste curious, where did you put your homepage view when you've
> got a project with a lot of apps? Is there a best practice here?

I usually make a home controller.  Then I typically use an index
action for the home page view.


-- 
Greg Donald
http://destiney.com/

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



Query Question ...

2007-05-23 Thread ZebZiggle

Hi all (again),

I'm hoping someone can help me with the syntax for this django
query 

I have three related tables

class User(models.Model):
# stuff ...

class Content(models.Model):
# stuff ...

class Relationship(models.Model):
user = models.ForeignKey(User)
content = models.ForeignKey(Content)
hasRead = models.BooleanField()

I want to get all the Content that the User has NOT read.

The catch:
The Relationship record between the User and the Content may not
exist. It only exists if a piece of content is actually read. If they
haven't, the record doesn't exist.

If I try:

content = Content.objects.filter(relationship_user = user,
relationship__hasRead = False)

I don't get any records. So I try to get crafty:

content = Content.objects.filter( Q(relationship__isnull = False) |
Q(relationship__hasRead = False)).filter(relationship_user = user)

has the same problem.

Looking at the raw SQL you can see the problem:

FROM "content"
INNER JOIN "relationship"
ON "content"."id" = "content__relationship"."content_id"
WHERE
"content__relationship"."id" IS NULL
OR
"content__relationship"."hasRead" = False

--and--

FROM "content"
INNER JOIN ...
WHERE
"content__relationship"."content_id" IS NULL
OR
"relationship"."hasRead" = False


well, I'm sure you see the problem. Perhaps what I need is a subquery,
but I'm not sure.

Can I phrase such a query with the django ORM?

Any suggestions?

Thanks
Sandy


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



Re: Where did you put your homepage view?

2007-05-23 Thread Julio Nobrega

  On project_name/views.py ?

  Or do you mean the html template? I usually put on the template root
dir, except for my largest project which has a sub-dir named after the
website, where I store site related stuff like TOS, privacy policy...

On 5/23/07, David Larlet <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm juste curious, where did you put your homepage view when you've
> got a project with a lot of apps? Is there a best practice here?
>
> Thanks,
> David
>
> >
>


-- 
Julio Nobrega - http://www.inerciasensorial.com.br

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



Where did you put your homepage view?

2007-05-23 Thread David Larlet

Hi,

I'm juste curious, where did you put your homepage view when you've
got a project with a lot of apps? Is there a best practice here?

Thanks,
David

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



How to delete a session

2007-05-23 Thread Ramashish Baranwal

Hi,

How can I delete the session of a request? The docs speak about using
session as a dict and setting and removing specific keys on that, but
I want to remove the session itself, something like del request.session

Any ideas?

Thanks in advance,
Ram


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



Re: Displaying my table data

2007-05-23 Thread [EMAIL PROTECTED]

Ok...then it would be soemthing like this:

choices = Choice.objects.filter(choice=1)
for choice in choices:   # you used filter, not get so I'm assuming
this is not the primary key and you are getting multiple objects back
  a.size.name
  a.price.name


However...if your size/price tables all just contain one field...maybe
you should have a model something like this..where you don't have
separate tables for size/price:

class Style(models.Model):
name = models.CharField(maxlength=200)
theslug = models.SlugField(prepopulate_from=('name',))

class Admin:
search_fields = ['name']

def __str__(self,):
return self.name

class Choice(models.Model):
choice = models.ForeignKey(Style,
edit_inline=models.TABULAR,num_in_admin=5)
size = models.IntegerField(size)
price = models..FloatField(null=True, max_digits=12,
decimal_places=2, blank=True)

def __str__(self,):
return str(self.choice)

On May 23, 1:54 am, Greg <[EMAIL PROTECTED]> wrote:
> Yea, I'm not sure why I used choice as the field name.  I probably
> should of used style.  Anyway, here are all my models
>
> class Size(models.Model):
> name = models.CharField(maxlength=100)
>
> def __str__(self,):
> return self.name
>
> class Admin:
> pass
>
> class Price(models.Model):
> name = models.IntegerField()
>
> def __str__(self,):
> return str(self.name)
>
> class Admin:
> pass
>
> class Style(models.Model):
> name = models.CharField(maxlength=200)
> theslug = models.SlugField(prepopulate_from=('name',))
>
> class Admin:
> search_fields = ['name']
>
> def __str__(self,):
> return self.name
>
> class Choice(models.Model):
> choice = models.ForeignKey(Style, edit_inline=models.TABULAR,
> num_in_admin=5)
> size = models.ForeignKey(Size, core=True)
> price = models.ForeignKey(Price, core=True)
>
> def __str__(self,):
> return str(self.choice)
>
> Again my problem is i want to know how to view all the sizes and
> prices for a paticular rug.  In my python shell I do the following.
> I currently have 3 sizes and prices
> associated with style 89b, but I can't seem to figure out how to
> access them.  a.size, a[size], etc
>
> >>> a = Choice.objects.filter(choice=1)
> >>> a
>
> [, , ]
>
> Thanks for any help
>
> On May 22, 11:06 pm, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > What does the model code look like for Size,Price?
>
> > Also,
>
> > choice = models.ForeignKey(Style,
> > edit_inline=models.TABULAR,num_in_admin=5)
>
> > Did you mean for that to be:
>
> > style = models.ForeignKey(Style,
> > edit_inline=models.TABULAR,num_in_admin=5)
>
> > Just curious..as then it would be consistent with the other objects.
>
> > On May 22, 12:43 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > > Vance,
> > > Ok...that worked.  However, I have a new problem.  I'm not sure how to
> > > display all the sizes and colors of a particular rug.  In my shell
> > > python I do the following
>
> > > >>> a = Choice.objects.filter(choice=1)
> > > >>> a
>
> > > [, , ]
>
> > > What do I need to type into the shell prompt to get all the sizes and
> > > colors associated with style 89b.  I currently have 3 sizes and colors
> > > associated with style 89b, but I can't seem to figure out how to
> > > access them.  a.size, a[size], etc
>
> > > Here are my model files.
>
> > > class Style(models.Model):
> > > name = models.CharField(maxlength=200)
> > > theslug = models.SlugField(prepopulate_from=('name',))
>
> > > class Admin:
> > > search_fields = ['name']
>
> > > def __str__(self,):
> > > return self.name
>
> > > class Choice(models.Model):
> > > choice = models.ForeignKey(Style, edit_inline=models.TABULAR,
> > > num_in_admin=5)
> > > size = models.ForeignKey(Size, core=True)
> > > price = models.ForeignKey(Price, core=True)
>
> > > def __str__(self,):
> > > return str(self.choice)
>
> > > Thanks
>
> > > On May 22, 2:41 am, "Vance Dubberly" <[EMAIL PROTECTED]> wrote:
>
> > > > My bet would be that this little bit of code right here:
>
> > > > def __str__(self,):
> > > >return self.choice
>
> > > > the return of __str__ needs to be a string not an object.
>
> > > > Vance
>
> > > > On 5/21/07, Greg <[EMAIL PROTECTED]> wrote:
>
> > > > > I am trying to display the table in my Choice table.  However it's
> > > > > error's out everytime I try to see the contents of the table.
>
> > > > > In my python shell prompt I do the following and get the error
>
> > > > > C:\django\mysite>python manage.py shell
> > > > > (InteractiveConsole)
> > > > > >>> from mysite.rugs.models import Choice
> > > > > >>> c = Choice.objects.all()
> > > > > >>> c
> > > > > Traceback (most recent call last):
> > > > >   File "", line 1, in ?
> > > > >   File "c:\Python24\lib\site-packages\django\db\models\query.py", line
> > > > > 102, 

newforms + testing

2007-05-23 Thread [EMAIL PROTECTED]

Hello,

I wrote a newforms form, but I have some problems when I want to test
the class.  Here's the definition:

def _users():
print "calling _users()"
return [(u.id, u.get_full_name()) for u in
User.objects.filter(is_active=True)]

class MemoForm(forms.Form):
body = forms.CharField(widget=forms.Textarea, required=True)
recipients = forms.MultipleChoiceField(choices=_users(),
required=True)

This works fine, however when I run my tests, _users() is called at
the very beginning, so the choices in recipients come from my
production database, not from the fixtures I wrote.  Does anyone know
how I could fix this?

Thank you,

Vincent


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



Re: Displaying my table data

2007-05-23 Thread [EMAIL PROTECTED]

Ok...then it would be soemthing like this:

choices = Choice.objects.filter(choice=1)
for choice in choices:   # you used filter, not get so I'm assuming
this is not the primary key and you are getting multiple objects back
  a.size.name
  a.price.name


However...if your size/price tables all just contain one field...maybe
you should have a model something like this..where you don't have
separate tables for size/price:

class Style(models.Model):
name = models.CharField(maxlength=200)
theslug = models.SlugField(prepopulate_from=('name',))

class Admin:
search_fields = ['name']

def __str__(self,):
return self.name

class Choice(models.Model):
choice = models.ForeignKey(Style,
edit_inline=models.TABULAR,num_in_admin=5)
size = models.IntegerField(size)
price = models..FloatField(null=True, max_digits=12,
decimal_places=2, blank=True)

def __str__(self,):
return str(self.choice)

On May 23, 1:54 am, Greg <[EMAIL PROTECTED]> wrote:
> Yea, I'm not sure why I used choice as the field name.  I probably
> should of used style.  Anyway, here are all my models
>
> class Size(models.Model):
> name = models.CharField(maxlength=100)
>
> def __str__(self,):
> return self.name
>
> class Admin:
> pass
>
> class Price(models.Model):
> name = models.IntegerField()
>
> def __str__(self,):
> return str(self.name)
>
> class Admin:
> pass
>
> class Style(models.Model):
> name = models.CharField(maxlength=200)
> theslug = models.SlugField(prepopulate_from=('name',))
>
> class Admin:
> search_fields = ['name']
>
> def __str__(self,):
> return self.name
>
> class Choice(models.Model):
> choice = models.ForeignKey(Style, edit_inline=models.TABULAR,
> num_in_admin=5)
> size = models.ForeignKey(Size, core=True)
> price = models.ForeignKey(Price, core=True)
>
> def __str__(self,):
> return str(self.choice)
>
> Again my problem is i want to know how to view all the sizes and
> prices for a paticular rug.  In my python shell I do the following.
> I currently have 3 sizes and prices
> associated with style 89b, but I can't seem to figure out how to
> access them.  a.size, a[size], etc
>
> >>> a = Choice.objects.filter(choice=1)
> >>> a
>
> [, , ]
>
> Thanks for any help
>
> On May 22, 11:06 pm, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > What does the model code look like for Size,Price?
>
> > Also,
>
> > choice = models.ForeignKey(Style,
> > edit_inline=models.TABULAR,num_in_admin=5)
>
> > Did you mean for that to be:
>
> > style = models.ForeignKey(Style,
> > edit_inline=models.TABULAR,num_in_admin=5)
>
> > Just curious..as then it would be consistent with the other objects.
>
> > On May 22, 12:43 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > > Vance,
> > > Ok...that worked.  However, I have a new problem.  I'm not sure how to
> > > display all the sizes and colors of a particular rug.  In my shell
> > > python I do the following
>
> > > >>> a = Choice.objects.filter(choice=1)
> > > >>> a
>
> > > [, , ]
>
> > > What do I need to type into the shell prompt to get all the sizes and
> > > colors associated with style 89b.  I currently have 3 sizes and colors
> > > associated with style 89b, but I can't seem to figure out how to
> > > access them.  a.size, a[size], etc
>
> > > Here are my model files.
>
> > > class Style(models.Model):
> > > name = models.CharField(maxlength=200)
> > > theslug = models.SlugField(prepopulate_from=('name',))
>
> > > class Admin:
> > > search_fields = ['name']
>
> > > def __str__(self,):
> > > return self.name
>
> > > class Choice(models.Model):
> > > choice = models.ForeignKey(Style, edit_inline=models.TABULAR,
> > > num_in_admin=5)
> > > size = models.ForeignKey(Size, core=True)
> > > price = models.ForeignKey(Price, core=True)
>
> > > def __str__(self,):
> > > return str(self.choice)
>
> > > Thanks
>
> > > On May 22, 2:41 am, "Vance Dubberly" <[EMAIL PROTECTED]> wrote:
>
> > > > My bet would be that this little bit of code right here:
>
> > > > def __str__(self,):
> > > >return self.choice
>
> > > > the return of __str__ needs to be a string not an object.
>
> > > > Vance
>
> > > > On 5/21/07, Greg <[EMAIL PROTECTED]> wrote:
>
> > > > > I am trying to display the table in my Choice table.  However it's
> > > > > error's out everytime I try to see the contents of the table.
>
> > > > > In my python shell prompt I do the following and get the error
>
> > > > > C:\django\mysite>python manage.py shell
> > > > > (InteractiveConsole)
> > > > > >>> from mysite.rugs.models import Choice
> > > > > >>> c = Choice.objects.all()
> > > > > >>> c
> > > > > Traceback (most recent call last):
> > > > >   File "", line 1, in ?
> > > > >   File "c:\Python24\lib\site-packages\django\db\models\query.py", line
> > > > > 102, 

Re: Displaying my table data

2007-05-23 Thread [EMAIL PROTECTED]

Ok...then it would be soemthing like this:

choices = Choice.objects.filter(choice=1)
for choice in choices:   # you used filter, not get so I'm assuming
this is not the primary key and you are getting multiple objects back
  a.size.name
  a.price.name


However...if your size/price tables all just contain one field...maybe
you should have a model something like this..where you don't have
separate tables for size/price:

class Style(models.Model):
name = models.CharField(maxlength=200)
theslug = models.SlugField(prepopulate_from=('name',))

class Admin:
search_fields = ['name']

def __str__(self,):
return self.name

class Choice(models.Model):
choice = models.ForeignKey(Style,
edit_inline=models.TABULAR,num_in_admin=5)
size = models.IntegerField(size)
price = models..FloatField(null=True, max_digits=12,
decimal_places=2, blank=True)

def __str__(self,):
return str(self.choice)

On May 23, 1:54 am, Greg <[EMAIL PROTECTED]> wrote:
> Yea, I'm not sure why I used choice as the field name.  I probably
> should of used style.  Anyway, here are all my models
>
> class Size(models.Model):
> name = models.CharField(maxlength=100)
>
> def __str__(self,):
> return self.name
>
> class Admin:
> pass
>
> class Price(models.Model):
> name = models.IntegerField()
>
> def __str__(self,):
> return str(self.name)
>
> class Admin:
> pass
>
> class Style(models.Model):
> name = models.CharField(maxlength=200)
> theslug = models.SlugField(prepopulate_from=('name',))
>
> class Admin:
> search_fields = ['name']
>
> def __str__(self,):
> return self.name
>
> class Choice(models.Model):
> choice = models.ForeignKey(Style, edit_inline=models.TABULAR,
> num_in_admin=5)
> size = models.ForeignKey(Size, core=True)
> price = models.ForeignKey(Price, core=True)
>
> def __str__(self,):
> return str(self.choice)
>
> Again my problem is i want to know how to view all the sizes and
> prices for a paticular rug.  In my python shell I do the following.
> I currently have 3 sizes and prices
> associated with style 89b, but I can't seem to figure out how to
> access them.  a.size, a[size], etc
>
> >>> a = Choice.objects.filter(choice=1)
> >>> a
>
> [, , ]
>
> Thanks for any help
>
> On May 22, 11:06 pm, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > What does the model code look like for Size,Price?
>
> > Also,
>
> > choice = models.ForeignKey(Style,
> > edit_inline=models.TABULAR,num_in_admin=5)
>
> > Did you mean for that to be:
>
> > style = models.ForeignKey(Style,
> > edit_inline=models.TABULAR,num_in_admin=5)
>
> > Just curious..as then it would be consistent with the other objects.
>
> > On May 22, 12:43 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > > Vance,
> > > Ok...that worked.  However, I have a new problem.  I'm not sure how to
> > > display all the sizes and colors of a particular rug.  In my shell
> > > python I do the following
>
> > > >>> a = Choice.objects.filter(choice=1)
> > > >>> a
>
> > > [, , ]
>
> > > What do I need to type into the shell prompt to get all the sizes and
> > > colors associated with style 89b.  I currently have 3 sizes and colors
> > > associated with style 89b, but I can't seem to figure out how to
> > > access them.  a.size, a[size], etc
>
> > > Here are my model files.
>
> > > class Style(models.Model):
> > > name = models.CharField(maxlength=200)
> > > theslug = models.SlugField(prepopulate_from=('name',))
>
> > > class Admin:
> > > search_fields = ['name']
>
> > > def __str__(self,):
> > > return self.name
>
> > > class Choice(models.Model):
> > > choice = models.ForeignKey(Style, edit_inline=models.TABULAR,
> > > num_in_admin=5)
> > > size = models.ForeignKey(Size, core=True)
> > > price = models.ForeignKey(Price, core=True)
>
> > > def __str__(self,):
> > > return str(self.choice)
>
> > > Thanks
>
> > > On May 22, 2:41 am, "Vance Dubberly" <[EMAIL PROTECTED]> wrote:
>
> > > > My bet would be that this little bit of code right here:
>
> > > > def __str__(self,):
> > > >return self.choice
>
> > > > the return of __str__ needs to be a string not an object.
>
> > > > Vance
>
> > > > On 5/21/07, Greg <[EMAIL PROTECTED]> wrote:
>
> > > > > I am trying to display the table in my Choice table.  However it's
> > > > > error's out everytime I try to see the contents of the table.
>
> > > > > In my python shell prompt I do the following and get the error
>
> > > > > C:\django\mysite>python manage.py shell
> > > > > (InteractiveConsole)
> > > > > >>> from mysite.rugs.models import Choice
> > > > > >>> c = Choice.objects.all()
> > > > > >>> c
> > > > > Traceback (most recent call last):
> > > > >   File "", line 1, in ?
> > > > >   File "c:\Python24\lib\site-packages\django\db\models\query.py", line
> > > > > 102, 

Re: Displaying my table data

2007-05-23 Thread [EMAIL PROTECTED]

Ok...then it would be soemthing like this:

choices = Choice.objects.filter(choice=1)
for choice in choices:   # you used filter, not get so I'm assuming
this is not the primary key and you are getting multiple objects back
  a.size.name
  a.price.name


However...if your size/price tables all just contain one field...maybe
you should have a model something like this..where you don't have
separate tables for size/price:

class Style(models.Model):
name = models.CharField(maxlength=200)
theslug = models.SlugField(prepopulate_from=('name',))

class Admin:
search_fields = ['name']

def __str__(self,):
return self.name

class Choice(models.Model):
choice = models.ForeignKey(Style,
edit_inline=models.TABULAR,num_in_admin=5)
size = models.IntegerField(size)
price = models..FloatField(null=True, max_digits=12,
decimal_places=2, blank=True)

def __str__(self,):
return str(self.choice)

On May 23, 1:54 am, Greg <[EMAIL PROTECTED]> wrote:
> Yea, I'm not sure why I used choice as the field name.  I probably
> should of used style.  Anyway, here are all my models
>
> class Size(models.Model):
> name = models.CharField(maxlength=100)
>
> def __str__(self,):
> return self.name
>
> class Admin:
> pass
>
> class Price(models.Model):
> name = models.IntegerField()
>
> def __str__(self,):
> return str(self.name)
>
> class Admin:
> pass
>
> class Style(models.Model):
> name = models.CharField(maxlength=200)
> theslug = models.SlugField(prepopulate_from=('name',))
>
> class Admin:
> search_fields = ['name']
>
> def __str__(self,):
> return self.name
>
> class Choice(models.Model):
> choice = models.ForeignKey(Style, edit_inline=models.TABULAR,
> num_in_admin=5)
> size = models.ForeignKey(Size, core=True)
> price = models.ForeignKey(Price, core=True)
>
> def __str__(self,):
> return str(self.choice)
>
> Again my problem is i want to know how to view all the sizes and
> prices for a paticular rug.  In my python shell I do the following.
> I currently have 3 sizes and prices
> associated with style 89b, but I can't seem to figure out how to
> access them.  a.size, a[size], etc
>
> >>> a = Choice.objects.filter(choice=1)
> >>> a
>
> [, , ]
>
> Thanks for any help
>
> On May 22, 11:06 pm, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > What does the model code look like for Size,Price?
>
> > Also,
>
> > choice = models.ForeignKey(Style,
> > edit_inline=models.TABULAR,num_in_admin=5)
>
> > Did you mean for that to be:
>
> > style = models.ForeignKey(Style,
> > edit_inline=models.TABULAR,num_in_admin=5)
>
> > Just curious..as then it would be consistent with the other objects.
>
> > On May 22, 12:43 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > > Vance,
> > > Ok...that worked.  However, I have a new problem.  I'm not sure how to
> > > display all the sizes and colors of a particular rug.  In my shell
> > > python I do the following
>
> > > >>> a = Choice.objects.filter(choice=1)
> > > >>> a
>
> > > [, , ]
>
> > > What do I need to type into the shell prompt to get all the sizes and
> > > colors associated with style 89b.  I currently have 3 sizes and colors
> > > associated with style 89b, but I can't seem to figure out how to
> > > access them.  a.size, a[size], etc
>
> > > Here are my model files.
>
> > > class Style(models.Model):
> > > name = models.CharField(maxlength=200)
> > > theslug = models.SlugField(prepopulate_from=('name',))
>
> > > class Admin:
> > > search_fields = ['name']
>
> > > def __str__(self,):
> > > return self.name
>
> > > class Choice(models.Model):
> > > choice = models.ForeignKey(Style, edit_inline=models.TABULAR,
> > > num_in_admin=5)
> > > size = models.ForeignKey(Size, core=True)
> > > price = models.ForeignKey(Price, core=True)
>
> > > def __str__(self,):
> > > return str(self.choice)
>
> > > Thanks
>
> > > On May 22, 2:41 am, "Vance Dubberly" <[EMAIL PROTECTED]> wrote:
>
> > > > My bet would be that this little bit of code right here:
>
> > > > def __str__(self,):
> > > >return self.choice
>
> > > > the return of __str__ needs to be a string not an object.
>
> > > > Vance
>
> > > > On 5/21/07, Greg <[EMAIL PROTECTED]> wrote:
>
> > > > > I am trying to display the table in my Choice table.  However it's
> > > > > error's out everytime I try to see the contents of the table.
>
> > > > > In my python shell prompt I do the following and get the error
>
> > > > > C:\django\mysite>python manage.py shell
> > > > > (InteractiveConsole)
> > > > > >>> from mysite.rugs.models import Choice
> > > > > >>> c = Choice.objects.all()
> > > > > >>> c
> > > > > Traceback (most recent call last):
> > > > >   File "", line 1, in ?
> > > > >   File "c:\Python24\lib\site-packages\django\db\models\query.py", line
> > > > > 102, 

HTTP_X_FORWARDED_FOR on HTTPS connections?

2007-05-23 Thread Leandro Zanuz


Hi Everybody.

There is a way to take HTTP_X_FORWARDED_FOR (the real ip) on HTTPS 
connections?

Thanks
Leandro Zanuz

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



Re: Is it essential to run setup.py?

2007-05-23 Thread Thomas Ashelford


On May 23, 9:47 pm, Daniel Ellison <[EMAIL PROTECTED]> wrote:
> Remember that the paths have to point to the directory in which each Python
> module lives. So inside the "django" directory there is another "django"
> directory which is the actual module that gets imported.
>
> Dan

On May 23, 4:17 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> So it should have a "django/" directory inside it and you would need to
> adjust the Pythonpath to point to /what/ever/dir/Django-0.96/ (you are
> putting Django-0.96/ on the path, too, right? Not stopping one directory
> too soon?)

You have given me a 'doh' moment. I should have figured that out for
myself, but all this has given me a much better understanding of how
Python path works - it was always one of those things I sort-of got
but never really paid enough attention to. Thanks for your help.

Thomas


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



problem with admin look and feel also with dojo

2007-05-23 Thread [EMAIL PROTECTED]

hi i am new to this group
i have installed apache2 and django 0.96 with mysql. i have a small
application installed with this setup. now when i start admin page it
shows plain page without any look and feel. i can see it with django
internal server. i read previous article on it and made some changes
but still does not work.  other things are working just fine. my
configuration is as follows:

lines added in httpd.conf file

Alias /media/ "/usr/local/lib/python2.5/site-packages/django/contrib/
admin/media/"


Order Deny,Allow
Allow from all


remaining is same

settings.py and urls.py is set according to django official guide as
things are working with django internal server

access_log shows
127.0.0.1 - - [23/May/2007:07:09:55 -0500] "GET /admin HTTP/1.1" 301
- this line appears only once when i make some change in
httpd.conf
127.0.0.1 - - [23/May/2007:07:09:55 -0500] "GET /admin/ HTTP/1.1" 200
1620
127.0.0.1 - - [23/May/2007:07:09:56 -0500] "GET /media/css/login.css
HTTP/1.1" 404 2647

yes one more thing i would like to add is previous http status code
was of access denied  unauthorized access 401 before i made above
changes to httpd.conf. if it was unauthorized then how come it went
missing after these changes and if i comment above changes it still
shows 404 instead of 401.

i have also have dojo installed and when i called dojo without any
changes to httpd.conf it was showing 401. now after those changes it
is saying 200 OK. also if i remove those changes from httpd.conf it
still says 200 OK. very strange. i am restarting apache all the time i
make changes. even i tried restarting computer but nothing.

i am using dojo as follows:


  






  dojo.require("dojo.event.*");
  dojo.require("dojo.widget.*");
  dojo.require("dojo.widget.Button");

  function helloPressed()
  {
alert('You pressed the button');
  }

  function init()
  {
var helloButton = dojo.widget.byId('helloButton');
dojo.event.connect(helloButton, 'onClick', 'helloPressed')
  }

  dojo.addOnLoad(init);


  
  
Hello World!



with
Alias /media/ "/usr/local/lib/python2.5/site-packages/django/contrib/
admin/media/"
in httpd.conf

it is loading but not working having following error in javascript
console
No. 1
Error: missing } in XML expression
Source File: http://localhost/test/media/js/dojo/dojo.js
alert ('You pressed the button');
and No 2
Error: dojo is not defined
Source File: http://localhost/test/

help on these above topics is required as soon as possible

thanks in advance

Dushyant


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



Re: need to know to learn django

2007-05-23 Thread Anthony DROGON

Gigs_ a écrit :
> What I need to know to learn django, except python(HTML, javascript,
> sql, etc)?
>
> thanks
>
>
> >
>   
Hi Gigs_,

HTML, Javascript, and even CSS, are things you need to know to develop 
static web pages.
Django will, then, allow you to have your pages dynamic.
But you cannot avoid static bases (start with HTML and CSS, as 
Javascript might be useless for what you want).

Since Django has got its own database API, you don't need to know SQL to 
use it.

Anthony.

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



Advice on Date-Based Generic Views

2007-05-23 Thread Justin

I'm looking for some advice on what date-based generic view (or a
custom view) is best for this situation:

I have a model in my app called 'Meeting', which contains a
meeting_date field.  The meetings are monthly, so what I would like to
setup the URLs like this:
#1   /meetings/
#2   /meetings/2007/
#3   /meetings/2007/may/

For #2, I'm using the 'year_archive' generic view.

For #3, I'm thinking about using the object_detail generic view, but
I'm not sure how to use the abbreviated month name, rather than the
month number.  Any ideas?

#1 is the one that I really need help with.  I want #1 to always point
to the next meeting.  So if the next meeting_date (after today) is
2007-05-25 I want "/meetings/" to be the same as "/meetings/2007/
may/".  What is the best way to achieve this?  I'd prefer not to just
redirect to the appropriate month, but I would like to use the same
template for the meeting details in #1 & #3.  I came up with a few
options that might work:

a. Use the 'archive_index' generic view with num_latest=1 and
allow_future=True.  The downside to this is that archive_index will
return the meeting in the 'latest' list in the template context AND
meetings would have to be entered each month after the previous
meeting (so the latest meeting is correct).  This latter one is not a
big deal, because some of the fields in Meeting cannot be populated
until after the previous meeting.  Is there an easy way to alias the
one object in 'latest' so that it will work with my
meeting_detail.html template?

b. Use the 'object_detail' for #1, but pass it
Meeting.objects.latest('pub_date').id as the object_id.  This is what
I am currently using, but my question is, does this hit the database
twice?  Once to get the latest object, and then again in
'object_detail' view? SimiIar to (a), I think this one also suffers
from having to enter the meetings after the previous meeting.

c. Write a custom view that determines the next meeting and returns a
context similar to 'object_detail' so I can use the same template both
places.


Justin


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



  1   2   >