Re: Django Powered Tabblo to be acquired by HP

2007-04-03 Thread bedros

nice work; I've always been impressed by Django; and Tabblo website
gives a more convincing reason to use Django.

But, I'm still not sure on javascript/ajax library to use with
Django... so my question which ajax kit did you use with Tabblo.

Thanks,

-Bedros

On Mar 23, 11:20 am, Ned Batchelder <[EMAIL PROTECTED]> wrote:
> We atTabbloare of course very excited about the acquisition by HP.
> One of the things that HP valued inTabblowas our ability to innovate
> quickly and deliver solid products in a short amount of time.  We
> definitely feel like Django was one of the reasons we were able to do
> that, and to make such an impression on HP.
>
> So thanks a bunch to the entire Django community.  You were part of our
> success.  We'll be continuing with Django inside HP.  Here's to more
> successes in the future!
>
> --Ned.
>
>
>
> Mitja wrote:
> > Just for the records: HP has revealed plans to acquireTabblo
>
> > Vyomesh Joshi, EVP at HP said: "By acquiringTabblo'stechnology and
> > making it available to companies that host popular websites, HP will
> > be firmly on the path to becoming the print engine of the web."
>
> > As Ned Batchelder wrote, acquiring technology was not the point.
> > Instead it was the creative solution they made: "...HP was excited by
> > what we created..."
>
> > It's interesting to hear that Django with it's background in
> > traditional press industry will be part of a big effort for becoming
> > the "print engine for the web".
>
> >http://go.theregister.com/feed/http://www.theregister.co.uk/2007/03/2...
> >http://www.nedbatchelder.com/blog/200703.html#e20070322T091142
> >http://www.hp.com/hpinfo/newsroom/press/2007/070322a.html
>
> --
> Ned Batchelder,http://nedbatchelder.com


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



Re: Using url in a view

2007-04-03 Thread Malcolm Tredinnick

On Tue, 2007-04-03 at 21:21 -0500, Chris Moffitt wrote:
> 
> Malcolm,
> 
> Thanks for the speedy response.  Upon further reflection, I'm thinking I'd
> like to do something like:
> 
> reverse(request.path)
> 
> Will that return the name of the view?  In this case, 'full-archive'

Oh, I see what you're asking now. There's no built-in way to do that. 

Regards,
Malcolm


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



Re: loaddata against postgresql doesn't update primary key's sequence 'last_value' ?

2007-04-03 Thread Russell Keith-Magee

On 4/4/07, Jon Ballard <[EMAIL PROTECTED]> wrote:
>
> Hello everybody, I'm new.  Django is the bomb.. my app is coming
> together quickly.

Glad you like it.

> Anyone have any ideas?  Am I doing something wrong perhaps?  Thanks
> for any help.

I don't think you're doing anything wrong - I've had similar comments
made to me privately by some of my work colleagues. I haven't had a
chance to look into the issue yet.

> I'll continue to research of course..

If you find out anything, feel free to let me know. In the meantime,
I've opened ticket #3915 to track the problem.

Yours,
Russ Magee %-)

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



Re: Using url in a view

2007-04-03 Thread Chris Moffitt


Malcolm,

Thanks for the speedy response.  Upon further reflection, I'm thinking I'd
like to do something like:

reverse(request.path)

Will that return the name of the view?  In this case, 'full-archive'

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



loaddata against postgresql doesn't update primary key's sequence 'last_value' ?

2007-04-03 Thread Jon Ballard

Hello everybody, I'm new.  Django is the bomb.. my app is coming
together quickly.

Now to my issue..

I dumped my database to json and tried to ingest it back in.  Seemed
to work fine at first -- everything was there -- but it turns out no
new records can be added because the sequence field 'last_value' for
all the auto primary keys was left at 1, despite many records being
added to the respective tables.  Now I tend to think this might
actually be an issue with Psycopg, but why would it manifest itself
only when using loaddata?

My setup:
Django 0.96
Ubuntu 6.10 (Edgy)
PostgreSQL 8.1.8-0ubuntu6.10
Psycopg 1.1.21-7

This is the error when trying to add a new record:
IntegrityError at /admin/spots/spot/add/
ERROR: duplicate key violates unique constraint "spots_spot_pkey"
INSERT INTO "spots_spot"

Anyone have any ideas?  Am I doing something wrong perhaps?  Thanks
for any help.

I'll continue to research of course..

-Jon


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Ordered list of objects?

2007-04-03 Thread Nathan R. Yergler

I'm working on an app for a client, and one of the requirements is
that they be able to re-order objects in the admin interface.  I know
exactly how I'd do with with an object database, but the ideas I've
come up with for doing it with Django all involve using some tracking
field, and then updating that to contain the relative order of
objects.

So... am I missing something obvious here that will let me do with
with a minimal amount of pain?

Thanks,

Nathan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Using url in a view

2007-04-03 Thread Malcolm Tredinnick

Hi Chris,

On Tue, 2007-04-03 at 20:27 -0500, Chris Moffitt wrote:
> Is there a way to access a named url from within a view?
> 
> For example,
> 
> Using this as a reference-
> http://www.djangoproject.com/documentation/url_dispatch/
> 
> say, I have this url:
> url(r'/archive/(\d{4})/$', archive, name="full-archive")
> 
> and access it like this in a template:
> {% url full-archive 1945 %}
> 
> Is there a way i could access it in a view?
> 
> def archive(request):
> Some code to access which named url here
> 
> Basically, I'd like to access the value "full-archive" while in the
> archive view.
> 
> Does this make sense?  If so, is this possible?

The "url" template tag is a wrapper around
django.core.urlresovers.reverse(). So you can call reverse directly and
pass in the URL pattern's name rather than the view name if you like.

The equivalent of the above example in a Python function would be:

reverse('full-archive', args=(1945,))

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



Using url in a view

2007-04-03 Thread Chris Moffitt

Is there a way to access a named url from within a view?

For example,

Using this as a reference-
http://www.djangoproject.com/documentation/url_dispatch/

say, I have this url:
url(r'/archive/(\d{4})/$', archive, name="full-archive")

and access it like this in a template:
{% url full-archive 1945 %}

Is there a way i could access it in a view?

def archive(request):
Some code to access which named url here

Basically, I'd like to access the value "full-archive" while in the
archive view.

Does this make sense?  If so, is this possible?

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



Django Job at WeFi

2007-04-03 Thread Pablos

Hopefully it is copacetic to post jobs to this list, I'm stoked to be
creating Django jobs!

About Me

I'm Pablos, and I'm looking for coders for my team.  You will talk to
me about this job, not a recruiter.  If this doesn't sound like the
job for you, please introduce me to the most stellar coders you've
ever worked with.  Email me directly:  [EMAIL PROTECTED]

About Us

Who really cares about Enterprise B2B Solutions crap?  Come help us
build something actual people can use.  We are a startup getting close
to launching the first version of our product which makes using Wi-Fi
a lot easier and more useful.  We are based in the Bay Area with an
R team in Tel Aviv.  We are starting a new web development group in
the U.S. and need some stellar talent.  Our front end stuff is written
in Python using Django.

About You

This will be a small team, and each member will have to be very
experienced with building and deploying web applications.  You've
written other software, but mostly web apps, probably with Java.  You
wish your garbage collector would free PHP once and for all.  You've
checked out Rails or Django and have maybe even used one of them for a
project or two.  The idea of building entirely new apps from scratch
in a very "agile" fashion sounds delightful.

Ideal Qualifications

