Dereferencing One-to-Many Relationships in Templates

2009-04-10 Thread Anthony

Hello,

I'm passing queryset 'S' to a template.  S has several attributes, M,
N and O.

M has a one-to-many relationship with T.  I need to display:

N, O, T^1, T^2 through T^n, etc. (the T list would be a filtered
subset)


Can this be done via template tags?  (Will I have to make custom
ones?)  At the moment, I'm considering breaking out the T^x values in
the view, then building a dictionary of tuples to pass them into the
template.  However, it would seem more natural to me to be able to de-
reference the T values directly from the template.

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



Re: adminsite instance and (registered) related objects question

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 21:24 -0700, patrickk wrote:
> 
> 
> On Apr 11, 6:03 am, Malcolm Tredinnick 
> wrote:
> > On Fri, 2009-04-10 at 20:17 -0700, patrickk wrote:
> > > anyone?
> >
> > *sigh* If somebody had an answer, they would have answered already. It's
> > kind of self-fulfilling prophecy!
> 
> your answer shows that it´s sometimes useful to ask twice.

I going to assume you meant to say "thankyou for responding even though
I failed to follow even the most basic mailing list etiquette." and it
just came out wrongly.

> 
> well ... I guess if the docs are not explicit (enough), one has to
> assume.

Not if you want to get very far, no. The normal approach is to adopt a
reasonable attitude and approach things with an open mind. when you
genuinely don't know what is going on. Making assumptions is *always* a
mistake. "I don't know how this behaves, so let's test it out. Okay, it
behaves like that. Now I know."

Instead, you waded in with a closed minded assumption and expressed the
possibility it might be a bug when the correct behaviour was right there
in front of you and you even worked out what the right interpretation
was. Your problems occurred because you made the assumption.

Malcolm


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



Re: adminsite instance and (registered) related objects question

2009-04-10 Thread patrickk



On Apr 11, 6:03 am, Malcolm Tredinnick 
wrote:
> On Fri, 2009-04-10 at 20:17 -0700, patrickk wrote:
> > anyone?
>
> *sigh* If somebody had an answer, they would have answered already. It's
> kind of self-fulfilling prophecy!

your answer shows that it´s sometimes useful to ask twice.

>
> [...]
>
>
>
> > > is this intentional? the docs doesn´t explain this and my assumption
> > > is that different adminsite instances are here to split up the models
> > > into different sections (within the admin).
>
> That's the bug: you assumed.

well ... I guess if the docs are not explicit (enough), one has to
assume.

>
> Admin sites are for creating entirely separate admin sites.
>
> > > for my usecase, editors who are responsible for the cinemaprogram are
> > > not responsible for adding movies, so it doesn´t really make sense to
> > > show the model "Movie" to them. they only need that model to related
> > > their entries to. the problem here is the "related object lookup",
> > > because the link is relative (beginning with "../../../").
>
> If the Movie model isn't being edited inline and is used elsewhere,
> there needs to be a way to edit it. You could use permissions to prevent
> them creating new ones (possibly. I rarely use permissions, so
> experiment and check the documentation). So either edit it inline or be
> prepared to have it have it's own entry.
>
> Realise, also, that you're not required to show the model on the main
> template if you don't want to. You can customise the templates and not
> display particular models there.

just for the record (if anyone else reads this and has the same
problem):
I registered _all_ models with my main admin site and changed the
links within the related lookups to /main_admin/app/model/ instead
of ../../../app/model.

changing templates is probably the right thing to do. but compared
with changing 50 (or more) templates, the above "solution" is less
work (and I don´t see any disadvantage).

anyway: malcolm, thanks for your answer. you definitely clarified
things.

thanks,
patrick

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



Re: adminsite instance and (registered) related objects question

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 20:17 -0700, patrickk wrote:
> anyone?

*sigh* If somebody had an answer, they would have answered already. It's
kind of self-fulfilling prophecy!

[...]
> >
> > is this intentional? the docs doesn´t explain this and my assumption
> > is that different adminsite instances are here to split up the models
> > into different sections (within the admin).

That's the bug: you assumed.

Admin sites are for creating entirely separate admin sites.

> > for my usecase, editors who are responsible for the cinemaprogram are
> > not responsible for adding movies, so it doesn´t really make sense to
> > show the model "Movie" to them. they only need that model to related
> > their entries to. the problem here is the "related object lookup",
> > because the link is relative (beginning with "../../../").

If the Movie model isn't being edited inline and is used elsewhere,
there needs to be a way to edit it. You could use permissions to prevent
them creating new ones (possibly. I rarely use permissions, so
experiment and check the documentation). So either edit it inline or be
prepared to have it have it's own entry.

Realise, also, that you're not required to show the model on the main
template if you don't want to. You can customise the templates and not
display particular models there.

Regards,
Malcolm



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



Re: syncdb adding extra table from models

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 20:36 -0700, nixon66 wrote:
> The meta option is already there. And the myproject_country table is
> still created.

I seem to remember there have been some problems where querying the
existing tables in the database returned them with different casing of
the name to what they were created with. Specifically with MySQL.

So what database backend are you using? What is the exact
capitalisation, both in your model and in the database when you list the
tables? Maybe you could put some debugging prints into the syncdb code
where it looks for existing tables
(django/core/management/commands/syncdb.py) to see what is coming back
when it retrieves the existing tables.

Regards,
Malcolm



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



Re: syncdb adding extra table from models

2009-04-10 Thread nixon66

The meta option is already there. And the myproject_country table is
still created.

On Apr 10, 4:51 pm, Ramiro Morales  wrote:
> On Fri, Apr 10, 2009 at 5:29 PM, nixon66  wrote:
>
> > I have a legacy database that I used inspectdb on to generate models.
> > Once I generated the models and cleaned them up, I ran manage.py
> > syncdb. Everything went fine except I have one model that it creates
> > another table from with the name of the app attached to the front. So
> > the model is called country. But django adds another table called
> > myporject_country to the database. Anyone know why it would do this
> > and what is the solution?
>
> Use the db_table Meta option:
>
> http://docs.djangoproject.com/en/dev/ref/models/options/#db-table
>
> class Country(models.Model):
>     # ...
>     class Meta:
>         db_table = ' country'
>
> HTH,
>
> --
> Ramiro Moraleshttp://rmorales.net
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: adminsite instance and (registered) related objects question

2009-04-10 Thread patrickk

anyone?

I´m not sure whether or not to open a ticket on this issue. It could
be "solved" with a better explanation in the docs.
Question is: Is this a "bug" or is the documentation incomplete/
inexplicit?

thanks,
patrick


On Apr 9, 9:50 am, patrickk  wrote:
> I´ve recently figured out that if you use different adminsite
> instances, you have to register every related model with every
> instance.
>
> giving an example:
> /admin/ ... autodiscover
> /configuration_admin/ ... config stuff
> /main_admin/ ... stuff important for editors (e.g. including the model
> "Movie")
> /cinema_admin/ ... cinemaprograms
>
> now, if an editor uses /cinema_admin/ to add/change/delete
> cinemaprograms, he/she needs the model "Movie" as a related/foreign
> key. now I have to register the model "Movie" within /main_admin/ as
> well as /cinema_admin/ to make this work.
>
> is this intentional? the docs doesn´t explain this and my assumption
> is that different adminsite instances are here to split up the models
> into different sections (within the admin).
> for my usecase, editors who are responsible for the cinemaprogram are
> not responsible for adding movies, so it doesn´t really make sense to
> show the model "Movie" to them. they only need that model to related
> their entries to. the problem here is the "related object lookup",
> because the link is relative (beginning with "../../../").
>
> thanks,
> patrick
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trying to use the aggregate functions

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 18:15 -0700, chris wrote:
> 
> 
> On Apr 10, 6:55 pm, Malcolm Tredinnick 
> wrote:
> 
> > However there could be, and likely are, many TextChar objects with the
> > same edition value, so it would be ambiguous as to which particular
> > object to return. Since there's no natural choice, there's no API to ask
> > Django to guess or provide a sample object or anything like that. It's
> > not appropriate to return a model object for that type of query.
> >
> > What is the real problem you are trying to solve here? Why do you need
> > an object back?
> 
> Well, I want to display in a template the name of the edition, rather
> than the primary key, which means nothing to the user.  Meanwhile I
> resorted to do the footwork in the view function like so, which allows
> me to achieve what I need:
> 
> reslist = [{'edition' :Edition.objects.get(pk=a['edition']).__unicode__
> (), 'count': a['char__count']} for a in char.textchar_set.values
> ('edition').annotate(Count('char'))]

Aah .. I'm dumb. I misread your original question as asking for a
TextChar object back (since you were querying on the TextChar model).

Returning Edition models -- which is indeed what you were asking for and
since completing my remedial reading course I can now see that -- is
definitely possible. Use Edition as the root for the queryset (the model
to query). This does what you're after:


Edition.objects.filter(textchar__unichar=char).annotate(Count("textchar"))

That will return a bunch of Edition objects, each with a textchar__count
attribute.

Sorry for being so dense early on.

Regards,
Malcolm


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



Re: trying to use the aggregate functions

2009-04-10 Thread chris



On Apr 10, 6:55 pm, Malcolm Tredinnick 
wrote:

> However there could be, and likely are, many TextChar objects with the
> same edition value, so it would be ambiguous as to which particular
> object to return. Since there's no natural choice, there's no API to ask
> Django to guess or provide a sample object or anything like that. It's
> not appropriate to return a model object for that type of query.
>
> What is the real problem you are trying to solve here? Why do you need
> an object back?

Well, I want to display in a template the name of the edition, rather
than the primary key, which means nothing to the user.  Meanwhile I
resorted to do the footwork in the view function like so, which allows
me to achieve what I need:

reslist = [{'edition' :Edition.objects.get(pk=a['edition']).__unicode__
(), 'count': a['char__count']} for a in char.textchar_set.values
('edition').annotate(Count('char'))]

Thanks for the help anyway!

All the best,

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



Re: Generic relations and unit tests.

2009-04-10 Thread Malcolm Tredinnick

On Sat, 2009-04-11 at 08:47 +0800, Russell Keith-Magee wrote:
> On Sat, Apr 11, 2009 at 5:53 AM, Poromenos  wrote:
> >
> > Hello,
> > I created a model that has a ForeignKey to ContentType, but now I
> > can't use my test fixtures, since the IDs they point to are random
> > every time the test database is created. I can't dump the contenttypes
> > data because then I get many duplicate inserts, since Django rebuilds
> > them every time it sets up the test DB. Is there any way for me to use
> > both ContentType and unit tests?
> 
> The IDs won't be completely random, but they certainly will be fragile
> and subject to change.
> 
> You have discovered ticket #7052; unfortunately, there isn't any easy
> fix at the moment.
> 
> 1) Don't use fixtures - create your test objects in the setUp() method
> of your test using normal Python code.
> 
> 2) Use the fixture to define the basic data in your objects, and then
> use the setUp() method to modify the contenttypes at runtime, based on
> the current values in the database. This means you don't serialize the
> contenttype objects themselves in your fixture, and you use and
> foreignkey reference to a contenttype as a temporary placeholder for
> the real value that will be inserted at runtime.
> 
> Obviously, neither of these are ideal solutions. This bug is something
> I want to look at for Django v1.2.

Well, I'd argue (1) is the ideal solution. Creating objects
programmatically is robust, self-documenting and encourages testers to
think about the minimum requirements needed for a self-contained
unittest. It's also fairly easy. Tends to be my normal practice.