3+ years developing web apps in an object oriented framework,
preferably with some Java.
MySQL, Python, Django, Linux, & Subversion fu.
AJAX, HTML, CSS, XML, REST, SOAP, ABCs, 123s, 000110, F=MA

This is a job for someone who is highly capable of taking a project
and running with it.  You need to be able to handle the full life
cycle of an application.  You will need great communication skills,
self motivation, and a burning desire to ship code.

Location:  West Coast, but we're flexible.

Compensation:  Competitive Salary, Health Insurance, Stock Options


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Curious error with Session Variables

2007-04-03 Thread Kenneth Gonsalves


On 03-Apr-07, at 11:06 PM, Ramdas S wrote:

> Looks like your browser isn't configured to accept cookies. Please  
> enable cookies, reload this page, and try again.
>
>
> Later if I persist
>
> I get this error

one person on irc was getting this - he solved it by physically  
restarting apache - he was relying on the autoreload of mod_python

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: object_list || didn't return an HttpResponse object

2007-04-03 Thread Forest Bond
On Tue, Apr 03, 2007 at 04:42:58PM -0700, TaMeR wrote:
> On Apr 3, 7:10 pm, Forest Bond <[EMAIL PROTECTED]> wrote:
> > The way your view is written, if the user is not authenticated, no
> > HttpResponse is returned (since no return statement is executed).  You
> > probably want to just raise Http404 in that case.
> I am not sure what you mean
> I have a HttpResponseRedirect if the user is not authenticated.
> This error happens with an authenticated user.
> If the user is not authenticated he/she gets redirected to the login
> page and that works fine.
> See:
> if not request.user.is_authenticated():
> return HttpResponseRedirect('/account/login/?next=%s' %
> request.path)

Oh, you're right.

But, all of your other code is also in that if block.  So if the user is
authenticated, the view doesn't return anything.

Looks like you just have an indentation problem.  Remember, Python code is
whitespace-sensitive.

-Forest


signature.asc
Description: Digital signature


Re: edit_inline causing problems with multiple relations

2007-04-03 Thread Malcolm Tredinnick

On Tue, 2007-04-03 at 07:24 -0700, mh wrote:
> I have two models that (simplified) look like this;
> 
> class List(models.Model):
>  name =models.CharField(maxlength=128)
>  class Admin:
>   pass
> 
> class Entry(models.Model):
>  name = models.CharField(maxlength=128, core=True)
>  list = models.ForeignKey(List, edit_inline=models.TABULAR)
>  to = models.ForeignKey(List, null=True, blank=True,
> related_name='to')
> 
> This doesn't seem to be working ('bool' object is not callable); any
> suggestions on how I could fix it?

I thought we fixed this a bit before 0.96 was released. Are you using
the latest release or some older code?

Regards,
Malcolm



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



Re: newforms and form_from_instance

2007-04-03 Thread Luciano Adamiak
Gary,

after some testing I came to this solution:

I created my own form_for_instance function like this:

def form_for_instance(instance):
f = forms.models.form_for_instance(instance=instance, form=MyCustomForm)

f.base_fields['email'].initial=instance.email
...
f.base_fields['senha'].initial=instance.senha

return f()

So... if I need a form for an instance it uses the
forms.models.form_for_instance using MyCustomForm, then I create an instance
of this form and set the initials in the fields.

I know it's not smart, but it works..




On 4/3/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
> >From what I remember you do:
>
> def myformcallback(f, **args):
> exclude = ['author']
> if f.name in exclude:
> return None
> return f.formfield(**args)
>
> MyForm = form_for_instance(book, formfield_callback=myformcallback)
>
> if request.POST:
> form = MyForm(request.POST)
> form.save()
> else:
> form = MyForm()
>
> I found it much easier to just bite the bullet and pretend
> form_for_model and form_for_instance don't exist.   It's more work
> initially, but it's clear.
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: edit_inline causing problems with multiple relations

2007-04-03 Thread Russell Keith-Magee

On 4/3/07, mh <[EMAIL PROTECTED]> wrote:
>
> This doesn't seem to be working ('bool' object is not callable); any
> suggestions on how I could fix it?

I can't see anything immediately wrong with your model - however, the
error you are reporting sounds like a known problem with the
manipulators and edit_inline. I can't remember the ticket number of
the top of my head, but I do know that problems with edit_inline and
manipulators is one of the many reasons that we are introducing
newforms.

> While at it I might as well ask a second question;
> Each entry can reference either another list, or something else. Is
> there any way to construct a foreign key from two fields (and have it
> work in the admin if possible)? My current solution is to have
> multiple foreign keys of which one is active and the others are null -
> works but feels somewhat ugly ;).

GenericRelations exist for this kind of relationship. GenericRelations
aren't completely stable or documented, and they aren't fully
supported in the Admin, but they do work reasonably well, and there
are some examples of their use at:

http://www.djangoproject.com/documentation/models/generic_relations/

Yours,
Russ Magee %-)

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



Re: object_list || didn't return an HttpResponse object

2007-04-03 Thread TaMeR



On Apr 3, 7:10 pm, Forest Bond <[EMAIL PROTECTED]> wrote:
> On Tue, Apr 03, 2007 at 03:46:04PM -0700, TaMeR wrote:
> > This used to work and I must have done something to break the code.
> > The simple page view still works fine but the list view gives me this
> > error and I been through my code a million times and can't find
> > anything wrong with it.
>
> The way your view is written, if the user is not authenticated, no 
> HttpResponse
> is returned (since no return statement is executed).  You probably want to 
> just
> raise Http404 in that case.
>
> -Forest
>
>  signature.asc
> 1KDownload

I am not sure what you mean
I have a HttpResponseRedirect if the user is not authenticated.
This error happens with an authenticated user.
If the user is not authenticated he/she gets redirected to the login
page and that works fine.
See:
if not request.user.is_authenticated():
return HttpResponseRedirect('/account/login/?next=%s' %
request.path)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: object_list || didn't return an HttpResponse object

2007-04-03 Thread Forest Bond
On Tue, Apr 03, 2007 at 03:46:04PM -0700, TaMeR wrote:
> This used to work and I must have done something to break the code.
> The simple page view still works fine but the list view gives me this
> error and I been through my code a million times and can't find
> anything wrong with it.

The way your view is written, if the user is not authenticated, no HttpResponse
is returned (since no return statement is executed).  You probably want to just
raise Http404 in that case.

-Forest


signature.asc
Description: Digital signature


ifchanged

2007-04-03 Thread Rob Slotboom

Within a template I want to use the folowing construction.

  {% for item in object_list reversed %}
 {% ifchanged %}
{% if not forloop.first %}{% endif %}
{{ item.pub_date|
date:"F" }}

 {% endifchanged %}
 {{ item.title }}
 {% if forloop.last %}{% endif %}
  {% endfor %}

It will generate
2007

march
february

2006

december etc

I run in to problems because of the "if" statement within the
ifchanged tag.

Any ideas

Rob


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



object_list || didn't return an HttpResponse object

2007-04-03 Thread TaMeR


This used to work and I must have done something to break the code.
The simple page view still works fine but the list view gives me this
error and I been through my code a million times and can't find
anything wrong with it.

= ERROR =
ValueError at /bbauction/events_list/1/
The view bbauction.views.events_list didn't return an HttpResponse
object.
Request Method: GET
Request URL:http://127.0.0.1:8000/bbauction/events_list/1/
Exception Type: ValueError
Exception Value:The view bbauction.views.events_list didn't return
an HttpResponse object.
Exception Location: /usr/lib/python2.4/site-packages/django/core/
handlers/base.py in get_response, line 94

= VIEW CODE =
from django.confimport settings
from django.contrib.auth.models import User
from django.shortcuts   import render_to_response
from django.httpimport HttpResponseRedirect
from bbauction.models   import *

def events_list(request, pagination_id):
if not request.user.is_authenticated():
return HttpResponseRedirect('/account/login/?next=%s' %
request.path)

from django.views.generic.list_detail import object_list
#events = Event.objects.all().values('id', 'name', 'postcode',
'start', 'vehicle').order_by('-start')
events = Event.objects.all().order_by('-start')
if len(events) == 0:
return render_to_response('bbauction/events_list.html', {'sid':
settings.SITE_ID})
return object_list(request, events, paginate_by = 30, page =
pagination_id, template_name = 'bbauction/events_list.html',
extra_context={'sid': settings.SITE_ID})

= URL CODE =
urlpatterns = patterns('bbauction',
(r'^events_list/(?P(\d+))/$', 'views.events_list'),
(r'^event_view/(?P(\d+))/$', 'views.event_view'),
)

= THE END =

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: newforms and form_from_instance

2007-04-03 Thread dballanc

>From what I remember you do:

def myformcallback(f, **args):
exclude = ['author']
if f.name in exclude:
return None
return f.formfield(**args)

MyForm = form_for_instance(book, formfield_callback=myformcallback)

if request.POST:
form = MyForm(request.POST)
form.save()
else:
form = MyForm()

I found it much easier to just bite the bullet and pretend
form_for_model and form_for_instance don't exist.   It's more work
initially, but it's clear.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: request object out of a view (I need to access session['data'])

2007-04-03 Thread Karen Tracey
I'll try to elaborate what James said.  (Did you consult the documentation
links he pointed to?  They detail how you get the request object accessible
in your templates, and thus your custom template tag.)

In order to get access to the request object in your custom template tag,
you must make some code changes elsewhere.  First you must include '
django.core.context_processors.request' in your TEMPLATE_CONTEXT_PROCESSORS
in settings.py.  Second, in the view that initially handles the request, you
must pass a RequestContext (instead of a plain old Context) to your call to
render_to_response.  Then, your template context will contain a variable
'request' that you can pass on to your custom template tag.  You can do this
either by passing it in as another argument ({% menu position request %}
instead of just {% menu position %}) or you could investigate using the
takes_context=True parameter on your register.inclusion_tag.

Basically you have to go all the way back to the view that initially handles
the request in order make sure that the request object continues to be
accessible in your templates and in the custom template tag you have
created.

Hope this helps,
Karen

On 4/3/07, Grupo Django <[EMAIL PROTECTED]> wrote:
>
>
> I don't know if I didn't understand you or if I you didn't don't
> understand me :-)
> Not sure abou what you are saying, I think I can't use it to make the
> template tag work.
> The template tag doesn't use a view to render the content, so it
> doesn't get the request object as a parameter.
> This is the code of the template tag:
>
> --
> register = template.Library()
> def menu(position):
>
> data = request.session["stored_data"]
> ...
> return {'output': output,}
>
> register.inclusion_tag('menu/menu.html')(bloque_menu)
>
> --
>
> So I need to read into data the data that is stored in the session.
> But the request object is not accessible.
> Sorry, I didn't understand what you wrote very good.
> Thank you.
>
>
>
>
>
>
> On 3 abr, 23:37, "James Bennett" <[EMAIL PROTECTED]> wrote:
> > On 4/3/07, Grupo Django <[EMAIL PROTECTED]> wrote:
> >
> > > Inside the custom template tag, I don't get the request object since
> > > it's not a view.
> >
> > Look into using RequestContext[1] in your views (generic views all use
> > it automatically), and enabling the "request" context processor[2].
> > This will make the variable "request" -- containing the HttpRequest
> > object -- available in template contexts, so in your tag's 'render'
> > method you could access it by doing something like:
> >
> > def render(self, context);
> > request = template.resolve_variable('request', context)
> > ...do stuff with the request...
> >
> >
> [1]http://www.djangoproject.com/documentation/templates_python/#subclass...
> >
> [2]http://www.djangoproject.com/documentation/templates_python/#django-c...
> >
> > --
> > "Bureaucrat Conrad, you are technically correct -- the best kind of
> correct."
>
>
> >
>

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



Re: request object out of a view (I need to access session['data'])

2007-04-03 Thread Grupo Django

I don't know if I didn't understand you or if I you didn't don't
understand me :-)
Not sure abou what you are saying, I think I can't use it to make the
template tag work.
The template tag doesn't use a view to render the content, so it
doesn't get the request object as a parameter.
This is the code of the template tag:
--
register = template.Library()
def menu(position):

data = request.session["stored_data"]
...
return {'output': output,}

register.inclusion_tag('menu/menu.html')(bloque_menu)
--

So I need to read into data the data that is stored in the session.
But the request object is not accessible.
Sorry, I didn't understand what you wrote very good.
Thank you.






On 3 abr, 23:37, "James Bennett" <[EMAIL PROTECTED]> wrote:
> On 4/3/07, Grupo Django <[EMAIL PROTECTED]> wrote:
>
> > Inside the custom template tag, I don't get the request object since
> > it's not a view.
>
> Look into using RequestContext[1] in your views (generic views all use
> it automatically), and enabling the "request" context processor[2].
> This will make the variable "request" -- containing the HttpRequest
> object -- available in template contexts, so in your tag's 'render'
> method you could access it by doing something like:
>
> def render(self, context);
> request = template.resolve_variable('request', context)
> ...do stuff with the request...
>
> [1]http://www.djangoproject.com/documentation/templates_python/#subclass...
> [2]http://www.djangoproject.com/documentation/templates_python/#django-c...
>
> --
> "Bureaucrat Conrad, you are technically correct -- the best kind of correct."


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



Re: request object out of a view (I need to access session['data'])

2007-04-03 Thread James Bennett

On 4/3/07, Grupo Django <[EMAIL PROTECTED]> wrote:
> Inside the custom template tag, I don't get the request object since
> it's not a view.

Look into using RequestContext[1] in your views (generic views all use
it automatically), and enabling the "request" context processor[2].
This will make the variable "request" -- containing the HttpRequest
object -- available in template contexts, so in your tag's 'render'
method you could access it by doing something like:

def render(self, context);
request = template.resolve_variable('request', context)
...do stuff with the request...

[1] 
http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext
[2] 
http://www.djangoproject.com/documentation/templates_python/#django-core-context-processors-request

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

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



Re: Internationalisation for non-supported languages

2007-04-03 Thread Rory Campbell-Lange

Dear Malcolm

Many thanks for your response.