So opinions clearly differ there. Which doesn't invalidate Russell's
opinion, but I wouldn't want people to think it's all horrible when
there's already a perfectly standard and supported way of doing this
(the setUp() method exists to set things up for unittests).

Regards,
Malcolm


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



Re: Generic relations and unit tests.

2009-04-10 Thread Russell Keith-Magee

On Sat, Apr 11, 2009 at 5:53 AM, Poromenos  wrote:
>
> Hello,
> I created a model that has a ForeignKey to ContentType, but now I
> can't use my test fixtures, since the IDs they point to are random
> every time the test database is created. I can't dump the contenttypes
> data because then I get many duplicate inserts, since Django rebuilds
> them every time it sets up the test DB. Is there any way for me to use
> both ContentType and unit tests?

The IDs won't be completely random, but they certainly will be fragile
and subject to change.

You have discovered ticket #7052; unfortunately, there isn't any easy
fix at the moment.

1) Don't use fixtures - create your test objects in the setUp() method
of your test using normal Python code.

2) Use the fixture to define the basic data in your objects, and then
use the setUp() method to modify the contenttypes at runtime, based on
the current values in the database. This means you don't serialize the
contenttype objects themselves in your fixture, and you use and
foreignkey reference to a contenttype as a temporary placeholder for
the real value that will be inserted at runtime.

Obviously, neither of these are ideal solutions. This bug is something
I want to look at for Django v1.2.

Yours
Russ Magee %-)

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



Re: This can't be that hard

2009-04-10 Thread Mr. T

Hi Malcolm, thanks for the reply.

We have embedded systems that connect to a twisted server that updates
table Foo periodically. I am trying to write an http server with
Django (which has been very helpful) that allows an overview of the
embedded systems status.

The main view makes an ajax call to my django httpserver periodically
as well. I can see some of the data my server is serving up isn't up
to date with the postgres database. Come to think of it, it is only
for some fields. So I'll look into it more myself before any one
should bother here. Must be something I've overlooked.

On Apr 10, 4:43 pm, Malcolm Tredinnick 
wrote:
> On Fri, 2009-04-10 at 14:46 -0700, Mr. T wrote:
> > Sorry, a QuerySet eval question. Yeah, I'm dumb I know.
>
> > My view is creating a query set, XXX.objects.all(). Stale data is
> > being served up all the time. Read the docs about generic views, when
> > sets are evaluated, some old posts in this group. Tried ._clone(),
> > tried iteration, tried len(), nothing will give fresh data in my set.
>
> What do you mean by stale data? There are a couple of possibilities that
> spring to mind:
>
> (1) You are seeing the same cached data in the queryset, although you
> said you've tried _clone() and that resets any internal cache.
>
> (2) You have data being committed in another transaction that isn't yet
> visible to your queryset's transaction. Which database are you using?
> How are you determining the data is stale?
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Customizing admin form

2009-04-10 Thread Brian Neal

On Apr 10, 4:46 pm, Oleg Oltar  wrote:
> Hi!
>
> I have a model which contains several TextFields and CharFields. I want to
> make all char fields longer and wider. How to do it?
>
> Thanks,
> Oleg

You can supply your own form that is using customized widgets to
construct the fields with.

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#form
http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Widget.attrs

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



Re: single queryset from multiple tables

2009-04-10 Thread Alex Gaynor
On Fri, Apr 10, 2009 at 7:52 PM, Malcolm Tredinnick <
malc...@pointy-stick.com> wrote:

>
> On Fri, 2009-04-10 at 19:44 -0400, Alex Gaynor wrote:
> >
> >
> > On Fri, Apr 10, 2009 at 7:40 PM, Malcolm Tredinnick
> >  wrote:
> [...]
> >
> > Particularly with iterators, storing the (next head item, rest
> > of
> > iterator) pair in a heap leads to a very neat and fast way to
> > create a
> > combined iterator. Here's one professional-quality
> > implementation that I
> > would recommend: http://code.activestate.com/recipes/491285/
> >
> > It has one unfortunate failing(which is the fault of the heapq
> > library), it doesn't take a key/cmp function like sorted does.  It is
> > otherwise completely excellent though.
>
> It's Python and so is the heap module! Modifying things is easy. I've
> used the same solution with custom comparison functions one a number of
> occasions. Even writing a small heap implementaiton with a custom
> comparison is only about two dozen lines. Come on, think a little bit
> outside the box!
>

I'm not!  A heap sort is a great solution to this problem(but you already
knew that), it's just that the implementation in the python stdlib doesn't
work perfectly for this usecase(indeed I filed a ticket about this upsteam
several months ago, for reference it was rejected).  I did the same thing
you suggested for a blog post on this topic a number of months ago, however
it wasn't nearly as optimial as this(I believe you even commented to that
effect on the post).


>
> Regards,
> Malcolm
>
>
>
>
> >
>
Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Re: single queryset from multiple tables

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 19:44 -0400, Alex Gaynor wrote:
> 
> 
> On Fri, Apr 10, 2009 at 7:40 PM, Malcolm Tredinnick
>  wrote:
[...]
> 
> Particularly with iterators, storing the (next head item, rest
> of
> iterator) pair in a heap leads to a very neat and fast way to
> create a
> combined iterator. Here's one professional-quality
> implementation that I
> would recommend: http://code.activestate.com/recipes/491285/
> 
> It has one unfortunate failing(which is the fault of the heapq
> library), it doesn't take a key/cmp function like sorted does.  It is
> otherwise completely excellent though.

It's Python and so is the heap module! Modifying things is easy. I've
used the same solution with custom comparison functions one a number of
occasions. Even writing a small heap implementaiton with a custom
comparison is only about two dozen lines. Come on, think a little bit
outside the box!

Regards,
Malcolm




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



Re: Object filtering with a GenericForeignKey field

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 16:04 -0700, M Godshall wrote:
> I have two models, Comment and Project.  Comments are connected to a
> Project through a GenericForeignKey, and each Project is assigned to a
> particular user.  I'd like to retrieve the latest comments for all the
> projects that a particular user is assigned to, but according to the
> Django documentation (and personal tests), a GenericForeignKey fields
> cannot be used directly with filter() or exclude(), so I can't do
> something like:
> 
> Comment.objects.filter(content_object__assigned_to=user).order_by
> ('date')[:10]
> 
> I'm assuming I need to use the extra() method to accomplish something
> like this, but I am not very savvy with it, and would appreciate any
> help I could get in piecing it together for this scenario.  Any other
> ideas would be appreciated as well.  Thanks in advance!

This doesn't sound particularly practical/possible. It would require
joining to every single model table so that all the necessary "date"
fields were available for all the possible content-type values (you
don't know in advance of running the query which content-type values
will be required).

Sorting in Python will be a better solution there.

Regards,
Malcolm



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



Re: single queryset from multiple tables

2009-04-10 Thread Alex Gaynor
On Fri, Apr 10, 2009 at 7:40 PM, Malcolm Tredinnick <
malc...@pointy-stick.com> wrote:

>
> On Fri, 2009-04-10 at 16:44 -0400, Alex Gaynor wrote:
> >
> >
> > On Fri, Apr 10, 2009 at 4:40 PM, veearrsix 
> > wrote:
> >
> > This question seems to have been asked a few times, but never
> > answered
> > fully.
>
> Not quite true. It's been answered fully a lot of times: querysets are
> iterators, so you have multiple sorted iterators and combining them into
> a single sorted iterator is just a merge sort.
>
> Creating a single queryset is almost always not the real problem people
> are trying to solve. Which is fortunate, since it doesn't make sense on
> a definitional level: a queryset is the result of filtering a set of
> model results, not combining arbitrary SQL. Combining multiple querysets
> into a single result that can be iterated through is the typical problem
> trying to be solved.
>
> [...]
> >
> > There is no way to get a single QuerySet with results from multiple
> > models.  What you want to do is best approximated like this:
> >
> > from itertools import chain
> >
> > sorted(chain(Model1.obejcts.all(), Model2.objects.all()), key=lambda
> > o: o.pub_date)
>
> That's a  bit crufty, since it pulls everything into memory immediately.
> Not cool with a few tens of thousands items in the result set (creating
> all those Python objects is noticeable).
>
> Merge or heap sort is your friend here. Sure, us old guys have the
> advantage here, because that stuff was very standard back in the age of
> dinosaurs when RAM was scarcer and hard- and tape-drives were slower, so
> random access wasn't always an option.
>
> Particularly with iterators, storing the (next head item, rest of
> iterator) pair in a heap leads to a very neat and fast way to create a
> combined iterator. Here's one professional-quality implementation that I
> would recommend: http://code.activestate.com/recipes/491285/
>

It has one unfortunate failing(which is the fault of the heapq library), it
doesn't take a key/cmp function like sorted does.  It is otherwise
completely excellent though.


>
> Regards,
> Malcolm
>
>
> >
>
Alex


-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Re: This can't be that hard

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 14:46 -0700, Mr. T wrote:
> Sorry, a QuerySet eval question. Yeah, I'm dumb I know.
> 
> My view is creating a query set, XXX.objects.all(). Stale data is
> being served up all the time. Read the docs about generic views, when
> sets are evaluated, some old posts in this group. Tried ._clone(),
> tried iteration, tried len(), nothing will give fresh data in my set.

What do you mean by stale data? There are a couple of possibilities that
spring to mind:

(1) You are seeing the same cached data in the queryset, although you
said you've tried _clone() and that resets any internal cache.

(2) You have data being committed in another transaction that isn't yet
visible to your queryset's transaction. Which database are you using?
How are you determining the data is stale?

Regards,
Malcolm



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



Re: single queryset from multiple tables

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 16:44 -0400, Alex Gaynor wrote:
> 
> 
> On Fri, Apr 10, 2009 at 4:40 PM, veearrsix 
> wrote:
> 
> This question seems to have been asked a few times, but never
> answered
> fully.

Not quite true. It's been answered fully a lot of times: querysets are
iterators, so you have multiple sorted iterators and combining them into
a single sorted iterator is just a merge sort.

Creating a single queryset is almost always not the real problem people
are trying to solve. Which is fortunate, since it doesn't make sense on
a definitional level: a queryset is the result of filtering a set of
model results, not combining arbitrary SQL. Combining multiple querysets
into a single result that can be iterated through is the typical problem
trying to be solved.

[...]
> 
> There is no way to get a single QuerySet with results from multiple
> models.  What you want to do is best approximated like this:
> 
> from itertools import chain
> 
> sorted(chain(Model1.obejcts.all(), Model2.objects.all()), key=lambda
> o: o.pub_date)

That's a  bit crufty, since it pulls everything into memory immediately.
Not cool with a few tens of thousands items in the result set (creating
all those Python objects is noticeable).

Merge or heap sort is your friend here. Sure, us old guys have the
advantage here, because that stuff was very standard back in the age of
dinosaurs when RAM was scarcer and hard- and tape-drives were slower, so
random access wasn't always an option.

Particularly with iterators, storing the (next head item, rest of
iterator) pair in a heap leads to a very neat and fast way to create a
combined iterator. Here's one professional-quality implementation that I
would recommend: http://code.activestate.com/recipes/491285/

Regards,
Malcolm


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