On 03/04/07, Malcolm Tredinnick ([EMAIL PROTECTED]) wrote:
> 
> Hi Rory,
> 
> On Tue, 2007-04-03 at 08:45 +0100, Rory Campbell-Lange wrote:
> > We are developing a website for use in 16 EU countries. Some of the
> > languages we need to cover are not supported by Django, according to:
> > http://www.djangoproject.com/documentation/settings/#languages
> > All of our translation strings are in template files and we have
> > generated corresponding .po files.
> > 
> > We need to support Polish, and to provide an example translation in
> > Afrikaans (language code 'af'), for which we have provided a translation
> > and generated $PROJECTPATH/locale/af/LC_MESSAGES/django.mo
> > 
> > I have tried generating the django.mo file for Afrikaans, setting
> > LANGUAGE_CODE = 'af' and restarting Apache. No luck. I've also tried to
> > list Afrikaans using the "dummy gettext() function" as described at
> > http://www.djangoproject.com/documentation/i18n/ with no success.
> > 
> > Help gratefully received.
> 
> Not sure if you noticed this note in the docs, but your application can
> only support translations that are "known" to Django's core as well. So,
> out of the box you are restricted to the list under django/conf/locale/.
> See
> http://www.djangoproject.com/documentation/i18n/#how-to-create-language-files 
> .
> 
> The good news is that it's easy enough to add an extra locale to the
> core so that your application can support that locale. You will need to
> modify your Django source for this. At the moment there isn't a way
> around that. I might get around to fixing this one day (or somebody else
> might, which would be great, but at the moment, I seem to be the
> de-facto i18n maintainer), but it's relatively low priority at the
> moment -- partly because we'd like to encourage translations of Django's
> core.
> 
> To add an extra locale to Django, do the following (I'll use "af" as the
> example):
> 
> (1) In the django/ directory, run bin/make-messages.py -l af.
> This will create django/conf/locale/af/LC_MESSAGES/django.po and
> djangojs.po in the same directory.
> 
> (2) In the django/ directory, run bin/compile-messages.py -l af
> to generate the corresponding .mo files.
> 
> (3) Add an entry for 'af' either in
> django/conf/global_settings.py (in the LANGUAGES list) or in
> your own settings file.

Hugely helpful. Many, many thanks. I will try this out and report back.

> This creates an empty translation file for the Django core. It doesn't
> add any value to your translations, but it does mean that your
> project/application translation files will be used for your app-specific
> strings. At this point, you should be good to go by settings
> LANGUAGE_CODE and so forth.
> 
> Note that the reference to "dummy gettext()" in the docs is just saying
> that you should avoid using the real (imported) gettext() function in
> that file. Just copy what global_settings.py does if you want that. We
> mark all the language names as translatable in global_settings.py, for
> example.

I think I understand -- I'll stick to standard imported gettext where I
can.

Many thanks again; 

Regards,
Rory
-- 
Rory Campbell-Lange 
<[EMAIL PROTECTED]>


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



request object out of a view (I need to access session['data'])

2007-04-03 Thread Grupo Django

Hi, I need to know how can I access data stored in the session out of
a view.
I have created a custom template tag which has to check a variable
stored in the request.session. It's strictly necessary to store the
data in a session variable at this moment.
Inside the custom template tag, I don't get the request object since
it's not a view.
I have no idea about how to retrieve the data.

And a secondary question related to this. If I wanted to retrieve a
value by GET within the template tag. Is it possible to access it?

Thank you very much.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Web Sites keep pointing against each other

2007-04-03 Thread Graham Dumpleton



On Apr 4, 4:38 am, "Keith Mallory" <[EMAIL PROTECTED]> wrote:
> I have a Ubuntu Server with 4-5 Django web sites hosted on mod_python.
>
> Everything works fine, expect that the web sites keeps on pointing against
> each other. That Site A points to Site B and B to C and so on.
>
> This is how I have set up my httpd.conf
>
> NameVirtualHost *
>
> 
> ServerName example.com
> SetHandler python-program
> PythonHandler django.core.handlers.modpython
> SetEnv DJANGO_SETTINGS_MODULE exp.settings
>Alias /admin_media "/var/www/exp/admin_media"
> PythonPath "['/var/www/exp/projects/'] + sys.path"
> PythonDebug On
> PythonInterpreter py
> 
> SetHandler None
> 
> 
>
> When I retstart the Apache Server, every site works perfectly, but then it
> all fails to point to the right domain. This has created a very embrassing
> situation. Has anyone experienced this, and what is the remedy?

Do you have all sites under the same VirtualHost, or do you have a
different VirtualHost container for each? You aren't really clear on
this as your description mentions different sites but your Apache
configuration only shows a single one being setup.

BTW, if under separate VirtualHost containers, do not use the
PythonInterpreter directive as you are to set them all to use 'py' as
the sub interpreter as then they will all overlap. When using
mod_python, the default is to give each VirtualHost container a
separate Python sub interpreter and thus they would be separate, you
appear to perhaps be overriding that.

Graham


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Vote only once/Remembering votes

2007-04-03 Thread [EMAIL PROTECTED]

I pulled the karma bit of contrib.comments out and made it a more
generic app, so I can use it anywhere. I have it store who voted as
user (as I suspect you would). And at that point all you have to do is
something like:

if KarmaScore.objects.filter(user = request.user):
return HttpResponse("You already voted!", mimetype="text/
html")

Note that in my case I'm actually returning the HttpResponse with
AJAX, so I don't care about building a page. I just want a string in
my response.


On Apr 1, 3:33 pm, "risomt" <[EMAIL PROTECTED]> wrote:
> Just as a quick reply, check out the Comment system in django/contrib:
>
> http://code.djangoproject.com/browser/django/trunk/django/contrib/com...
>
> it has a karma like system and may or may not have unique votes
>
> On Apr 1, 3:08 pm, "SimpleMan" <[EMAIL PROTECTED]> wrote:
>
> > I'm creating something similar to a social poll application. I need
> > the site to remember and prevent users from voting multiple times on
> > each poll, so I figured I would create a new SubmittedPoll model like
> > described in this thread (anonymous users are not a 
> > concern):http://groups.google.com/group/django-users/browse_thread/thread/734f...
>
> > In addition, users will be able to "digg" each poll as well as vote on
> > what category it should belong to. All three of these actions is only
> > allowed once per user, and won't necessarily happen simultaneously (or
> > at all). What's the best way to do this? Should I create three
> > separate models to keep track of votes: SubmittedPoll, SubmittedDigg,
> > and SubmittedCategory? Or is there a more efficient way to do this?
>
> > Any advice is appreciated. Thanks in advance!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 and form_from_instance

2007-04-03 Thread ladamiak

I'm with the same problem..

I've looked at the code of the form_for_intance function and saw
something about the formfield_calback..

Looks like we must suply a function that sets the initial of each
field.. But I'm not sure..

Any way... If you find something, please let me now..

[]'s
Luciano Adamiak



On Mar 28, 7:07 pm, Gary Wilson <[EMAIL PROTECTED]> wrote:
> Starting to play around with newforms and I am trying to create a form
> with fewer fields than the model and post-fill those fields in the view.
>   With the following example models and form:
>
> class Book(models.Model):
>  author = models.CharField(maxlength=100, blank=True)
>  title = models.CharField(maxlength=100)
>
> class BookForm(forms.Form):
>  title = forms.CharField()
>
>  From looking at the code, I was lead to believe I could do something
> like this:
>
> book = Book.objects.get_or_create(author='me', title='go')[0]
> form = forms.form_for_instance(book, form=BookForm)()
>
> The form rendered the single title field, but didn't set it's initial
> value to "go".  It appears thatform_for_instanceis creating all the
> form fields for the model (with correct initial values), but the
> creation of the new form type in the last line ofform_for_instance()
> blows away the fields just created inform_for_instance() with the
> base_fields created in DeclarativeFieldsMetaclass.__new__.
>
> Does the form parameter to theform_for_instance() only intended to
> accept forms inheriting BaseForm and not Form?  The docstring does
> mention BaseForm.  If this is the case, then what is best way to make a
> form with fewer fields than the model?  Removing them from form.fields
> after instantiating my form instance and overriding the save() method of
> my custom form to insert the desired values after my form has been
> validated?
>
> Gary


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: MySQLdb version

2007-04-03 Thread joey101

I did this all, but it still doens't work :(

When running ./dispatch.fcgi directly it looks as though the problem
is all cleared up, but even after killing fcgi 'till it's dead it
still brings up a 500 error on my site.

Does this sound like it's still related or is it some other problem?
If it is another problem any one have ideas on finding out what it is?

Thanks!
Joey


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Web Sites keep pointing against each other

2007-04-03 Thread Keith Mallory
I have a Ubuntu Server with 4-5 Django web sites hosted on mod_python.

Everything works fine, expect that the web sites keeps on pointing against
each other. That Site A points to Site B and B to C and so on.

This is how I have set up my httpd.conf

NameVirtualHost *


ServerName example.com
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE exp.settings
   Alias /admin_media "/var/www/exp/admin_media"
PythonPath "['/var/www/exp/projects/'] + sys.path"
PythonDebug On
PythonInterpreter py

SetHandler None





When I retstart the Apache Server, every site works perfectly, but then it
all fails to point to the right domain. This has created a very embrassing
situation. Has anyone experienced this, and what is the remedy?

K Mallory

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Curious error with Session Variables

2007-04-03 Thread Ramdas S
browsing through the user groups, I see that the issue is a clash between
Django and PHP4/5. I cannot turn them off, since some sites on our server
still use PHP. Is there any solution where we can ensure that Django does
not clash with PHP and live peacefully.

I am eager to know

Ramdas

On 4/3/07, Ramdas S <[EMAIL PROTECTED]> wrote:
>
> Since last few days I am getting this error on Django web sites hosted.
> Obviously it is clashing with something.
>
> When I work on admin interface to add or delete content, I get logged off
> and it takes some time for me to login again.
>
> I get the following messages
>
> Please enter a correct username and password. Note that both fields are
> case-sensitive.
>
> If I keep on trying then the message changes to
>
> Looks like your browser isn't configured to accept cookies. Please enable
> cookies, reload this page, and try again.
>
>
> Later if I persist
>
> I get this error
>
> -
>
> SuspiciousOperation at /admin/ User may have tampered with session cookie. 
> Request
> Method: POST  Request URL: http://developeriq.com/admin/  Exception Type:
> SuspiciousOperation  Exception Value: User may have tampered with session
> cookie.  Exception Location: 
> /usr/lib/python2.4/site-packages/django/contrib/admin/views/decorators.py
> in _decode_post_data, line 40
>
>
>
>
>
> I am using the latest development version Mod_Python, Apache and Ubuntu
> Linux
>
> What can be the reason
>
>
>
> Thanks
>
>
> Ramdas S
>
> The Server is a dedicated server, and it also runs PHP, MySQl and some PHP
> and Python software.
>
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Curious error with Session Variables

2007-04-03 Thread Ramdas S
Since last few days I am getting this error on Django web sites hosted.
Obviously it is clashing with something.

When I work on admin interface to add or delete content, I get logged off
and it takes some time for me to login again.

I get the following messages

Please enter a correct username and password. Note that both fields are
case-sensitive.

If I keep on trying then the message changes to

Looks like your browser isn't configured to accept cookies. Please enable
cookies, reload this page, and try again.


Later if I persist

I get this error

-

SuspiciousOperation at /admin/ User may have tampered with session
cookie. Request
Method: POST  Request URL: http://developeriq.com/admin/  Exception Type:
SuspiciousOperation  Exception Value: User may have tampered with session
cookie.  Exception Location:
/usr/lib/python2.4/site-packages/django/contrib/admin/views/decorators.py
in _decode_post_data, line 40





I am using the latest development version Mod_Python, Apache and Ubuntu
Linux

What can be the reason



Thanks


Ramdas S

The Server is a dedicated server, and it also runs PHP, MySQl and some PHP
and Python software.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Per-app permissions ?

2007-04-03 Thread Chris Brand

What's the best way to restrict access on a per-app basis ?
I want to have two apps, with some users allowed access to one, others
allowed access to the other, and some allowed access to both.

Any advice would be very much appreciated.

Thanks,

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



models.TABULAR Question ...

2007-04-03 Thread ZebZiggle

I want to be able to add new elements and delete individual
elements ... can I do this with the Tabular view?

For example:

Container

   Element 1 [delete]
   Element 2 [delete]
   Element 3 [delete]

   add new Element   new Container

Is there a switch for this? Currently I can only get the num_in_admin
set of Elements and it's all or nothing.

Thx,
Sandy

-
http://www.MyDarkSecret.com
The Murder Mystery Dinner Party in Django


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: upload_to with username

2007-04-03 Thread Jay Parlar

On 4/3/07, Stephen Mizell <[EMAIL PROTECTED]> wrote:
>
> > That line is executed exactly once, at the time the file is imported. So
> > it is not dynamic in any way.
> >
> > (I seem to be saying that at least every other day here. It's normal
> > Python behaviour, people. Please stop hoping it were otherwise!)
>
> Thanks for the help.  I didn't call it dynamic, though.  What are you
> referring to?

Your suggested code implies that it be dynamic though. The
models.FileField() line will only ever be executed one time. You're
passing it the value get_current_user(), but that value only ever gets
passed that one time.

If it were "dynamic", then get_current_user() would get called
everytime the FileField is accessed, which is what you wanted, but
that's not the case. Hence Malcolm's comment :)

Jay P

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



Re: Locate subset language problem

2007-04-03 Thread Nuno Mariz

Malcolm,
A patch that works for me is in: django/utils/translation/
real_trans.py in the function: "def
get_language_from_request(request):":

for lang, mainlang, order in langs:
if lang in supported or mainlang in supported:
# If the lang is not supported but mainlang is, than
activate mainlang
if not lang in supported and mainlang in supported:
lang = mainlang


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: upload_to with username

2007-04-03 Thread Stephen Mizell

> That line is executed exactly once, at the time the file is imported. So
> it is not dynamic in any way.
>
> (I seem to be saying that at least every other day here. It's normal
> Python behaviour, people. Please stop hoping it were otherwise!)

Thanks for the help.  I didn't call it dynamic, though.  What are you
referring to?

I'll look through the fields.py file and see what I can do.  I'm
pretty new to Django and even Python, so I'm guessing I won't have
much luck ;)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



edit_inline causing problems with multiple relations

2007-04-03 Thread mh

I have two models that (simplified) look like this;

class List(models.Model):
 name =models.CharField(maxlength=128)
 class Admin:
  pass

class Entry(models.Model):
 name = models.CharField(maxlength=128, core=True)
 list = models.ForeignKey(List, edit_inline=models.TABULAR)
 to = models.ForeignKey(List, null=True, blank=True,
related_name='to')

This doesn't seem to be working ('bool' object is not callable); any
suggestions on how I could fix it?

While at it I might as well ask a second question;
Each entry can reference either another list, or something else. Is
there any way to construct a foreign key from two fields (and have it
work in the admin if possible)? My current solution is to have
multiple foreign keys of which one is active and the others are null -
works but feels somewhat ugly ;).


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Locate subset language problem

2007-04-03 Thread Nuno Mariz

Sure.

On Apr 3, 2:37 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> Could you file a ticket about this, please?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Generic views. Really generic

2007-04-03 Thread [EMAIL PROTECTED]

Thanks, Malcolm. That's basically what I was thinking. To clarify,
though, I was saying a custom view for this would be quite simple -
almost trivial - and I'm most assuredly *not* a programmer. I was only
leaning toward a generic view because I trust them more than I do my
own code.

Anyway, since the items know which category they're in, I'll just pass
the category and item slugs to the view and query for the item that
matches.

Thanks!