Re: rendering values from ManyToMany fields

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 12:16 -0700, Adam Fraser wrote:
[...]
> The problem I'm running into is that the value that comes into render
> for the ManyToManyField is a list of the id's for the selected stains
> and not the stains themselves.  I assume I should be getting them
> somehow through the django.db.models.fields.related.ManyRelatedManager
> which is in the original_value, but I haven't been able to figure out
> how.
> 
> Anyone know what I'm missing?

The Widget subclass should only be processing the data that is going to
be displayed on the form. For something like a choice field based on
models, this would be, say, the pk value and a string to use for the
human-readable portion.

The django.forms.models.ModelChoiceField is a good example to look at to
see what's going on. It uses ModelChoiceIterator.choice() to generate
the data that is passed to the widget for rendering and you'll see that
it returns (pk, label) pairs.

So it sounds like things are working as expected. What extra work are
you trying to do at the widget level that requires more than what is
already passed in (the sequence of (pk, label) values)? Why isn't
whatever field you're using generating the right data? It's the Field
subclass that you want to be addressing here, not the widget.

In summary, widgets are objects that know how to take flat data and
convert it to HTML. Fields are objects that know how to take more
complex Python things (models, arbitrary objects, ...) and convert them
to flat data for passing to the widgets.

Regards,
Malcolm



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



Re: Different admin registry behavior with mod_python versus dev server

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 12:01 -0700, Joe Sr. wrote:
[...]
> That's a good idea I will check on, but it wouldn't explain why it
> works with the development server and not mod_python.

It might well explain that. There's no guarantee about import order and
certainly no guarantee that it will be the same on different platforms
or installation. In particular, the moment in time when applications are
imported (in django.db.models.loading.AppCache) varies and is usually
much earlier in the development server -- right at the start of things
-- than in a hosted environment.

Regards,
Malcolm



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



Re: Where is dictfetchall ?

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 13:25 -0400, Alex Gaynor wrote:
[...]
> Take a look at the values() method on a queryset:
> http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-fields

Since the original poster was explicitly asking about custom SQL
situations, this isn't a valid solution. Sure, it would be possible to
subclass ValuesQuerySet and use that, but the three line alternative is
going to be 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Where is dictfetchall ?

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 10:24 -0700, MS wrote:
> Hi Malcolm!
> 
> > >  then is there any good (built-in) way
> > > to write custom SQL queries wich would return dicts instead of tuples?
> >
> > You know the order the values will be returned in and you know the names
> > of the columns. So you can create an iterator that returns the
> > dictionary results:
> >
> > def dict_iterator(cursor, col_names):
> >for row in cursor.fetchall():
> >   yield dict(zip(col_names, row))
> >
> 
> 
> Yes, of course I can write it. But isn't a framework supposed to
> relieve us from such a boilerplate code?
> Especially that it was in the framework already. Strange...

It was removed because it wasn't particularly useful and added quite a
bit of usage and implementation overhead. Django is not, and never has
been intended to be, a complete replacement for everything. Using
dictfetchall() requires some overhead to retrieve the column names and
ordering each time from the database and so on. Since you already have
the column names, if you want to create a dictionary, it's actually
faster in almost all cases (except for database wrappers that for some
reason *always* retrieve the column names) to simply incorporate the
above two line function.

In a way, Django is doing you a favour here: less maintenance for
everybody, meaning we can focus on the important stuff, and a faster
path to your goal if you need.

If there's some truly compelling use-case that requires something like
dictfetchall() (and "I want it" isn't a compelling use-case, since the
above solution is of equivalent difficulty and has the advantages I've
mentioned), then explain it on django-dev and we would consider it. But
we don't add things just because somebody, somewhere might want it some
day. It has to be something that isn't otherwise easily possible.

Regards,
Malcolm



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



Re: Foreign Key query question

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 05:45 -0700, nikita kozlovsky wrote:
> On Mar 9, 3:21 am, Malcolm Tredinnick 
> wrote:
> 
> Hello, Malcolm.
> 
> > > Again, the correct syntax would be:
> > > Message.objects.filter(student__isnull=True)
> 
> Why ORM uses LEFT OUTER JOIN on this query ? Why not "... WHERE
> student_id IS NULL" ?

Django's SQL is going exactly what you suspect and not using any outer
join here. Using a simplified version of the original two models:

class Student(models.Model):
   ...

class Message(models.Model):
   title = models.CharField(max_length=50)
   student = models.ForeignKey(Student)

... the SQL that is generated for Message.objects.filter(student=None)
is:

SELECT `outer_message`.`id`, `outer_message`.`title`, 
`outer_message`.`student_id` FROM `outer_message` WHERE 
`outer_message`.`student_id` IS NULL

(I have put it into an application called "outer", hence the table
prefix and I happen to be using MySQL in my directory of test
applications at the moment, hence the backticks instead of normal single
quotes.)

The ORM tries to trim any unnecessary table joins, particularly towards
the end of the join sequence. Any times that it includes unnecessary
tables, or uses outer joins when we can reliably see it should be an
inner join is pretty much a bug. Here, for example, it knows that the
student_id field is a reliable indicator of whether there is a related
object, so it does exactly what you expect.

Sometimes people see extra table joins that they aren't expecting
because they are ordering by a field in the related model. For example,
using Meta.ordering = ("student",) here would require an extra join.
But, the simplest won't need more than the message table.

Does that answer your question?

Regards,
Malcolm


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



Object filtering with a GenericForeignKey field

2009-04-10 Thread M Godshall

I have two models, Comment and Project.  Comments are connected to a
Project through a GenericForeignKey, and each Project is assigned to a
particular user.  I'd like to retrieve the latest comments for all the
projects that a particular user is assigned to, but according to the
Django documentation (and personal tests), a GenericForeignKey fields
cannot be used directly with filter() or exclude(), so I can't do
something like:

Comment.objects.filter(content_object__assigned_to=user).order_by
('date')[:10]

I'm assuming I need to use the extra() method to accomplish something
like this, but I am not very savvy with it, and would appreciate any
help I could get in piecing it together for this scenario.  Any other
ideas would be appreciated as well.  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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Generic relations and unit tests.

2009-04-10 Thread Poromenos

Hello,
I created a model that has a ForeignKey to ContentType, but now I
can't use my test fixtures, since the IDs they point to are random
every time the test database is created. I can't dump the contenttypes
data because then I get many duplicate inserts, since Django rebuilds
them every time it sets up the test DB. Is there any way for me to use
both ContentType and unit tests?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looking for something lighter than Sproutcore or Cappuccino that integrates well with Django

2009-04-10 Thread lkcl



On Apr 10, 9:29 pm, lkcl  wrote:
> > We've recently done the dance through a wide range of tools and ended up
> > selecting Qooxdoo (qooxdoo.org) for a variety of reasons.

 http://demo.qooxdoo.org/current/playground/#Calculator

 ok - found one that works.  and, actually, for a javascript
framework, the source code and readability is not bad - i can see why
you picked it.   so -  just for kicks i might write a calculator
example, for pyjamas, tomorrow.  it won't take long.

 so - yeah, imagine the functionality of qooxdoo, but you get to write
stuff in python, not javascript.  all the ui widget classes are in
python, not javascript. that's pyjamas.

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



Customizing admin form

2009-04-10 Thread Oleg Oltar
Hi!

I have a model which contains several TextFields and CharFields. I want to
make all char fields longer and wider. How to do it?


Thanks,
Oleg

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



This can't be that hard

2009-04-10 Thread Mr. T

Sorry, a QuerySet eval question. Yeah, I'm dumb I know.

My view is creating a query set, XXX.objects.all(). Stale data is
being served up all the time. Read the docs about generic views, when
sets are evaluated, some old posts in this group. Tried ._clone(),
tried iteration, tried len(), nothing will give fresh data in my set.

If I do this in the django manage.py shell it's no problem at 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looking for something lighter than Sproutcore or Cappuccino that integrates well with Django

2009-04-10 Thread lkcl


> We've recently done the dance through a wide range of tools and ended up
> selecting Qooxdoo (qooxdoo.org) for a variety of reasons.

 i'd love to be able to evaluate it, but i get this:

Error: unterminated string literal
Source File: http://demo.qooxdoo.org/current/demobrowser/script/demobrowser.js
Line: 7214, Column: 177
Source Code:
(function(){var m='',k="mshtml",j='"/
>',i="",h='" style="vertical-
align:top;',g="scale",f="qx.client",e="qx.ui.decoration.Util",d=' Also pretty heavy on the UI side, though it has capabilities to be used
> as a component on an otherwise static site.

 yehh, i did an integration of a pyjamas app with a joomla site -
http://worldfairtradeday09.org (see events listings and remember that
that's a live site, not a demo).  so it's possible, but...  yechh :)

 regarding the use of qooxdoo:

* how do you anticipate being able to deal with situations where your
app evolves beyond what qooxdoo has to offer?

* does your application have to face a whopping great hit of the
entire qooxdoo libraries (extjs has a two MEGABYTE hit of javascript,
per page) even if you use a tiny proportion of its functionality?

* has your organisation got the time, skills, and resources, to fix or
improve qooxdoo if you encounter any bugs, flaws or missing features?

not being funny, or anything, but given a choice between under 10,000
lines of python (1500 of which is the python-to-javascript compiler)
and 50,000 lines of javascript, i know which one i'd pick, every time,
even if the widget set that the smaller project provided was more
"basic" than the "feature-rich" javascript framework/widget set.

l.


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



blank = True and unique = True

2009-04-10 Thread CrabbyPete

I have a field for emails. I want it to be blank if nothing in there
and unique if something is. I get a duplicate field error if I have to
messages with blank fields. I can use null = True and it works, but
django's admin blows up. I seen some stuff, but no real solution. Does
anyone have a good solution for this?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looking for something lighter than Sproutcore or Cappuccino that integrates well with Django

2009-04-10 Thread lkcl



On Apr 8, 7:43 pm, Scott Newman  wrote:
> > I've been looking at a couple of RIA frameworks, namely Sproutcore and
> > Cappuccino.  The feel a bit too heavy for me.  Sproutcore does not
> > integrate well with Django
> > The reason I'm posting is to ask the community if they have know of
> > anything that is at a higher level than jQuery + jQuery UI and a lower
> > level than Sproutcore/Cappuccino.  I'd like to find something that has
> > this kind of stuff in it:
> > - Client-side Javascript MVC implementation (Both Sproutcore and
> > Cappuccino have controllers and view)
> > - Easy layouts (I really 
> > likehttp://cappuccino.org/learn/tutorials/automatic-layout/)
> > - Data bindings (Step 4 
> > onhttp://www.sproutcore.com/documentation/hello-world-tutorial-2-your-f...)
>
> When I looked into some of the heavier JavaScript application
> frameworks such as SproutCore, Cappucino, and ExtJS, the biggest
> hurdle I faced was my own approach.
>
> These frameworks are designed to build complete web applications, not
> to be sprinkled within Django template files the way I might do with
> jQuery.

 yes - that's a fact.  pyjamas is no exception.  although gwt-ext
proves that you can mix extjs into GWT, extjs itself is several tens
of thousands of lines of custom-written javascript; gwt-ext itself is
tens of thousands of lines of java - just the integration/startup in
gwt-ext to plumb extjs into gwt is eight _thousand_ lines of
javascript, on its own.

so you _can_ plug in "other JS frameworks" into pyjamas but you end up
thinking, "why in god's name am i spending so much time converting
some ridiculous javascript widget set framework which i'm never going
to fully understand, never going to be able to debug, never going to
be able to extend; why am i going to make myself wholly dependent on
that javascript framework, when i could be writing my own widgets, in
python, writing my own easily customisable, easily understandable
python framework that will be compiled to javascript to run in the web
browser??"

we have several people asking e.g. "i want prototype to be compatible
with pyjamas!" and i warn them, "don't do it - convert the app from
javascript to python / pyjamas and start from there".

it's a different, _much_ easier paradigm.  imagine that python-gtk2
was available for running in _all_ web browsers - that's what it's
like, except the underlying widget set is far more flexible than
python-gtk2.


> Even with my jQuery projects, my initial results were a morass of
> spaghetti code because I was approaching my client-side projects as a
> web developer, relying on my experience with what I'd call "request
> and response" thinking. I had to study the practices of traditional
> stateful, event-driven desktop application development before my
> attempts at these projects went more smoothly. (and I'm still
> learning!)

 yeah - the design of pyjamas is much more along the lines of event-
driven interaction that you'd expect of python-qt4 and python-gtk2
apps.  you register for listening for click events with
"addClickListener()".  you register for keyboard events with
"addKeyboardListener()".  see http://pyjs.org/examples/helloworld/ for
an utterly simple example of this.

> If you settle on a client-side MVC framework, you'll probably want to
> keep the frontend and backend completely separate and use Django for
> web services calls to send and receive data to the frontend.

 yep.  that's the approach i take to every single project with
pyjamas, now - using JSONRPC it's just utterly trivial.  you have to
work _really_ hard to make life difficult for yourself - mostly in the
form of getting over sheer disbelief that it should be much much
harder than it is. see 
http://pyjs.org/examples/jsonrpc/output/JSONRPCExample.html
don't use the python cgi-bin service, use the php one or install the
examples on your own system and set up cgi-bin execution.

l.



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



Re: Generic relations swamp

2009-04-10 Thread zayatzz

Ok, I did some search on web and i took closer look at the
errormessage. :

Request information
GET

No GET data
POST
VariableValue
poll-trans-content_type-object_id-0-keel
u'1'
poll-trans-content_type-object_id-0-id
u''
poll-trans-content_type-object_id-1-keel
u'2'
poll-trans-content_type-object_id-TOTAL_FORMS
u'2'
_save
u'Save'
poll-trans-content_type-object_id-1-name
u'Pollname in russian'
pub_date_1
u'23:45:15'
pub_date_0
u'2009-04-10'
poll-trans-content_type-object_id-1-id
u''
active
u'on'
poll-trans-content_type-object_id-0-name
u'Pollname in estonian'
poll-trans-content_type-object_id-INITIAL_FORMS
u'0'

If i understand this correctly then the content object id is not
beeing saved - it does not save the id of the poll with the
translations. Is this correct? And how can i fix this?

I found many threads about incomplete generic relations support in
admin - they were from '07 or so, so the things could be different.
And i found this :
http://djangoplugables.com/projects/django-genericadmin/

Could this be of any use?

Would anything else help?

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



Re: Looking for something lighter than Sproutcore or Cappuccino that integrates well with Django

2009-04-10 Thread lkcl



On Apr 8, 2:34 pm, Rob Madole  wrote:
> I've been looking at a couple of RIA frameworks, namely Sproutcore and
> Cappuccino.  The feel a bit too heavy for me.  Sproutcore does not
> integrate well with Django.  Cappuccino uses Objective-J as the
> language and I'm not convinced this is a good choice for our team.
>
> The reason I'm posting is to ask the community if they have know of
> anything that is at a higher level than jQuery + jQuery UI and a lower
> level than Sproutcore/Cappuccino.

 well as raymond mentions, you _really_ should look at pyjamas http://pyjs.org
or if you want to cause yourself a headache because you don't like
python and prefer java - GWT.

>  I'd like to find something that has
> this kind of stuff in it:
>
> - Client-side Javascript MVC implementation (Both Sproutcore and
> Cappuccino have controllers and view)

 yep - i outline how pyjamas helps you keep at least the V and the C
on the client-side, in javascript, but you're still actually writing
python - in http://advogato.org/article/993.html

> - Easy layouts (I really 
> likehttp://cappuccino.org/learn/tutorials/automatic-layout/)

 err, that's not enough to understand what the heck is going on, but i
can guess

pyjamas allows you to still use CSS stylesheets, and still allows you
to call setWidth("80%") or "150px" etc. on widgets,

and, also, the "Table"-style panels such as pyjamas.ui.Grid have a
"CellFormatter" option which allows you to set the width and height
(in pixels, em or %, whatever) of individual cells.

FlexTable also allows you to set what "rowspan" and "colspan" of
individual cells.



> - Data bindings (Step 4 
> onhttp://www.sproutcore.com/documentation/hello-world-tutorial-2-your-f...)

  i don't understand in the _slightest_ bit what that's about.  but it
smells like it's substituting a widget into some HTML. if that's the
case, then pyjamas.ui.RootPanel() takes an optional string argument
which can be the "id" in the DOM model HTML, naming the element in the
HTML page that you want the widget to be attached to.

see http://pyjs.org/examples/dynamictable/ - DynaTable.py look for
this:

slot = RootPanel("calendar")

and then note that in public/DynaTable.html there is a 


> So something less heavy,

 yep.  pyjamas is about 9,000 lines - total.

> less "Desktop" feel;

 well, that's up to you.

> more Web 2.0 (Gmail, Digg, Delicious).

 yep.  definitely.

> But more organization than a blank HTML and a
> 

Re: syncdb adding extra table from models

2009-04-10 Thread Ramiro Morales

On Fri, Apr 10, 2009 at 5:29 PM, nixon66  wrote:
>
> I have a legacy database that I used inspectdb on to generate models.
> Once I generated the models and cleaned them up, I ran manage.py
> syncdb. Everything went fine except I have one model that it creates
> another table from with the name of the app attached to the front. So
> the model is called country. But django adds another table called
> myporject_country to the database. Anyone know why it would do this
> and what is the solution?

Use the db_table Meta option:

http://docs.djangoproject.com/en/dev/ref/models/options/#db-table

class Country(models.Model):
# ...
class Meta:
db_table = ' country'

HTH,

-- 
Ramiro Morales
http://rmorales.net

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



Re: single queryset from multiple tables

2009-04-10 Thread Alex Gaynor
On Fri, Apr 10, 2009 at 4:40 PM, veearrsix  wrote:

>
> This question seems to have been asked a few times, but never answered
> fully.
>
> I am looking to query more than one table, but return the results to a
> template as one queryset ordered by date.
>
> The reason i'm doing this is to create a single queryset including
> information from a blog table, twitter table and delicious table to be
> displayed as a sort of log of my online activity sorted by date.
>
> the blog post model:
>
> class Post(models.Model):
>slug = models.SlugField(unique=True)
>tags = TagField()
>title = models.CharField(max_length=80)
>pubdate = models.DateTimeField(default=datetime.datetime.now)
>modifieddate = models.DateTimeField(auto_now=True)
>body = models.TextField()
>draft = models.BooleanField(default=True)
>closed = models.BooleanField()
>
> the delicious model (taken from syncr app)
>
> class Bookmark(models.Model):
># description, href, tags, extended, dt
>description = models.CharField(max_length=250, blank=True)
>url = models.URLField(unique=True)
>tags = TagField()
>extended_info = models.TextField(blank=True)
>post_hash = models.CharField(max_length=100)
>saved_date = models.DateTimeField()
>
> the twitter model (taken from syncr app)
>
> class Tweet(models.Model):
>pub_time= models.DateTimeField()
>twitter_id  = models.PositiveIntegerField()
>text= models.TextField()
>user= models.ForeignKey('TwitterUser')
>
>
> I'd like to get these into one queryset, possibly including a field
> that indicates what type of listing is being displayed. Obviously I
> dont need all of the fields from each of the models, just enough to
> display the title and a possible link.
>
> Thanks in adance, hope someone can help me out, I don't know where to
> start with this.
> >
>
There is no way to get a single QuerySet with results from multiple models.
What you want to do is best approximated like this:

from itertools import chain

sorted(chain(Model1.obejcts.all(), Model2.objects.all()), key=lambda o:
o.pub_date)


Alex
-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



single queryset from multiple tables

2009-04-10 Thread veearrsix

This question seems to have been asked a few times, but never answered
fully.

I am looking to query more than one table, but return the results to a
template as one queryset ordered by date.

The reason i'm doing this is to create a single queryset including
information from a blog table, twitter table and delicious table to be
displayed as a sort of log of my online activity sorted by date.

the blog post model:

class Post(models.Model):
slug = models.SlugField(unique=True)
tags = TagField()
title = models.CharField(max_length=80)
pubdate = models.DateTimeField(default=datetime.datetime.now)
modifieddate = models.DateTimeField(auto_now=True)
body = models.TextField()
draft = models.BooleanField(default=True)
closed = models.BooleanField()

the delicious model (taken from syncr app)

class Bookmark(models.Model):
# description, href, tags, extended, dt
description = models.CharField(max_length=250, blank=True)
url = models.URLField(unique=True)
tags = TagField()
extended_info = models.TextField(blank=True)
post_hash = models.CharField(max_length=100)
saved_date = models.DateTimeField()

the twitter model (taken from syncr app)

class Tweet(models.Model):
pub_time= models.DateTimeField()
twitter_id  = models.PositiveIntegerField()
text= models.TextField()
user= models.ForeignKey('TwitterUser')


I'd like to get these into one queryset, possibly including a field
that indicates what type of listing is being displayed. Obviously I
dont need all of the fields from each of the models, just enough to
display the title and a possible link.

Thanks in adance, hope someone can help me out, I don't know where to
start with this.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Linking Back to Home Page from Template

2009-04-10 Thread Anthony

Thank you both!

Exactly what I need, both for now and moving forward.


On Apr 10, 12:59 pm, Colin Bean  wrote:
> Take a look at the reverse() function and the "url" template 
> tag:http://docs.djangoproject.com/en/dev/topics/http/urls/#reversehttp://docs.djangoproject.com/en/dev/ref/templates/builtins/#url
>
> The "url" tag is what you want to generate a link in your template
> based on one of your URL patterns.
>
> Colin
>
> On Fri, Apr 10, 2009 at 11:50 AM, Anthony  wrote:
>
> > Hi Everyone,
>
> > This is really basic and I tried looking up this question since it
> > can't be a new one, but the closest thread I found was this one:
>
> > http://groups.google.com/group/django-users/browse_thread/
> > thread/d2524403e13fcd22/515358199feebc68?lnk=gst=url+home
> > +page#515358199feebc68">Home page question thread
>
> > I'm trying to set up my templates so that I have a link back to my
> > home page.  I've got the following URL conf set up so that it points
> > to "http://www.mysite.com":
>
> > url(r'^$', myapp.views.home, name = "url-home")
>
> > Is there a way to de-reference "url-home" from within my templates so
> > I don't have to hard code my home page?
>
> > Thanks!
> > 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



syncdb adding extra table from models

2009-04-10 Thread nixon66

I have a legacy database that I used inspectdb on to generate models.
Once I generated the models and cleaned them up, I ran manage.py
syncdb. Everything went fine except I have one model that it creates
another table from with the name of the app attached to the front. So
the model is called country. But django adds another table called
myporject_country to the database. Anyone know why it would do this
and what is the solution?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Running Django admin site using Lighttpd

2009-04-10 Thread stephendwolff

Here's a lighttpd config (just the part for a single website at
fictional ip '1.2.3.4')

project lives in the 'user' home folder, - _project will be your
django project folder - ie the one with 'manage.py'

look at the lighttpd docs for the specifics of the "main" options.

email me off list if you have any specific examples you want to chat
about...

cheers

Stephen

-

$SERVER["socket"] == "1.2.3.4" {

server.document-root= "/home/user/_project"
accesslog.filename = "/home/user/_project/log/access.log"

fastcgi.server = (
"/project.fcgi" => (
"main" => (
"bin-path" => "/home/user/_project/www/project.fcgi",
"socket" => "/tmp/projectlivecgi.sock",
"idle-timeout" => 120,
"check-local" => "disable",
"min-procs" => 2,
"max-procs" => 50,
"allow-x-send-file" => "enable",
)
)
)

alias.url = (
"/media/" => "/usr/local/django/trunk/django/contrib/admin/
media/",
"/stats/" => "/home/user/_project/www/stats/",
"/docs/"  => "/home/user/_project/docs/",
)

url.rewrite-once = (
"^(/media.*)$" => "$1",
"^(/docs.*)$" => "$1",
"^/favicon\.ico$" => "/media/favicon.ico",
"^(/stats.*)$" => "/stats/$1",
"^(/.*)$" => "/project.fcgi$1",
)

}

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



Re: Linking Back to Home Page from Template

2009-04-10 Thread Colin Bean

Take a look at the reverse() function and the "url" template tag:
http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url

The "url" tag is what you want to generate a link in your template
based on one of your URL patterns.

Colin

On Fri, Apr 10, 2009 at 11:50 AM, Anthony  wrote:
>
> Hi Everyone,
>
> This is really basic and I tried looking up this question since it
> can't be a new one, but the closest thread I found was this one:
>
> http://groups.google.com/group/django-users/browse_thread/
> thread/d2524403e13fcd22/515358199feebc68?lnk=gst=url+home
> +page#515358199feebc68">Home page question thread
>
>
> I'm trying to set up my templates so that I have a link back to my
> home page.  I've got the following URL conf set up so that it points
> to "http://www.mysite.com":
>
> url(r'^$', myapp.views.home, name = "url-home")
>
>
> Is there a way to de-reference "url-home" from within my templates so
> I don't have to hard code my home page?
>
> Thanks!
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Linking Back to Home Page from Template

2009-04-10 Thread Joe Sr.

On Apr 10, 1:50 pm, Anthony  wrote:
> Hi Everyone,
>
> This is really basic and I tried looking up this question since it
> can't be a new one, but the closest thread I found was this one:
>
> http://groups.google.com/group/django-users/browse_thread/
> thread/d2524403e13fcd22/515358199feebc68?lnk=gst=url+home
> +page#515358199feebc68">Home page question thread
>
> I'm trying to set up my templates so that I have a link back to my
> home page.  I've got the following URL conf set up so that it points
> to "http://www.mysite.com":
>
> url(r'^$', myapp.views.home, name = "url-home")
>
> Is there a way to de-reference "url-home" from within my templates so
> I don't have to hard code my home page?
>
> Thanks!
> Anthony

Try Home Page


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



rendering values from ManyToMany fields

2009-04-10 Thread Adam Fraser

Hello,

I'm using a ManyToManyField to model a relationship where a "Project"
object may have many different "Stain" objects.  The code is working
successfully and looks like this

class Stain(models.Model):
def __unicode__(self):
return unicode(self.name)
name = models.CharField(max_length=40)

class Project(models.Model):
name = models.CharField(max_length=200)
stains = models.ManyToManyField(Stain, blank=True) # not required
...


However, I've also subclassed ModelForm in the interest of defining a
readonly view of the Project data (ie: a view without inputs).  The
code in forms.py is like this:

class ReadOnlyWidget(forms.Widget):
'''
Widget used by our ModelForm when rendering in readonly mode.
'''
def __init__(self, original_value, display_value):
self.original_value = original_value
self.display_value = display_value
super(ReadOnlyWidget, self).__init__()

def render(self, name, value, attrs=None):
if self.display_value is not None:
return unicode(self.display_value)
if type(value) == list:
#
#  Need to format list fields so they're seen in read only
view
#
return unicode(value)
return unicode(self.original_value)

def value_from_datadict(self, data, files, name):
return self.original_value

class ModelForm(forms.ModelForm):
'''
Define our own model forms so we can use the form to render a
read-only detail page.
'''
def __init__(self, *args, **kwargs):
readonly = kwargs.get('readonly', False)
if readonly:
del kwargs['readonly']
super(ModelForm, self).__init__(*args, **kwargs)
if readonly:
obj = self.instance
for field_name in self.fields:
if hasattr(obj, 'get_%s_display' % field_name):
display_value = getattr(obj,
'get_%s_display' %
field_name)()
else:
display_value = None
self.fields[field_name].widget = ReadOnlyWidget(getattr
(obj, field_name, ''), display_value)

class ProjectForm(ModelForm):
class Meta:
model = Project



The problem I'm running into is that the value that comes into render
for the ManyToManyField is a list of the id's for the selected stains
and not the stains themselves.  I assume I should be getting them
somehow through the django.db.models.fields.related.ManyRelatedManager
which is in the original_value, but I haven't been able to figure out
how.

Anyone know what I'm missing?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to use InlineModelAdmin for ManyToMany without an Intermediary model?

2009-04-10 Thread Christopher Dodd

I realized my question was just a bit off. What I really want is to
create a TabularInline to edit the members relationship on the Group
interface.  This is what you get when you use an intermediary model,
as well as the ability to edit the other members of that model.

I could, of course, create a bogus intermediary model and get what I
want, but it would be really unfortunate if I had to change my (valid)
Model to clean up my Admin interface.

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



Re: Different admin registry behavior with mod_python versus dev server

2009-04-10 Thread Joe Sr.

On Apr 10, 1:27 pm, Alex Gaynor  wrote:
> On Fri, Apr 10, 2009 at 2:24 PM, Joe Sr.  wrote:
>
> > I have been using this little trick to get a list of all my model
> > classes that are subclasses of Component:
>
> > component_list = []
>
> > for k in django.contrib.admin.site._registry:
> >    if issubclass(k, Component):
> >        component_list.append(k)
>
> > It works splendidly under the development server or using the shell
> > under manage.py.  However, under an apache server with mod_python, it
> > doesn't work.  I only get 2 of my classes out of about 12.
>
> > Does admin.site.register() function differently under mod_python?
>
> > The apache2 error_log only had something about "server reached
> > MaxClients setting, consider raising the MaxClients setting."
>
> Where exactly do you have this code?  The issue is that this code might be
> getting excecuted before all your applications have been added to the admin.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero

That's a good idea I will check on, but it wouldn't explain why it
works with the development server and not mod_python.

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



Linking Back to Home Page from Template

2009-04-10 Thread Anthony

Hi Everyone,

This is really basic and I tried looking up this question since it
can't be a new one, but the closest thread I found was this one:

http://groups.google.com/group/django-users/browse_thread/
thread/d2524403e13fcd22/515358199feebc68?lnk=gst=url+home
+page#515358199feebc68">Home page question thread


I'm trying to set up my templates so that I have a link back to my
home page.  I've got the following URL conf set up so that it points
to "http://www.mysite.com":

url(r'^$', myapp.views.home, name = "url-home")


Is there a way to de-reference "url-home" from within my templates so
I don't have to hard code my home page?

Thanks!
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: inheritance, abstract base classes and generic foreign keys

2009-04-10 Thread herr.klein...@googlemail.com



On Apr 10, 12:10 pm, Malcolm Tredinnick 
wrote:
> On Fri, 2009-04-10 at 02:34 -0700, herr.klein...@googlemail.com wrote:
> > Thanks Malcom.
>
> > All right lets see if i could put my real problem simpler. Lets say
> > you are the tutor of a programming course and you want to check the
> > programming assignments semi-automatically.
> > So you would set up a Task to which a student can submit a solution.
> > If the solution is accepted depends on various tests. For example does
> > the program compute the right output to a given input, is everything
> > well formated and right commented, is every occurrence of the students
> > name deleted from the code so that a reviewer that might know the
> > student can grade unbiased, etc.
> > These test are configureable for every assignment that uses them.
> > Every Test inherits a common interface(eg.  run_test()) from the
> > abstract test base class.
> > Now the first step is to assign a bunch of tests to an assignment.
> > This is problematic because different tests are different classes/
> > tables. A task could have one test trough a generic foreign link, but
> > again only one.
>
> You could probably do with one more level of indirection here.
> Assignments can contain a one-to-many to a model that contains a generic
> relation to the right type of test.
>
>         class Task(models.Model):
>            ...
>
>         class Attempt(models.Model):
>            task = models.ForeignKey(Task)
>            content_type = models.ForeignKey(ContentType)
>            object_id = models.IntegerField()
>            test = models.GenericForeignKey()
>
> The test / content_type / object_id collection point to your various
> test classes. You can then run through them with:
>
>         for attempt in task.attempt_set.all():
>            attempt.test.run_test(...)
>
> [...]
>
> > I hope that makes it a bit clearer.
>
> > Cage = Task
> > Animals = Tests
> > walk = run_test()
>
> > I think my analogy wasn't that bad.
>
> Whatever. When I said I couldn't understand it, I wasn't just making
> idle conversation. It wasn't at all clear what were classes or models in
> your original description. This time around, you talked about concrete
> models and assigning something to something else using many-to-many
> relations and so forth. It may well have made sense to you, but that's
> the least of concerns when asking for help.
>
> Regards,
> Malcolm


Thanks for your fast reply.

Thats a nice idea. Works great.
Now if i only could get the tests to appear inline in the task admin
page.
Do you think i could accomplish that by setting the formset in an
inlineModelAdmin to something else or do i think in the wrong
direction.

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



Re: Different admin registry behavior with mod_python versus dev server

2009-04-10 Thread Alex Gaynor
On Fri, Apr 10, 2009 at 2:24 PM, Joe Sr.  wrote:

>
> I have been using this little trick to get a list of all my model
> classes that are subclasses of Component:
>
> component_list = []
>
> for k in django.contrib.admin.site._registry:
>if issubclass(k, Component):
>component_list.append(k)
>
> It works splendidly under the development server or using the shell
> under manage.py.  However, under an apache server with mod_python, it
> doesn't work.  I only get 2 of my classes out of about 12.
>
> Does admin.site.register() function differently under mod_python?
>
> The apache2 error_log only had something about "server reached
> MaxClients setting, consider raising the MaxClients setting."
>
>
> >
>
Where exactly do you have this code?  The issue is that this code might be
getting excecuted before all your applications have been added to the admin.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Different admin registry behavior with mod_python versus dev server

2009-04-10 Thread Joe Sr.

I have been using this little trick to get a list of all my model
classes that are subclasses of Component:

component_list = []

for k in django.contrib.admin.site._registry:
if issubclass(k, Component):
component_list.append(k)

It works splendidly under the development server or using the shell
under manage.py.  However, under an apache server with mod_python, it
doesn't work.  I only get 2 of my classes out of about 12.

Does admin.site.register() function differently under mod_python?

The apache2 error_log only had something about "server reached
MaxClients setting, consider raising the MaxClients setting."


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



How to detect changes in ManyToManyField

2009-04-10 Thread M Godshall

When working with foreign keys, it's really easy to detect changes in
the field by writing a custom save method.  It would look something
like this:

def save(self, force_insert=False, force_update=False):
old_user = None
if Project.objects.filter(id__exact=self.id).count(): #the project
exists
project = Project.objects.get(id=self.id)
old_user = project.assigned_to  #assigned_to field is ForeignKey
(User)
super(Project, self).save()
else: #The project does not exist
super(Project, self).save()
project = Project.objects.get(id=self.id)
new_user = self.assigned_to
if old_user != new_user:
#the assigned_to user has changed. do something

However, after some research and personal testing, it appears you
can't do this with ManyToManyField's because the related table is not
updated until after the save method is called.  In light of this, I
wrote a view to detect this change in the front end, but I can't seem
to figure out the proper syntax to detect a change in the m2m field.
Any feedback on my code would be appreciated.

def edit_project(request, project_id):
"""
Edit a project (marcomm_lead is the M2M field)

"""
project = get_object_or_404(Project, id=project_id)
if request.method == 'POST':
form = EditProjectForm(request.POST, instance=project)
if form.is_valid():
old_marcomm = 
project.marcomm_lead.all().values_list('email',
flat=True).order_by('email') #store the old marcomm_lead emails
new_project = form.save()
if new_project.marcomm_lead.all(): #if project has 
marcomm lead(s)
new_marcomm = 
new_project.marcomm_lead.all().values_list('email',
flat=True).order_by('email') #store the new marcomm_lead emails
if new_marcomm != old_marcomm: #not sure if 
this works
recipients = []
if len(old_marcomm) > 0: #if there were 
old marcomm lead(s)
for lead in new_marcomm:
if lead not in 
old_marcomm: #never works.  please advise! Only
add lead to list if it was not in the old marcomm list

recipients.append(lead) #add the person's email to the list
else: #there were no old marcomm lead(s)
for lead in new_marcomm: #for 
each marcomm lead
recipients.append(lead) 
#add the person's email to the list
current_site = 
Site.objects.get_current()
subject = 
render_to_string('projects/email/
marcomm_lead_subject.txt', { 'project': project })
message = 
render_to_string('projects/email/
marcomm_lead_body.txt', { 'site': current_site, 'project': project })
send_mail(subject, message, 
settings.DEFAULT_FROM_EMAIL,
recipients)
success_url = project.get_absolute_url()
return HttpResponseRedirect(success_url)
else:
form = EditProjectForm(instance=project)
return render_to_response('projects/edit_project.html', { 'project':
project, 'form': form }, context_instance=RequestContext(request))
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Modifying the User model

2009-04-10 Thread soniiic

The way I achieved this was to make my own registration form and use
this:

email = forms.EmailField(widget=forms.TextInput(attrs=dict
(attrs_dict,maxlength=75)),label=_(u'Email address'))

where attrs_dict was earlier defined as:
attrs_dict = { 'class': 'required' }

also, the email address isn't checked for uniqueness (which i think is
silly) so I added this:

def clean_email(self):
"""
Validate that the email is not already in use.

"""
try:
user = 
User.objects.get(email__iexact=self.cleaned_data['email'])
except User.DoesNotExist:
return self.cleaned_data['email']
raise forms.ValidationError(_(u'This email is already taken. 
Please
choose another.'))

On Apr 10, 6:51 pm, Davide  wrote:
> Hi all,
> we've been using the django User model from contrib.auth.models
> As we want to re-use as much code as possible, is there a way to edit
> the class properties, making the "email" field required? As a default
> this is not a required field. Gooogled for some answers but didn't
> find one, but if I missed something please let me know.
> Thanks in advance,
> Davide
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Modifying the User model

2009-04-10 Thread Davide

Hi all,
we've been using the django User model from contrib.auth.models
As we want to re-use as much code as possible, is there a way to edit
the class properties, making the "email" field required? As a default
this is not a required field. Gooogled for some answers but didn't
find one, but if I missed something please let me know.
Thanks in advance,
Davide

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



Re: Where is dictfetchall ?

2009-04-10 Thread Alex Gaynor
On Fri, Apr 10, 2009 at 1:24 PM, MS  wrote:

>
> Hi Malcolm!
>
> > >  then is there any good (built-in) way
> > > to write custom SQL queries wich would return dicts instead of tuples?
> >
> > You know the order the values will be returned in and you know the names
> > of the columns. So you can create an iterator that returns the
> > dictionary results:
> >
> > def dict_iterator(cursor, col_names):
> >for row in cursor.fetchall():
> >   yield dict(zip(col_names, row))
> >
>
>
> Yes, of course I can write it. But isn't a framework supposed to
> relieve us from such a boilerplate code?
> Especially that it was in the framework already. Strange...
>
> Regards
> MS
>
> >
>
Take a look at the values() method on a queryset:
http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-fields

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Re: Where is dictfetchall ?

2009-04-10 Thread MS

Hi Malcolm!

> >  then is there any good (built-in) way
> > to write custom SQL queries wich would return dicts instead of tuples?
>
> You know the order the values will be returned in and you know the names
> of the columns. So you can create an iterator that returns the
> dictionary results:
>
>         def dict_iterator(cursor, col_names):
>            for row in cursor.fetchall():
>               yield dict(zip(col_names, row))
>


Yes, of course I can write it. But isn't a framework supposed to
relieve us from such a boilerplate code?
Especially that it was in the framework already. Strange...

Regards
MS

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



Re: Generating USER documentation?

2009-04-10 Thread Baxter

> On 10 Apr., 16:28, "bax...@gretschpages.com" 
> wrote:
>
> > What I'm after is documentation for the admin users, similar to the
> > generated documentation, only less technical. A simple how-to for
> > people who just want to know how to do things in the admin, but don't
> > care about views, models and template tags.

Thinking it through a bit more, I'm thinking something like the
existing documentation would work, perhaps using a docstring in each
app's admin.py.
I still have no idea how to make it happen, though.

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



Re: Generating USER documentation?

2009-04-10 Thread patrickk

something like this is included with grappelli, see
http://code.google.com/p/django-grappelli/

patrick


On 10 Apr., 16:28, "bax...@gretschpages.com" 
wrote:
> What I'm after is documentation for the admin users, similar to the
> generated documentation, only less technical. A simple how-to for
> people who just want to know how to do things in the admin, but don't
> care about views, models and template tags.
>
> Is there an easy way to create/generate such a thing?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 1 django project, 2 targets (fastcgi and GAE) - best practices?

2009-04-10 Thread Konrad Martin

Hi cgarvey

On 10 Apr., 15:25, cgarvey  wrote:
> It (migrating Django to appEngine via appEnginePatch) required changes to the 
> models,

You are right, model changes are unevitable when migrating from a
relational database, MySQL for example to Google's big table.

Google doesn't use a relational database because it doesn't scale very
good. So developing an application with a hopefully big audience
anyway it might be worthwile to think about restricting on database
usage whith good scalability, eg not to use Django features which
don't work in the appEngine world.

Afterwards is should be easy to migrate to appEngine, you only have to
exchange the django model for the according appEngine model, eg
instead of writing
from django.db import models
  class xyz(models.Model):
title=models.CharField() ...

you write
from google.appengine.ext import db
  class xyz(db.Model):
title=db.StringProperty() ...

Hopefully a simple translation process and vice versa if you want to
switch to another provider once your code is based on database usage
with good scalability.

In my eyes that's at least the development target of the app-engine-
patch project.

Konrad


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



Generating USER documentation?

2009-04-10 Thread bax...@gretschpages.com

What I'm after is documentation for the admin users, similar to the
generated documentation, only less technical. A simple how-to for
people who just want to know how to do things in the admin, but don't
care about views, models and template tags.

Is there an easy way to create/generate such a thing?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Help! PNG file upload error...

2009-04-10 Thread Brian Neal

On Apr 9, 12:45 am, higer  wrote:
> When I upload a PNG file and use PIL to handle it,there will be an
> error occured:
> 'NoneType' object is unsubscriptable
>
> I do not know why and other formats(BMP GIF JPG JPEG) are all ok.

I don't know if this is your problem, but in order to use certain file
formats in PIL you have to have some prequisites installed. Here is
the PIL doc page for PNG support:

http://www.pythonware.com/library/pil/handbook/format-png.htm

In particular, note:

"PIL identifies, reads, and writes PNG files containing "1", "L", "P",
"RGB", or "RGBA" data. Interlaced files are currently not supported."

And also:

"Note: To enable PNG support, you need to build and install the ZLIB
compression library before building the Python Imaging Library. See
the distribution README for details."

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



Re: 1 django project, 2 targets (fastcgi and GAE) - best practices?

2009-04-10 Thread cgarvey

On Apr 10, 11:33 am, Konrad Martin  wrote:
> there is the appEnginePatch project too. Dedicated to deploy existing
> Django on 
> appEngine.http://code.google.com/p/app-engine-patch/wiki/Documentation


Thanks Konrad,

I came across that afterwards, and had a quick look. It still required
changes to the models, I think, but I'll give it more consideration
next week again. Thanks for the suggestion!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Foreign Key query question

2009-04-10 Thread nikita kozlovsky

On Mar 9, 3:21 am, Malcolm Tredinnick 
wrote:

Hello, Malcolm.

> > Again, the correct syntax would be:
> > Message.objects.filter(student__isnull=True)

Why ORM uses LEFT OUTER JOIN on this query ? Why not "... WHERE
student_id IS NULL" ?

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



Re: 1 django project, 2 targets (fastcgi and GAE) - best practices?

2009-04-10 Thread Konrad Martin

Hi cgarvey

there is the appEnginePatch project too. Dedicated to deploy existing
Django on appEngine.
http://code.google.com/p/app-engine-patch/wiki/Documentation

It has got a ready made app-engine-patch sample. Download
http://app-engine-patch.googlecode.com/files/app-engine-patch-sample-1.0.zip
and try its auth, admin and registration capabilites.

If you have got questions there is the app angine patch discussion
group
http://groups.google.com/group/app-engine-patch?hl=en

Konrad


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



Re: Running django on a web hosting account

2009-04-10 Thread Konrad Martin

Hi Sergio

> - Google App Engine[1] - you will need adapt somethings in your code.

There is the project appEnginePatch to deploy django on Google
appEngine out of the box.
http://code.google.com/p/app-engine-patch/wiki/Documentation

The app-engine-patch has got a ready made sample. Download
http://app-engine-patch.googlecode.com/files/app-engine-patch-sample-1.0.zip
and try.

You will need to have Python 2.5 or 2.6 (not 3.0)
windows: http://www.python.org/ftp/python/2.5.4/python-2.5.4.msi
and Google appEngine SDK
windows: http://googleappengine.googlecode.com/files/GoogleAppEngine_1.2.0.msi
installed.

There is a app engine patch discussion group too:
http://groups.google.com/group/app-engine-patch?hl=en

Konrad

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



Re: How best to deal with non-abstract model inheritance in the admin

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 05:41 -0700, AndyB wrote:
> Hi,
> 
> I've got a model called Courses and a model that inherits from it
> called SpecialCourses that has some extra fields.
> 
> It seems that any SpecialCourses I add also show up in the changelist
> for Courses which will be confusing for content editors ("remember to
> edit them under SpecialCourses or you won't see the extra fields").
> 
> I could override the default ModelAdmin queryset for Courses and
> filter out any that also have an associated SpecialCourse.
> 
> Is this the best approach or have I overcomplicated things?

I think that -- filtering them out in the admin queryset -- sounds like
the correct approach if that's the way you want to model things. Should
be fairly straightforwards.

Regards,
Malcolm



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



Re: ForeignKey to a Base Model and Relationships with the Inherited Models

2009-04-10 Thread cfiles

On Apr 8, 8:59 pm, Malcolm Tredinnick 
wrote:
> (1) Reflect the requirement in the data modelling. Particularly useful
> if it's going to be a firm requirement, always. The way to provide
> relations between a model and multiple other models is to use the
> GenericRelation field, which tracks the content type along with the pk
> value for the related object.

I will look into this. That is more along the lines of what I want.

> (2) Override the admin change form so that the appropriate account type
> information is also collected.

Yeah, I wanted to avoid this route :)

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



How best to deal with non-abstract model inheritance in the admin

2009-04-10 Thread AndyB

Hi,

I've got a model called Courses and a model that inherits from it
called SpecialCourses that has some extra fields.

It seems that any SpecialCourses I add also show up in the changelist
for Courses which will be confusing for content editors ("remember to
edit them under SpecialCourses or you won't see the extra fields").

I could override the default ModelAdmin queryset for Courses and
filter out any that also have an associated SpecialCourse.

Is this the best approach or have I overcomplicated things?

regards,

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



Re: Strange FileField behaviour

2009-04-10 Thread John Baker

Thanks mucho Malcolm. It seems I did forget to set the form encoding
in the one template but not the others!

> The usual reason files aren't uploaded is because you forget to specify
> the enctype attribute as a multipart/form-data encoding. 
> Seehttp://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-
>
> Did you perhaps forget to do that in the template that isn't working?
> This would be easy to do if you were using the form.is_multipart() test
> on another form object and combining it with your file upload form in
> the same HTML "form" element.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Where is dictfetchall ?

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 04:50 -0700, MS wrote:
[...]
> If it's not available any longer

Which it isn't.

>  then is there any good (built-in) way
> to write custom SQL queries wich would return dicts instead of tuples?

You know the order the values will be returned in and you know the names
of the columns. So you can create an iterator that returns the
dictionary results:

def dict_iterator(cursor, col_names):
   for row in cursor.fetchall():
  yield dict(zip(col_names, row))

Regards,
Malcolm



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



Re: Strange FileField behaviour

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 04:41 -0700, John Baker wrote:
> I have a form that validates the size of a file and it works in one
> page but not another. This is very strange. The only difference
> between the two templates is that the working one has only a single
> form (below) and the non-working one has 3 forms (including the form
> below). For some reason, in a non-working situation the value of f is
> None.

When you say the template has 3 forms, do you mean three separate HTML
forms, or three form objects passed to the template that are combined
into a single HTML form?

The usual reason files aren't uploaded is because you forget to specify
the enctype attribute as a multipart/form-data encoding. See
http://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files-to-a-form
 .

Did you perhaps forget to do that in the template that isn't working?
This would be easy to do if you were using the form.is_multipart() test
on another form object and combining it with your file upload form in
the same HTML "form" element.

Regards,
Malcolm



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



Where is dictfetchall ?

2009-04-10 Thread MS

Hi All,
Who dumped dictfetchall from Django? I can see it used to be there,
but I can't find it in 1.0.
http://code.djangoproject.com/ticket/2662
http://blog.doughellmann.com/2007/12/using-raw-sql-in-django.html

If it's not available any longer then is there any good (built-in) way
to write custom SQL queries wich would return dicts instead of tuples?
Or just hacking like in the link above?

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



Strange FileField behaviour

2009-04-10 Thread John Baker

I have a form that validates the size of a file and it works in one
page but not another. This is very strange. The only difference
between the two templates is that the working one has only a single
form (below) and the non-working one has 3 forms (including the form
below). For some reason, in a non-working situation the value of f is
None.

Anyone got any ideas? It is very strange and driving me crazy.. Django
1.0.2 is just not putting the UploadedFile object in cleaned_data when
I believe it should!

class DocumentFileUploadForm(forms.Form):
file1 = forms.FileField(label="Upload CV / Folio", required=False)

def clean(self):
f = self.cleaned_data.get('file1')
if f is None:
raise ValidationError("Please attach a CV!")
if f.size > settings.MAX_FILE_SIZE:
raise ValidationError("Total file size exceeds the allowed
limit")

return self.cleaned_data

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



Re: Generic relations swamp

2009-04-10 Thread zayatzz

does anyone know how to solve this problem?

Alan

On 9 apr, 21:54, zayatzz  wrote:
> Thanks.
>
> That worked for enabling translations for poll names - i had to insert
> 'from django.contrib.contenttypes import generic', right?
> It worked, but it raised few more questions. When creating poll i get
> lines for name translations now and in front of each of them there is
> language drop down menu, where i can choose to which language this
> translation belongs to. How can i replace that with just language
> name. Do i have to create some kind of loop for that view (/poll/poll/
> add), so i just get correct amount of name translations and nothing
> else?
>
> in any case it worked, but when i tried to save that poll i got this
> error :
>
> Request URL:    http://127.0.0.1:8000/admin/poll/poll/add/
> Exception Type:         TypeError
> Exception Value:        coercing to Unicode: need string or buffer,
> GenericRelatedObjectManager found
>
> Runnin search on that error i found 
> :http://mail.python.org/pipermail/python-list/2006-July/566947.html
>
> Does that mean, that connection between translation and poll name
> failed or something else at all?
>
> Alan.
>
> On Apr 9, 6:36 pm, matehat  wrote:
>
> > First of all, the ModelAdmin needs to know about how to handle the
> > generic relations and whether you even need them to appear. You need
> > to subclass "generic.GenericTabularInline" (in the same way you
> > subclassed "admin.ModelAdmin") and specify fields you want to be able
> > to edit on that Trans object (probably only the "name" field if I
> > understood right) and the actual model (here Trans). Then, you'd need
> > to add the 'inlines' attribute to your PollAdmin and add the
> > GenericTabularInline subclass. So your code should look something
> > like :
>
> >http://dpaste.com/30763/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problem setting up Admin site per chapter 6

2009-04-10 Thread Patrick Kennedy

Yes, thanks a lot. I got it working!  :)

Patrick
Website: www.pknews.org



On Wed, Apr 8, 2009 at 9:24 PM, Xpineapple  wrote:
>
>
> Per manual ( www.djangobook.com/en/2.0/ ), Chapter 6, I try to setup
> the admin site.  My version of Django is (1, 0, 2, 'final', 0) which
> is covered by this manual.
>
> However, after following guidance on activating site, I get this error
> when running server and going to http://127.0.0.1:8000/admin/ -
>
> AttributeError: 'AdminSite' object has no attribute 'urls'
>
> The steps are very easy to follow, so perhaps something is problematic
> here?  I am running on Linux Fedora 10 X84_64.  Please help. Thanks...
>
> >
>

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



Re: Help! PNG file upload error...

2009-04-10 Thread higer

I want to get a thumbnail version of the uploaded image,so I have to
use PIL to handle it.
But I do not know why that error occured.
We can know that the chafferer is either the Django or the PIL.
Then I wrote a .py script to handle images of different format ,all
goes well.The operations are the same as views.py.
Thus,I think there may be a problem in Django.


On Apr 9, 2:41 pm, Kushal Das  wrote:
> On Thu, Apr 9, 2009 at 11:15 AM, higer  wrote:
>
> > When I upload a PNG file and usePILto handle it,there will be an
> > error occured:
> > 'NoneType' object is unsubscriptable
>
> > I do not know why and other formats(BMP GIF JPG JPEG) are all ok.
> > The following is  my code in my views.py:
>
> > f = request.FILES["imagefile"]
> > fileExt = (f.name).split(".")[-1].lower() #get the pic's extension
> > parser = ImageFile.Parser()
> > for chunk in f.chunks():
> >       parser.feed(chunk)
> > img = parser.close()
> > img.save("test"+"."+fileExt)
>
> I guess you can save the file uploaded directly, any special reason to usePIL?
>
> Kushal
> --http://fedoraproject.orghttp://kushaldas.in
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: inheritance, abstract base classes and generic foreign keys

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 02:34 -0700, herr.klein...@googlemail.com wrote:
> Thanks Malcom.
> 
> All right lets see if i could put my real problem simpler. Lets say
> you are the tutor of a programming course and you want to check the
> programming assignments semi-automatically.
> So you would set up a Task to which a student can submit a solution.
> If the solution is accepted depends on various tests. For example does
> the program compute the right output to a given input, is everything
> well formated and right commented, is every occurrence of the students
> name deleted from the code so that a reviewer that might know the
> student can grade unbiased, etc.
> These test are configureable for every assignment that uses them.
> Every Test inherits a common interface(eg.  run_test()) from the
> abstract test base class.
> Now the first step is to assign a bunch of tests to an assignment.
> This is problematic because different tests are different classes/
> tables. A task could have one test trough a generic foreign link, but
> again only one.
 
You could probably do with one more level of indirection here.
Assignments can contain a one-to-many to a model that contains a generic
relation to the right type of test.

class Task(models.Model):
   ...

class Attempt(models.Model):
   task = models.ForeignKey(Task)
   content_type = models.ForeignKey(ContentType)
   object_id = models.IntegerField()
   test = models.GenericForeignKey()

The test / content_type / object_id collection point to your various
test classes. You can then run through them with:

for attempt in task.attempt_set.all():
   attempt.test.run_test(...)

[...]
> I hope that makes it a bit clearer.
> 
> Cage = Task
> Animals = Tests
> walk = run_test()
> 
> I think my analogy wasn't that bad.

Whatever. When I said I couldn't understand it, I wasn't just making
idle conversation. It wasn't at all clear what were classes or models in
your original description. This time around, you talked about concrete
models and assigning something to something else using many-to-many
relations and so forth. It may well have made sense to you, but that's
the least of concerns when asking for help.

Regards,
Malcolm


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



Re: trying to use the aggregate functions

2009-04-10 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 02:05 -0700, chris wrote:
> Hi there,
> 
> Here I am trying to use the aggregate functions available in SVN trunk
> (I am not sure if they have been released).  The following is a
> simplified version of the models involved:
> 
> class Edition(models.Model):
> edkey = models.TextField()
> 
> class TextChar(models.Model):
> edition = models.ForeignKey(Edition)
> char= models.TextField(blank=True)
> unichar = models.ForeignKey(Char)
> 
> class Char(AdminMetadata):
> unicode = models.CharField(max_length=7, blank=True)
> 
> and here is what I am trying to do with them:
> 
> In [55]: c = Char.objects.get(pk=1)
> In [56]: c.textchar_set.values('edition').annotate(Count('char'))
> Out[56]: [{'char__count': 46, 'edition': 1}, {'char__count': 1,
> 'edition': 2}]
> 
> So I want to find out how many characters do occur in which edition
> and I get the result as expected.  However, instead of the edition
> objects, what I get back are the pk values of the edition.  Is there a
> way to change this so that I get the objects that can be rendered in a
> template?

The problem here is that there is no canonical object to give back. It's
an ambiguous request. You are asking for a char__count value per edition
value, not per TextChar object.

However there could be, and likely are, many TextChar objects with the
same edition value, so it would be ambiguous as to which particular
object to return. Since there's no natural choice, there's no API to ask
Django to guess or provide a sample object or anything like that. It's
not appropriate to return a model object for that type of query.

What is the real problem you are trying to solve here? Why do you need
an object back?

Regards,
Malcolm



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



Re: inheritance, abstract base classes and generic foreign keys

2009-04-10 Thread herr.klein...@googlemail.com

Thanks Malcom.

All right lets see if i could put my real problem simpler. Lets say
you are the tutor of a programming course and you want to check the
programming assignments semi-automatically.
So you would set up a Task to which a student can submit a solution.
If the solution is accepted depends on various tests. For example does
the program compute the right output to a given input, is everything
well formated and right commented, is every occurrence of the students
name deleted from the code so that a reviewer that might know the
student can grade unbiased, etc.
These test are configureable for every assignment that uses them.
Every Test inherits a common interface(eg.  run_test()) from the
abstract test base class.
Now the first step is to assign a bunch of tests to an assignment.
This is problematic because different tests are different classes/
tables. A task could have one test trough a generic foreign link, but
again only one. What i want to do is this:

for test in task.test_set()
test.run_test(solution)

where task.test_set() is the problematic part.

I hope that makes it a bit clearer.

Cage = Task
Animals = Tests
walk = run_test()

I think my analogy wasn't that bad.

Serialization of the test sub classes data members wouldn't be a
problem, because i access a test only in two cases: on creation an to
run run_test(). I would never need to join the checker configuration
against anything.
But yeah, i like the idea of having the configuration in human
readable form in the database much more.

Sorry that i cant post code. I don't have any that would explain it
more, because i haven't implemented any of the above ideas because
they all seam to be a dead end.

So if anybody could enlighten me,
that would be greatly appreciated.

Daniel



On Apr 10, 1:43 am, Malcolm Tredinnick 
wrote:
> On Thu, 2009-04-09 at 15:48 -0700, herr.klein...@googlemail.com wrote:
> > Hi!
>
> > I have cages filled with animals. All animals can move, but they do it
> > all differently. Some animals even have attributes the others don't.
> > Now i want all the animals in a cage to move.
>
> > How do i implement that in Django? First i thought i could use simple
> > inheritance, serialize the attributes and save them to a TextField,
> > but i have no idea where to unserialize them at fetchtime. So i
> > figured that wouldn't be the best approach.
>
> > So what i found out what i really want is an abstract animal base
> > class. Now the Problem is how do i get them in the cage? I could use
> > generic foreign keys, but in this case i would need one for every
> > animal, which wouldn't work.
> > So what am i missing here? How is it intended to be?
>
> I have sat and thought about this for a while and I still have
> absolutely no idea what you're asking. Could you forget about the
> abstract stuff with animals and cages and show some small examples of
> the code you're trying to write and an explanation of what isn't
> working? Is an animal class meant to be linked to a cage class? Is a
> cage even a class, or is it an attribute? Why was serializing ever an
> option for relational model representation?
>
> Unfortunately, you've over-generalised your problem to the degree that
> it probably only makes sense to you now. :-)
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trying to use the aggregate functions

2009-04-10 Thread James Bennett

On Fri, Apr 10, 2009 at 4:05 AM, chris  wrote:
> So I want to find out how many characters do occur in which edition
> and I get the result as expected.  However, instead of the edition
> objects, what I get back are the pk values of the edition.

This is expected behavior; when you use values() you are saying "I do
not want the full objects, I only want raw database values". And the
raw DB value for a foreign key relationship is whatever value happens
to be in that column -- in this case, the ID.



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

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



Re: registration and profile must save at a time

2009-04-10 Thread Praveen

Thanks and i tried to do in same fashion as Bennett suggested
but getting errror

def register_handle_form(request, redirect=None):

print "I am in handle form"
form_class = utils.get_profile_form()
if request.method == 'POST':
print "i am in profile post"
profileform = form_class(data=request.POST,
files=request.FILES)
form = RegistrationForm(request.POST)
if form.is_valid():
contact = form.save(request)
profile_obj = profileform.save(commit=False)
profile_obj.user = request.user
profile_obj.save()
if not redirect:
redirect = urlresolvers.reverse
('registration_complete')
return (True, http.HttpResponseRedirect
(urlresolvers.reverse('registration_complete')))
#return HttpResponseRedirect(reverse
('registration_complete'))

else:
initial_data = {}
try:
contact = Contact.objects.from_request(request,
create=False)
initial_data = {
'email': contact.email,
'first_name': contact.first_name,
'last_name': contact.last_name }
except Contact.DoesNotExist:
log.debug("No contact in request")
contact = None

signals.satchmo_registration_initialdata.send(contact,
contact=contact,
initial_data=initial_data)

form = RegistrationForm(initial=initial_data)
profileform = form_class(data=request.POST,
files=request.FILES)
return (False, form, profileform)



def activate(request, activation_key):
from registration.models import RegistrationProfile
activation_key = activation_key.lower()
account = RegistrationProfile.objects.activate_user
(activation_key)

if account:
# ** hack for logging in the user **
# when the login form is posted, user = authenticate
(username=data['username'], password=data['password'])
# ...but we cannot authenticate without password... so we work-
around authentication
account.backend = settings.AUTHENTICATION_BACKENDS[0]
login(request, account)
contact = Contact.objects.get(user=account)
request.session[CUSTOMER_ID] = contact.id
send_welcome_email(contact.email, contact.first_name,
contact.last_name)
signals.satchmo_registration_verified.send(contact,
contact=contact)

context = RequestContext(request, {
'account': account,
'expiration_days': config_value('SHOP',
'ACCOUNT_ACTIVATION_DAYS'),
})
return render_to_response('registration/activate.html', context)


def register(request, redirect=None, template='registration/
registration_form.html'):
"""
Allows a new user to register an account.
"""
print " I am in my register"
ret = register_handle_form(request, redirect)
#ret = register_handle_profile_form(request, redirect)
#form_class = utils.get_profile_form()
#pform = form_class(data=request.POST, files=request.FILES)
print "Ret length :", len(ret)
print "Ret :", ret
#print "Pet :", pform
success = ret[0]
todo = ret[1]
profiledo = ret[2]
#print "Profile object :", profiledo
if len(ret) > 2:
extra_context = ret[2]
#print "If extra context", extra_context
else:
extra_context = {}
#print "Else extra context", extra_context

if success:
return "Successfull"
else:
if config_get_group('NEWSLETTER'):
show_newsletter = True
else:
show_newsletter = False

ctx = {
'form': todo,
'pform': profiledo,
'title' : _('Registration Form'),
'show_newsletter' : show_newsletter
}
print "CTX :", ctx
#if extra_context:
 #   ctx.update(extra_context)

context = RequestContext(request, ctx)
return render_to_response(template, context)

ERROR:
tuple index out of range

profiledo = ret[2]  //in this line
when i go to accounts/register/ at first time and tried to print the
ret
Ret : (False, , ) it
returns me a tuple with 3 elements after clicking on register button
it return me tuple with 2 elements.


On Apr 9, 11:50 am, James Bennett  wrote:
> On Thu, Apr 9, 2009 at 12:27 AM, Praveen  
> wrote:
> > Thank you so much Malcolm but to display extra fields on sign up we
> > will have to customize the django.contric.auth.forms then that form is
> > generated from the user models i am so much confused whether i will
> > have to add extra field in user model class or not but i do not want
> > change the structure of auth_user table. ok in a single line i want
> > django-registration and django-profile to be mingle in one form. could
> > you please suggest me link or idea.
>
> So you need to provide:
>
> 1. A form class which has all the fields you care about, and
> 2. A 'save()' method on 

Re: add 'link' to admin interface of model

2009-04-10 Thread ramu...@gmail.com

If I understand correctly the same problem solve by this code:


def colored_name(self):
return '%s %s' %
(self.color_code, self.first_name, self.last_name)
colored_name.allow_tags = True


manual http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-display




On Apr 9, 8:31 pm, Psihonavt  wrote:
> good evening guys!
> have a question:
> in my model i have a field, like
> guarantee = models.CharField(_("Link to guarantee"), max_length=250,
> blank=True)
> to this charfield, on some conditions, i generate some link 
> (f.e.http://myshop.com/guarantee/47/)
> What i want is:
> in admin interface of my model, in place where my guarantee field is
> (where normally some input-boxes) i want add some click able link,
> with url from that CharField (http://myshop.com/guarantee/47/)
>
> I'll be appreciated for any suggestions.
>
> thnx
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Problem with request.session.set_expiry(0)

2009-04-10 Thread Rama Vadakattu

hi,
1) I have done request.session.set_expiry(0)
 which means user session should expire when he closes the
browser.

But it is not happening i have tested it several times? Any hint
on what can be wrong?

HOw did it test?
---
By closing browser and opening again.




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



trying to use the aggregate functions

2009-04-10 Thread chris

Hi there,

Here I am trying to use the aggregate functions available in SVN trunk
(I am not sure if they have been released).  The following is a
simplified version of the models involved:

class Edition(models.Model):
edkey = models.TextField()

class TextChar(models.Model):
edition = models.ForeignKey(Edition)
char= models.TextField(blank=True)
unichar = models.ForeignKey(Char)

class Char(AdminMetadata):
unicode = models.CharField(max_length=7, blank=True)

and here is what I am trying to do with them:

In [55]: c = Char.objects.get(pk=1)
In [56]: c.textchar_set.values('edition').annotate(Count('char'))
Out[56]: [{'char__count': 46, 'edition': 1}, {'char__count': 1,
'edition': 2}]

So I want to find out how many characters do occur in which edition
and I get the result as expected.  However, instead of the edition
objects, what I get back are the pk values of the edition.  Is there a
way to change this so that I get the objects that can be rendered in a
template?

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



Re: Flup question

2009-04-10 Thread mysticalfirebird

Thanks
this is my misunderstanding,I had consider flup can be a webserver and
other webserver can call it.

l`ll try to setup lighttpd or cherokee.

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



Re: Flup question

2009-04-10 Thread Alex Koshelev

Flup is just a proxy library between your Django project and
web-server. It is communicating with web-server through FastCGI
protocol. So you cannot just start FastCGI daemon and visit you
project with browser. To work properly you must set up your
web-server's FastCGI capabilities and direct it to flup's daemon
according to documentation [1].

[1]: 
http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#howto-deployment-fastcgi


On Fri, Apr 10, 2009 at 8:31 AM, mysticalfirebird
 wrote:
>
> I`m a rookie.
> I wonder how flup work.
>
> I have typed  "python manage.py runfcgi  host=127.0.0.1 port=8000
> daemonize=false ".
> the  terminal return nothing but a newline.
> I try to visit http://127.0.0.1:8000/ with my Firefox.but no page
> return.and the port(127.0.0.1:8000) is used.
>
> if I type "python manage.py runfcgi " without host params . the
> terminal will return homepage`s HTML code on terminal self.
>
> if i type“python manage.py runfcgi   daemonize=false host=127.0.0.1
> port=8000 protocol=scgil", terminal return “WSGIServer starting up”
> and then I visit http://127.0.0.1:8000/ the terminal return "Protocol
> error 'invalid netstring length'"
> I still can`t get my page on browser. which run well on web server of
> django self(manage.py runserver).
>
> my system:
> ubuntu 8.10
> python 2.5.2
> django 1.0.2 final
> flup 1.0.1
>
>
> >
>

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