On Apr 2, 9:36 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Mon, 2007-04-02 at 19:17 -0700, [EMAIL PROTECTED] wrote:
> > I hope I explain this well.
>
> > I'm building a site that will have X number of categories. I don't
> > know how many.
> > Each category will have at least one item, but I don't know how many.
>
> > So, I need to display all categories, then each item in the category,
> > then a detail view, without hardcoding the categories in urls.py
> > (because more categories may be added at any time).
>
> > I can get as far as:
> >  (r'^(?P[-\w]+)/$',
> > 'django.views.generic.list_detail.object_detail', dict(category_dict,
> > slug_field='slug', template_name="category.html")),
> >(r'^$', 'django.views.generic.list_detail.object_list',
> > dict(queryset=Category.objects.all(),
> > template_object_name="category",  template_name="base.html")),
>
> > But for the detail view, I think I need something like //
> > /item
>
> > Can this be done in generic views, or do I need to write a custom
> > view? I'm sure there's some bit of documentation somewhere I'm
> > forgetting or havent' read that makes this easy
>
> The main problem -- and I think you are already hinting that you have
> come across this -- is how to construct the queryset for the detail view
> and for the "items in each category" view. It's not easy to do this in
> the URL configuration file, because the queryset depends on parameters
> in the URL.
>
> Instead, write a little view function that takes the parameters from the
> URL and uses them to create the appropriate queryset. Then call the
> generic view, passing in the right queryset. For an example of what I
> mean, 
> seehttp://www.pointy-stick.com/blog/2006/06/29/django-tips-extending-gen
>
> > (not that a custom
> > view for this would be hard).
>
> As an aside: you need to disabuse yourself of this notion. :-)
>
> One of my genuine concerns with generic views is that people use them as
> a crutch, rather than an aid, and struggle mightily against the urge to
> move beyond their support. Writing full-blown view functions is not that
> hard. Sure, you have to sit down and work out what information you want
> and where to get it from, but it's just Python code. With generic views,
> you have to learn a mini-language of which parameters to pass in and
> what they mean and what your template will end up receiving. I suspect
> people work through that and then think "well, normal views are going to
> be even harder". They aren't. They're different and if you're used to
> writing code, perhaps even easier.
>
> 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: Copy table Design many, many times

2007-04-03 Thread Robert

Ned, True,

Thanks both for quick reply.  Actually did try exec at first.. .
character  When it went wrong at first, I doubted myself and thought I
meant eval from js instead hence that post.  I went back to it and
realized how to include the nest "pass" just underneath it using the
escape

---clearly a semi newbie with python

As for the table situation.. actually I do understand databases a bit
better than python and realize that normally one would make a single
table or rather just a few tables instead of copying the design of one
many times.
This is an oddball application, however.. nothing that is going to
serve a web site, but something I am just doing to verify something
else.  Call it an off-label use of a db.

Thanks again..

Robert





On Apr 1, 8:24 pm, Ned Batchelder <[EMAIL PROTECTED]> wrote:
> To expand on what true.chesire is saying: There's really no reason to
> create many identical tables.  Usually you'll want to create a single
> table with one more column to distinguish among the different instances.
>
> --Ned.
>
>
>
> [EMAIL PROTECTED] wrote:
>
> >> I have tried eval with no success..
>
> > Try exec.
>
> > Also, I think it is highly unlikely that there is no other ways to
> > solve your problem in more elegant way.
>
> --
> Ned Batchelder,http://nedbatchelder.com


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



Re: Can't save utf data

2007-04-03 Thread Calumet

Question is off. I recreated all tables with utf8 charset. It helped.

On Apr 3, 3:37 pm, "Calumet" <[EMAIL PROTECTED]> wrote:
> I can't save utf data to database in admin and shell. In tutorial
> application
>
> Warning at /admin/polls/poll/4/
> Data truncated for column 'question' at row 1
>
> Last two calls:
> --
> /usr/lib/python2.4/site-packages/MySQLdb/cursors.py in execute
> self._warning_check()
>
> ListType
> TupleType   
> args['lalala \xd1\x84\xd1\x8b', '2007-04-08 23:32:04', '4']
> charset 'utf8'
> db  
> exc_info
> query   "UPDATE `polls_poll` SET `question`='lalala
> \xd1\x84\xd1\x8b',`pub_date`='2007-04-08 23:32:04' WHERE `id`='4'"
> r   0L
> self
>
> /usr/lib/python2.4/site-packages/MySQLdb/cursors.py in _warning_check
> warn(w[-1], self.Warning, 3)
>
> self
> w   ('Warning', 1265L, "Data truncated for column 'question' at row 1")
> warn
> warnings(('Warning', 1265L, "Data truncated for column 'question' at
> row 1"),)
> --
>
> Data in POST
> question'lalala \xd1\x84\xd1\x8b'
>
> Django 0.96
> MySQL 5.0.24
>
> I updated some data manually. Admin displays utf text incorrectly.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 gurus: Forms With Multiple Inline Objects?

2007-04-03 Thread Malcolm Tredinnick

Hi Paul,

On Tue, 2007-04-03 at 11:45 +, Paul Childs wrote:
> Hi folks,
> 
> Can someone suggest to me what I need to do to make this question a
> little more answerable?

"All our newforms gurus are out of the office at the moment. If you'd
like to leave a message, please press..." :-)

Sorry, your message slipped through the cracks. Let's try to fix that.

> 
> On Apr 1, 12:05 am, "Paul Childs" <[EMAIL PROTECTED]> wrote:
> > I am trying to make the switch to new forms with little success. I
> > have searched the news group, looked over examples (found this to be
> > very good  http://www.djangoproject.com/documentation/models/model_forms/)
> > and looked at some suggested tutorials.
> >
> > The reason for the lack of success is that a lot of our code mimics
> > the edit inline behaviour found in the current Django admin using the
> > old forms and I haven't seen any way or examples of how to do this
> > with newforms.
> >
> > Could someone please give me a push in the right direction, example
> > code or a link to a tutorial.

I'm not an expert in this area yet, but I suspect you are waiting on
some new functionality that has only just been committed on the
newforms-admin branch. If you have a look at
http://code.djangoproject.com/changeset/4836 you'll see that Joseph
Kocherhans committed the subforms-within-forms stuff that is needed for
behaviour like edit_inline.

On django-developers recently, there was a thread
(http://groups.google.com/group/django-developers/browse_frm/thread/8b6094bd8811c140/#
 ) that talked about exactly this.

So you could (a) experiment with the newforms-admin branch, since it
tracks trunk fairly closely, (b) pull out the relevant bits from [4836]
and apply them to your local copy, or (c) wait a little longer until
newforms-admin is merged with trunk. The above thread indicates that
Adrian is eager to move forwards on this. So it looks hopeful.

Sorry if none of these are a perfect solution for you. It's work in
progress at the moment.

Regards,
Malcolm


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



Re: newforms gurus: Forms With Multiple Inline Objects?

2007-04-03 Thread Paul Childs

Hi folks,

Can someone suggest to me what I need to do to make this question a
little more answerable?

On Apr 1, 12:05 am, "Paul Childs" <[EMAIL PROTECTED]> wrote:
> I am trying to make the switch to new forms with little success. I
> have searched the news group, looked over examples (found this to be
> very good  http://www.djangoproject.com/documentation/models/model_forms/)
> and looked at some suggested tutorials.
>
> The reason for the lack of success is that a lot of our code mimics
> the edit inline behaviour found in the current Django admin using the
> old forms and I haven't seen any way or examples of how to do this
> with newforms.
>
> Could someone please give me a push in the right direction, example
> code or a link to a tutorial.
>
> 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
-~--~~~~--~~--~--~---



Can't save utf data

2007-04-03 Thread Calumet

I can't save utf data to database in admin and shell. In tutorial
application

Warning at /admin/polls/poll/4/
Data truncated for column 'question' at row 1

Last two calls:
--
/usr/lib/python2.4/site-packages/MySQLdb/cursors.py in execute
self._warning_check()

ListType
TupleType   
args['lalala \xd1\x84\xd1\x8b', '2007-04-08 23:32:04', '4']
charset 'utf8'
db  
exc_info
query   "UPDATE `polls_poll` SET `question`='lalala
\xd1\x84\xd1\x8b',`pub_date`='2007-04-08 23:32:04' WHERE `id`='4'"
r   0L
self


/usr/lib/python2.4/site-packages/MySQLdb/cursors.py in _warning_check
warn(w[-1], self.Warning, 3)

self
w   ('Warning', 1265L, "Data truncated for column 'question' at row 1")
warn
warnings(('Warning', 1265L, "Data truncated for column 'question' at
row 1"),)
--

Data in POST
question'lalala \xd1\x84\xd1\x8b'

Django 0.96
MySQL 5.0.24

I updated some data manually. Admin displays utf text incorrectly.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Access to m2m relation in model's save()?

2007-04-03 Thread Malcolm Tredinnick

On Tue, 2007-04-03 at 11:46 +0200, Jarek Zgoda wrote:
> I'm trying to get the values from many-to-many relation in the model's
> save() method, but the list of related objects is always empty. After
> the save(), the list has expectd content, but not until the save()
> finishes. Is this normal behaviour and I should look elsewhere to
> process the to-be-saved object depending on related object's values, or
> there is something wrong with my understanding of how Django saves model
> objects?

Your understanding is basically correct and at the moment you can't get
to this information directly inside the saving process. Here's a
slightly long explanation of why it's not possible and what we might do
about it.

The problem is that a bit of a chicken-and-egg conflict: many-to-many
relations are saved in an intermediate that saves the ids for each pair
of objects. So if object A is related to B1 and B2 via m2m, we save the
[id(A), id(B1)] and [id(A), id(B2)] as two rows in the intermediate
table (by id(A), I mean A's primary key value).

In order to save the pair id(A), id(B1), we need to know both those
values. We only know id(A) after object A has been saved, in the case
where it has an auto-generated primary key value and is being saved for
the first time (i.e. created). So the A.save() method is invoked before
the m2m saving is done. After all the objects have been saved, the
AddManipulator object saves the intermediate relations.

We don't talk about AddManipulator and ChangeManipulator objects much in
Django, because they are an under-the-covers feature. We do talk about
manipulators in general a bit in the (old)forms framework and
AddManipulator and ChangeManipulator are just automatically generated
versions of those.

Now, in the medium- to long-term, we are, of course, moving away from
oldforms to newforms. Part of the reason for this change is that
manipulators turned out to be a bit of a brain-twister in their
complexity.

Your particular problem, though is one that hasn't yet become easy to
solve. I think we will end up adding a new signal that is emitted when
the m2m relations have been saved, maybe passing the list of saved
objects to the signal handler or something. This hasn't really been
discussed much in detail yet, but it is a missing piece of functionality
that we will solve at some point.

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: Access to m2m relation in model's save()?

2007-04-03 Thread Jarek Zgoda

Jarek Zgoda napisał(a):

> I'm trying to get the values from many-to-many relation in the model's
> save() method, but the list of related objects is always empty. After
> the save(), the list has expectd content, but not until the save()
> finishes. Is this normal behaviour and I should look elsewhere to
> process the to-be-saved object depending on related object's values, or
> there is something wrong with my understanding of how Django saves model
> objects?

Oh my God, I am lost here.



-- 
Jarek Zgoda

"We read Knuth so you don't have to."

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Access to m2m relation in model's save()?

2007-04-03 Thread Jarek Zgoda

I'm trying to get the values from many-to-many relation in the model's
save() method, but the list of related objects is always empty. After
the save(), the list has expectd content, but not until the save()
finishes. Is this normal behaviour and I should look elsewhere to
process the to-be-saved object depending on related object's values, or
there is something wrong with my understanding of how Django saves model
objects?

-- 
Jarek Zgoda

"We read Knuth so you don't have to."

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Dynamic query building

2007-04-03 Thread Malcolm Tredinnick

On Tue, 2007-04-03 at 09:32 +0200, Atilla wrote:
> On 03/04/07, Honza Král <[EMAIL PROTECTED]> wrote:
> > something like this works for me...
> >
> > q = Q( tag__name=first_tag )
> > for tag in other_tags:
> >   q = q | Q( tag__name=tag )
> 
> What kind of query does this build BTW? Is it smart enough to put them
> all into a "WHERE name IN ( all-your-tags-here) ?

Not yet, it's not. Will be soon, though. :-)

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: Internationalisation for non-supported languages

2007-04-03 Thread Malcolm Tredinnick

Hi Rory,

On Tue, 2007-04-03 at 08:45 +0100, Rory Campbell-Lange wrote:
> We are developing a website for use in 16 EU countries. Some of the
> languages we need to cover are not supported by Django, according to:
> http://www.djangoproject.com/documentation/settings/#languages
> All of our translation strings are in template files and we have
> generated corresponding .po files.
> 
> We need to support Polish, and to provide an example translation in
> Afrikaans (language code 'af'), for which we have provided a translation
> and generated $PROJECTPATH/locale/af/LC_MESSAGES/django.mo
> 
> I have tried generating the django.mo file for Afrikaans, setting
> LANGUAGE_CODE = 'af' and restarting Apache. No luck. I've also tried to
> list Afrikaans using the "dummy gettext() function" as described at
> http://www.djangoproject.com/documentation/i18n/ with no success.
> 
> Help gratefully received.

Not sure if you noticed this note in the docs, but your application can
only support translations that are "known" to Django's core as well. So,
out of the box you are restricted to the list under django/conf/locale/.
See
http://www.djangoproject.com/documentation/i18n/#how-to-create-language-files .

The good news is that it's easy enough to add an extra locale to the
core so that your application can support that locale. You will need to
modify your Django source for this. At the moment there isn't a way
around that. I might get around to fixing this one day (or somebody else
might, which would be great, but at the moment, I seem to be the
de-facto i18n maintainer), but it's relatively low priority at the
moment -- partly because we'd like to encourage translations of Django's
core.

To add an extra locale to Django, do the following (I'll use "af" as the
example):

(1) In the django/ directory, run bin/make-messages.py -l af.
This will create django/conf/locale/af/LC_MESSAGES/django.po and
djangojs.po in the same directory.

(2) In the django/ directory, run bin/compile-messages.py -l af
to generate the corresponding .mo files.

(3) Add an entry for 'af' either in
django/conf/global_settings.py (in the LANGUAGES list) or in
your own settings file.

This creates an empty translation file for the Django core. It doesn't
add any value to your translations, but it does mean that your
project/application translation files will be used for your app-specific
strings. At this point, you should be good to go by settings
LANGUAGE_CODE and so forth.

Note that the reference to "dummy gettext()" in the docs is just saying
that you should avoid using the real (imported) gettext() function in
that file. Just copy what global_settings.py does if you want that. We
mark all the language names as translatable in global_settings.py, for
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
-~--~~~~--~~--~--~---



Re: Internationalisation for non-supported languages

2007-04-03 Thread TaMeR



On Apr 3, 3:45 am, Rory Campbell-Lange <[EMAIL PROTECTED]>
wrote:
> We are developing a website for use in 16 EU countries. Some of the
> languages we need to cover are not supported by Django, according 
> to:http://www.djangoproject.com/documentation/settings/#languages
> All of our translation strings are in template files and we have
> generated corresponding .po files.
>
> We need to support Polish, and to provide an example translation in
> Afrikaans (language code 'af'), for which we have provided a translation
> and generated $PROJECTPATH/locale/af/LC_MESSAGES/django.mo
>
> I have tried generating the django.mo file for Afrikaans, setting
> LANGUAGE_CODE = 'af' and restarting Apache. No luck. I've also tried to
> list Afrikaans using the "dummy gettext() function" as described 
> athttp://www.djangoproject.com/documentation/i18n/with no success.
>
> Help gratefully received.
>
> Regards
> Rory
>

Hi Rory,

For Polish you can check this out I don't know about African
http://code.google.com/p/diamanda/


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: HowTo assign user to group at registration

2007-04-03 Thread TaMeR



On Apr 3, 3:25 am, Atilla <[EMAIL PROTECTED]> wrote:
> On 03/04/07, TaMeR <[EMAIL PROTECTED]> wrote:

> group  = Group.objects.get(condition)
> new_user.groups.add(group)
>
> I'm not sure why it doesn't raise errors there though, if .add() only
> accepts a related object.


Thanks, I will try that. I'll get back to you if I figure out why I
don't get an error.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



unique_together error 'isUniquetype_primary'

2007-04-03 Thread TaMeR


Hello,

I see others use this like at following link without adding a
AddManipulator why do I get this error?

By the way, I did rebuild the db (sqlite3) after adding
unique_together

http://svn.zyons.python-hosting.com/trunk/zilbo/common/counter/models.py

= ERROR =
AttributeError at /admin/data/contact/add/
'AddManipulator' object has no attribute 'isUniquetype_primary'
Request Method: GET
Request URL:http://127.0.0.1:8000/admin/data/contact/add/
Exception Type: AttributeError
Exception Value:'AddManipulator' object has no attribute
'isUniquetype_primary'
Exception Location: /usr/lib/python2.4/site-packages/django/db/models/
fields/__init__.py in get_manipulator_fields, line 240


= Code ==

class PhoneBook(models.Model):
contact = models.ForeignKey(Contact, edit_inline=models.TABULAR,
num_in_admin=2)
type= models.CharField(_("Type"), choices=PHONE_CHOICES,
maxlength=20)
phone   = models.CharField(_("Phone Number"), blank=True,
maxlength=12, core=True)
primary = models.BooleanField(_("Primary"), default=False)

def __str__(self):
return ("%s - %s" % (self.type, self.phone))

class Meta:
unique_together = (("type", "primary"),)
ordering = ['-primary']
verbose_name = _("Phone Number")
verbose_name_plural = _("Phone Numbers")

class Admin:
fields = (
  (None, {'fields': ('contact',
'type','phone','primary')}),
 )
list_display = ('contact', 'type','phone','primary')


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Dynamic query building

2007-04-03 Thread Atilla
On 03/04/07, Honza Král <[EMAIL PROTECTED]> wrote:
> something like this works for me...
>
> q = Q( tag__name=first_tag )
> for tag in other_tags:
>   q = q | Q( tag__name=tag )

What kind of query does this build BTW? Is it smart enough to put them
all into a "WHERE name IN ( all-your-tags-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: HowTo assign user to group at registration

2007-04-03 Thread Atilla

On 03/04/07, TaMeR <[EMAIL PROTECTED]> wrote:
>
>
> I use two registration forms one for clients one for vendors.
> Depending on form used I would like to assign the user to a group.
>
> How do I use new_user.groups.add('Client')
>
> Below is my code that does not raise any errors but also does not add
> the user to the group.
>
> =  CODE =
> def register(request, success_url='/accounts/register/complete/'):
>
> Context::
> form
> The registration form
>
> Template::
> registration/registration_form.html
>
> """
> if request.method == 'POST':
> form = RegistrationForm(request.POST)
> if form.is_valid():
> new_user 
> =RegistrationProfile.objects.create_inactive_user(username=form.clean_data['username'],
>
> password=form.clean_data['password1'],
>
> email=form.clean_data['email'])
> new_user.groups.add('Client')
> return HttpResponseRedirect(success_url)
> else:
> form = RegistrationForm()
> return render_to_response('registration/registration_form.html',
>   { 'form': form },
>   context_instance=RequestContext(request)
>  )
>
>

If i remember correctly, .add() takes an object that it needs
association to, so you'll have to do (where condition expresses which
group you want to add the user to):

group  = Group.objects.get(condition)
new_user.groups.add(group)

I'm not sure why it doesn't raise errors there though, if .add() only
accepts a related object.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: M2M relationships via an intermediary table .. how do i get to the data in my template?

2007-04-03 Thread oliver

Hi, yes i was approaching it very wrong, but figured it out.
Here is a little test which i got to work with the help of some IRC
django people! (Thanks).

I didnt know that django would also send all the related items from
the intermediate table to the template. Very nice!
I guess I should do some filtering thou as this could be a lot of
data..

Using my "news", "imagegroup", "images" setup, this is how i get to
the "images" data from the news object.

Yes News as a name would be better but than admin made Newss out of
it ;), I forgot that you can define the plural some where in the
model.

This gets the 1st result:
{{ new.imagegroup.all.0.image.caption }}

{% if new.imagegroup.all.0 %}
This has images
{% else %}
This has NO images
{% endif %}

This gets all results: 
{% for newsitem in new.imagegroup.all %}

{{ newsitem.createdate }}

{{ newsitem.position }}

{{ newsitem.image.caption }}

{{ newsitem.image.get_imagefile_url }}


{% endfor %}

On Apr 2, 10:17 am, Atilla <[EMAIL PROTECTED]> wrote:
> On 30/03/07, oliver <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Hi,
> > I am starting out with django and python, don't have much experience
> > in either. I have managed to create a few "simple" website with django
> > and really enjoy working with it.
>
> > But I am a bit stuck on my latest project. I am using a M2M relation
> > via an intermediary table.
>
> >http://dpaste.com/hold/7651/ I put all the code in there ..
>
> > I have a Image model, a ImageGroup (intermediate table) model and a
> > News (New) model.
> > New(s) has a:
> > imagecollection = models.ManyToManyField(ImageGroup...)
>
> > and ImageGroup holds:
> > Position (for sorting)
> > and a ForgeignKey to Image
>
> > Image holds:
> > Caption and the path to the image file.
>
> > I made a simple inclusion tag to get my News objects and send them to
> > my template.
> > But I am stuck on how do I get to the image data in my template? More
> > specific for this example I only need the 1st image, later on I will
> > need all related images but I hope I will understand how to do it once
> > I get to that stage.
>
> > I guess I need something in the inclusion_tag to get me the related
> > images in the order of the intermediate table "position" field?
>
> > I tried this but django complains about "self" (global name 'self' is
> > not defined)
> > images = ImageGroup.objects.filter( new =
> > self.id ).order_by( 'position' )[:1]
>
> That can't work. I guess what you're trying to do can be accomplished
> with ImageGroup.objects.select_related().latest().  Or any other
> filter you require, instead of the latest() shortcut.
>
> See how to read out the list of related fields in the django docs, and
> also not that you can do filter() on fields of the related models as
> well, for example Image.objsects.filter(imagegroup__new__islive=True).
>
> Also - "News" has no singular form,"New" is a weird class name to use,
> isn't it ? :)
>
> > I read the docs and found examples in this group but I can't get my
> > head around it how it works on my model layout.
>
> > any help will be greatly appreciated.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---