Re: "slice" xhtml content and keep it valid xhtml?

2006-09-27 Thread Luke Plant

On Wednesday 27 September 2006 08:09, Gábor Farkas wrote:

> i have the following problem:
>
>
> in a page-template, i have to display the first 100 characters of
> some html content.
>
> the problem is, that if i simply slice the html-content as if it were
> plaintext, then sometimes some tags get cut in the half etc...
>
> so, is there a way to do this slicing without losing html-validness?

What if your 100 characters stops with some tag still open, or multiple 
tags still open -- e.g. in the middle of a cell of a table?  In 
general, you can't solve this.  How should those tags be closed again?  
You could in theory have a naive solution that just closes all opens 
tags, but there's no guarantee this will be appropriate.

The only way I can think to do this is strip the HTML, then slice.  
Also, remember that Django currently uses bytestrings internally 
(default UTF8), so you might want to decode into unicode strings before 
slicing, then re-encode.

Luke

-- 
Hofstadter's Law: It always takes longer than you expect, even when you 
take into account Hofstadter's Law.

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: threadlocals with limit_choices_to in models

2006-09-27 Thread Luke Plant

On Thursday 21 September 2006 21:56, Kr0n wrote:
> ibson wrote:
> > Apologiz for saying it worked!!! It doesn't work after some times
> > even after restarting apache every 15 minutes!!!
> > So the question is always there. And it seems I am not the only to
> > hav this problem
>
> Yep. I've also a problem with this, but for me it's simply doesn't
> work at all. I'm using the info in
> http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser plus
> "limit_choices_to" like ibson but with no success.
>
> Anyone could bring some light on this?

The point at which you are calling 'threadlocals.get_current_user()' is 
when the class is being constructed.  If you have some Python code like 
this:

class Foo:
   bar = do_something()

then do_something() is called when Python reads the module containing 
Foo and executes it, and creates a class object.  This happens *once* 
for top level classes like this (i.e. classes that are not being 
dynamically generated etc), so you can't use this to have data that 
will vary on a per-request basis.  The value of 'bar', 
or 'usergroup=threadlocals.get_current_user()' in the example code, is 
fixed from the first time this module is imported.  Whether the 
threadlocal middleware code has been called at all by this point may 
well depend on import order of the different bits and pieces.

Luke

-- 
Hofstadter's Law: It always takes longer than you expect, even when you 
take into account Hofstadter's Law.

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Custom SQL in Q objects

2006-08-31 Thread Luke Plant

On Thursday 31 August 2006 14:03, bk wrote:
> class CategoryPhoto(models.Model):
>   category = models.ForeingKey(Category, edit_inline=models.Tabular)
>   position = models.PositiveIntegerField(core=True)
>   photo = models.ForeignKey(Photo, limit_choices_to={'category__pk':
> ???})
>
> ??? is where I basically want to use the id of the current category
> being edited to limit the photo choices to those set for that
> category - since there's over 100 records in the db so far.
>
> Any chance this would be possible with a similar Q class?

I don't think this will be possible, if I understand correctly. 
The 'limit_choices_to' parameter simply alters the query that is used 
to get the list of photos used to populate the drop down list.  This 
query is completely independent of which CategoryPhoto is being 
edited - in fact, when adding a CategoryPhoto object (as opposed to 
editing), the object doesn't even exist in the database, but the photo 
drop down still needs to be populated.

The only way I can recommend is to add some AJAX that responds to 
changes to the category drop and repopulates the photo drop down 
accordingly.  Thankfully this should be pretty easy using the 'js' 
admin option.

Luke

-- 
"Pessimism: Every dark cloud has a silver lining, but lightning kills 
hundreds of people each year trying to find it." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Generic relations and tags

2006-06-27 Thread Luke Plant

On Tuesday 27 June 2006 18:06, Jay Parlar wrote:
> So I'm now trying the new generic relations out for tags, much like
> the example in the documentation. The problem I'm having is doing a
> filter() to get a QuerySet of tags with unique names. Any thoughts on
> this?
>
> If two different objects are both given a tag "foo", there will be
> two tags in the system that have 'foo' as their 'tag' value. The only
> way I can think of doing this so far is to manually pull all the
> results out of a QuerySet, and use Python to figure out all the
> unique tag names.

Would something like this do it?

your_query_set.distinct().values('tag')

Luke


-- 
"Defeat: For every winner, there are dozens of losers.  Odds are you're 
one of them." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



OT: Re: ANN: Screencast demo of the WebFaction control panel

2006-06-22 Thread Luke Plant


Jay Parlar wrote:

> Luke, which hosting plan are you using? I know that Shared 2 is the
> minimum for Django, but I'm curious if it's "enough".

I'm on shared 2, which seems to be fine for my needs.  The main thing
that would worry me is the amount of memory, so I haven't used any
caching.  Since my site (www.cciw.co.uk) is low traffic and never
likely to be slashdotted, this should never be a problem.  I imagine
Jacob and Adrian and co will be able to tell you about memory
requirements for adding effective caching, I have no idea.

To be honest, I'd really like to know more about how the memory usage
is limited, and how I can check, and whether I need to do anything.
Right now, for instance, 'ps aux' shows 10 apache instances of mine
each using about 18 Mb, which is a lot more than my 40 Mb limit.  I
know that they will actually be sharing a lot of that, and that the
calculations are actually more complex, but my knowledge runs out just
about there.

Luke


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



Re: ANN: Screencast demo of the WebFaction control panel

2006-06-21 Thread Luke Plant

On Wednesday 21 June 2006 19:09, Jeremy Dunck wrote:

> > The demo is available at:
> > http://blog.webfaction.com/control-panel-demo
> >
> > Remi.
> > http://www.webfaction.com  - Hosting for an agile web
>
> Scary-cool.

I'm a WebFaction customer and I have to say I'm very impressed with them 
so far.  With zero experience of Trac I used their control panel to set 
up a working Trac instance in a few minutes, as well as a Django app.  
Switching the Django sources to use subversion was no problem.  Adding 
in the necessary domains when I transferred a domain and 'went live' a 
few days ago was dead simple too -- everything was obvious and just 
worked.

It's all very slick.

Luke

-- 
As Ralph Waldo Emerson once said, "I hate quotations." 

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: overriding-default-model-methods what am i doing wrong ?

2006-06-21 Thread Luke Plant

On Tuesday 20 June 2006 17:17, coulix wrote:

> when i add a tag element via the admin interface, or from a blog
> entry. total_ref is always null. why doesnt it get affected to 28 ?
> thanks

It looks OK to me.  I do have similar code that sets values like this, 
so it should work.

To debug, try making sure your code is actually being executed e.g. 
print statements or throwing exceptions at the relevant points.

Luke

-- 
As Ralph Waldo Emerson once said, "I hate quotations." 

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Custom manager filter by logged in user.

2006-06-17 Thread Luke Plant

On Saturday 17 June 2006 10:50, Adam Hoscilo wrote:

> I would like to filter entries from a logged in user and give him/her
> the ability to edit them - it would be nice to ensure that scope by
> manager.
> As far as I know Models don't have access to request and session data
> (and I realize it's a MVC/MVT schema violation). Is there any way to
> manage that by custom managers or maybe some other nice way?
> PS django.pl coming soon :)

Personally I think that it's bad to have models access HTTP request 
data, but it's not so bad to enable them to have access to 
authorisation data -- this is a very common business requirement.  If 
you don't do it in the model itself, you'd probably need to do it in 
some 'business rules' layer that wraps model access.

So I store the logged in user in threadlocal storage, using a 
middleware, then access it in my models.

It looks like this:

 myproject/middleware/threadlocals.py

try:
from threading import local
except ImportError:
# Python 2.3 compatibility
from django.utils._threading_local import local

_thread_locals = local()

def get_current_user():
return getattr(_thread_locals, 'user', None)

class ThreadLocals(object):
"""Middleware that gets various objects from the
request object and saves them in thread local storage."""
def process_request(self, request):
_thread_locals.user = getattr(request, 'user', None)

 end


Then put ThreadLocals into your list of installed middleware, and import 
the get_current_user() function from your model code.  I often use this 
in custom managers -- if you set the custom manager as your default 
manager, this has the very nice advantage that it works for related 
objects too.

Luke

-- 
A former CEO: "Some of you think that only half of the Board of 
Directors do all the work and the rest do nothing, actually the reverse 
is true."  (True Quotes From Induhviduals, Scott Adams)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Generic views and "include"

2006-06-15 Thread Luke Plant

On Wednesday 14 June 2006 13:50, opendev wrote:
> Hello,
>
> I am trying to render the output of multiple generic views under one
> template. Is this possible and if so how? The include tag renders
> only a template and cannot be used for the output of an entire view
> afaik.

The output of a view is always an HttpResponse object (which will 
usually contain an HTML document).  Since there is no simple way of 
combining HttpResponse objects or the HTML documents they contain, the 
answer to the question is no.

You will have to write your own view function to do this.  Also, you may 
have to modify your templates to refactor out the bit that can be 
included into other templates.

Luke

-- 
A dyslexic agnostic doesn't believe in Dog 

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: problem with related foreignkey in model

2006-06-15 Thread Luke Plant

On Thursday 15 June 2006 15:12, Antonello Cicchese wrote:

> now the problem is that in my admin i want to display in the city
> field only cities related to the previously selected state, how can i
> do this?

Hacking this in server side will be difficult.  My approach would be to 
use the 'js' Admin option to include a bunch of custom Javascript.  
This would add an event handler to the State drop down to detect any 
change.  When that drop down is changed, it would then do some Ajax to 
a specialised view function to get the list of Cities for the newly 
selected State and rewrite the contents of the Cite  field.

Have fun!

Luke

-- 
"Adversity: That which does not kill me only postpones the inevitable." 
(despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: No such column error + tag question

2006-06-15 Thread Luke Plant

On Wednesday 14 June 2006 16:41, Guillermo Fernandez Castellanos wrote:

> I've been developping a link model (see at the end of the post, kind
> of personal delicious) , and when I try to use the admin interface to
> add a url, I obtain the following error:
> Request Method:   GET
> Request URL:  http://127.0.0.1:8000/admin/links/link/
> Exception Type:   OperationalError
> Exception Value:  no such column: links_link.link
> Exception Location:   c:\program
> files\python24\lib\site-packages\django-0.91-py2.4.egg\django\db\back
>ends\sqlite3\base.py in execute, line 69
>
> It is really curious because the table seems to exist.

Does the column exist too?

> Another question, I've developped a quick tag model (see also at the
> end). Would I be able to use the same tag model for, say, blog posts
> and images at the same time? Or would I have to subclass or use
> different implementation of the Tag class?

Given your implementation, you could use the Tag class with as many 
other models as you like.  However, if your Tag class had a ForeignKey 
to a specific model, the common way to handle this is described here:

http://feh.holsman.net/articles/2006/06/03/django-contenttype

Luke

-- 
"Adversity: That which does not kill me only postpones the inevitable." 
(despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Foreign keys and applications

2006-06-15 Thread Luke Plant

On Wednesday 14 June 2006 12:20, Viktor wrote:
> I have two applications in my project:
>
...

> But when in my views I try to do:
>
> c1 = Cls1.objects.get(pk=1)
> clss = c1.cls2_set.all()
>
> I get:
>
> 'Cls1' object has no attribute 'cls2_set'

This is because your models are in different apps.  I can't remember 
off-hand what the correct syntax is (it might be something like 
cl.app2_cls2_set.all()), but the easiest way is to do this:

class Cls2(models.Model):
c = models.ForeignKey(Cls1, related_name='cls2_set')

Luke

-- 
"Adversity: That which does not kill me only postpones the inevitable." 
(despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: How to do named HTML anchors with Django?

2006-06-13 Thread Luke Plant

On Tuesday 13 June 2006 18:46, ZebZiggle wrote:
> Sorry if this a really silly question everyone, but how do I jump to
> named anchor with the URL mapping of Django?
>
> I have a template that uses  targets and want to go to
> a specific target from another page /mypage#foo

Yep, you need to spell it:

/mypage/#foo

Otherwise the CommonMiddleware will do a redirect to add the trailing 
slash that will strip the fragment.

Luke

-- 
I went to the Missing Persons Bureau. No one was there.

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: MyFormWrapper.myfield works in {{}} but not {%%} ?

2006-06-13 Thread Luke Plant

On Tuesday 13 June 2006 13:36, mazurin wrote:
> Thanks. I think I figured it out. It's not the expr tag, it's {%%}.
> It seems that {%%} doesn't cause a form field to render into HTML the
> way {{}} does.

{%%} by itself doesn't do anything -- the only bit of data that is 
extracted and handled is the first word ('expr' in this case).  It is 
the responsibility of the python code that is associated with 'expr' to 
parse the rest of the text inside {%%} as it sees fit.

Luke

-- 
I went to the Missing Persons Bureau. No one was there.

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Strange problems in 0.91

2006-06-12 Thread Luke Plant

On Sunday 11 June 2006 17:13, Andrew Degtiariov wrote:

> So for avoiding these problems I have looked to migrate to MRT.
> Anybody know is construction
>   Entry.objects.filter(
> headline__startswith='What').exclude(
> pub_date__gte=datetime.now()).filter(
> pub_date__gte=datetime(2005, 1, 1))
>
> translated to a single SQL query with WHERE clause? E.g. to something
> like SELECT * FROM table_name WHERE headline LIKE 'What%' AND NOT
> pud_date
>
> >= '2006-06-11 19:08:17' AND pub_date >= '2005-01-01 00:00:00'.
>
> Or all filtering provided at application level?

Django's ORM doesn't do any filtering in Python -- it generates the 
correct SQL and sends that to the database.

Luke

-- 
To iterate is human, to recurse, divine. L. Peter Deutch

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: TEMPLATE_CONTEXT_PROCESSORS confusion

2006-06-10 Thread Luke Plant

On Saturday 10 June 2006 16:40, Todd O'Bryan wrote:

> so I'd like to add userinfo to the context by default. To do that,
> I've figured out that I need to add my own function to
> TEMPLATE_CONTEXT_PROCESSORS, but I'm a little confused how to get the
> currently logged in user so I can get the appropriate user info.
>
> def userInfoProcessor(request):
>   #this will get called after django.core.context_processors.auth, so
>   #the user will be in the context, but how do I get access to the
> context
>   #if I only have an HttpRequest instance?
>   ui = #somehow get the appropriate UserInfo instance
>   return { 'userinfo':ui }
>
> What am I missing?

You can get the User object direct from the request object  -- 
request.user (assuming it is the currently logged in user you want), 
and get the UserInfo from that.

Luke

-- 
The probability of someone watching you is proportional to the 
stupidity of your action.

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: OT: Password checker

2006-06-10 Thread Luke Plant

On Saturday 10 June 2006 14:40, Todd O'Bryan wrote:
> What do people use to verify the strength of user passwords? Is there
> a Python library out there that's good?
>
> I've found python-crack, but that requires cracklib to be installed
> on the server and I'd prefer something self-contained.

I use John the Ripper ('sudo apt-get install john' for Debian users, 
which I guess you're not, looking at your mail agent).  It's not a 
python program, and but assuming you want to use it on a Linux/Unix 
box, it should be easy enough to compile it as a standalone binary -- 
it doesn't seem to depend on any libraries except standard C libs.

Luke

-- 
The probability of someone watching you is proportional to the 
stupidity of your action.

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Extending User model after magic-removal

2006-06-10 Thread Luke Plant

On Friday 09 June 2006 18:02, Marcin Kaszynski wrote:

> I just spent some time looking for a way to extend the User model in
> a way that would allow me to:
>
> 1. add fields to the model itself,
> 2. use the standard admin interface to edit them,
> 3. keep changes to Django minimal and generic.
>
> I came up with something that actually works well and is generic
> enough to extend any other model: I changed ModelBase.__new__ to call
> a function that modifies attributes of the new class before it gets
> created.  The function is defined in project settings file, so it is
> easy to have different User models in different projects without
> further changes to Django code.

This is actually quite interesting.  You would need to alter your patch 
a bit so that it works for models with 'app_label' defined -- the 
"model_module.__name__.split('.')[-2]" logic should exist in only one 
place.  Other than that it seems quite good -- maybe you should create 
a ticket.

Luke

-- 
The probability of someone watching you is proportional to the 
stupidity of your action.

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Possibly new Django user questions

2006-06-10 Thread Luke Plant

On Friday 09 June 2006 23:50, binjured wrote:

> 1) How robust is Django?  Take for instance the User class.  Say I
> wanted to add the field "favorite_color" and have it editable in the
> admin interface and work with all applicable functions, is that
> possible?  What if I need to connect to a Soap server after a
> successful local login, send some commands, get a response, and set a
> cookie?  Can things like this be done without rolling my own
> completely custom User class (this could have only to do with the
> login model, I don't know)?

This sounds like you are really asking 'how *flexible* is Django?'.  
With regards to adding fields, see:
http://code.djangoproject.com/wiki/ExtendedUserModel

As for logging in, it depends on what you mean -- are you talking about 
the admin?  If you are talking about your own logging in functionality, 
you can do whatever you want.  I imagine you could write a 'view 
middleware' to implement this otherwise.

> 2) Is there any way to make a portable Django app, i.e. the user
> getting the app doesn't have to install Django to their system?  This
> isn't a huge deal because I can still develop our portable apps in
> PHP, but it would be neat ;)

You don't have to *install* Django into system directories, if that is 
what you are asking - it just has to live somewhere on your python 
path.  This is the way I always use it.


> My biggest problem with "heavy" frameworks like Django, regardless of
> the language, is customizability.  Usually they do certain things a
> certain way extremely well, but if you try to deviate from that too
> much then you're in trouble.  I am tired of reinventing the wheel in
> PHP, but at least when reinventing the wheel we decide exactly what
> it looks like ;)

Django's components are in general very loosely coupled, so you are not 
forced into doing everything the Django way.  You can use a different 
template engine, a different ORM (if you don't want the admin), a 
different URL despatching mechanism (by creating a single item in 
urlconf that goes to your custom function).

Even the admin has various hooks to allow overriding (e.g. you can 
provide different templates, you can even provide different view 
functions using additional urlconf entries), but it doesn't contain 
every single hook that someone somewhere would like it too -- it would 
just become crazy.

There is some intrinsic inflexibility in the models that the admin 
depends on i.e. User, Group, Permission, ContentTypes -- these are 
models that are not only managed by the admin, but that the admin uses 
itself -- it's impossible not to depend on them in some way.  There are 
SoC plans to make authorisation more modular though, or at least more 
capable.  

Luke

-- 
The probability of someone watching you is proportional to the 
stupidity of your action.

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: TypeError adding an item in the Admin UI

2006-06-05 Thread Luke Plant

On Monday 05 June 2006 14:02, Chris H wrote:
> The full error is:
> TypeError at /admin/catalog/item/add/
> __deepcopy__() takes exactly 2 arguments (1 given)

Adrian fixed it in svn, my bad sorry.

Luke

-- 
"Whoever calls on the name of the LORD will be saved." (Romans 10:13)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: combining models in something like a queryset?

2006-06-05 Thread Luke Plant

On Monday 05 June 2006 14:57, benj wrote:

> def index(request):
> titles = list(Alias.objects.all()) + list( Song.objects.all())
> titles.sort(lambda x, y: cmp(x.title, y.title)
> return render_to_response('songs/index.html', {'titles': titles})
>
>
> This gives me lists of objects with the correct attributes and
> methods which is great, and when I need to filter the results (for
> example, for category views) I can easily do that by replacing .all()
> with .filter() or whatever else. The problem with this solution is
> that I need to pull the entire set of results into a list, and (if
> the site catches on), that's bad memory use and potentially slow. I
> wish it were possible to create an iterable object like a queryset
> that could be assigned two models to do this more efficiently. If
> anyone has advice about any more efficient way to get this done, I'd
> appreciate it.

Django's ORM can only do what is possible in SQL -- unless you can think 
of SQL that will do this, it can't be done.

One possible method is to create a VIEW in your db that does a UNION of 
columns from different tables.  If you create an index on that view, 
you may be able to do an ORDER BY efficiently over the relevant column.  
I'm not sure though.  Obviously it depends on your db supported indexed 
views.

Luke

-- 
"Whoever calls on the name of the LORD will be saved." (Romans 10:13)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Django magic removal and access to user into template.

2006-06-05 Thread Luke Plant

On Monday 05 June 2006 20:02, Spock wrote:

> --
> from django.template import RequestContext as Context
> from django.shortcuts import render_to_response
>
>
> def index(request):
>   ..[cut bla bla ]..
>   return render_to_response('helpdesk/ticket_list.html',
> Context(request,{'object_list':t}))
> --
>
> Is there any "DRY"(shorter) method for this Context(request,{})
> _every_time  ? :)

I understand what you mean, but really, if you want the template system 
to have access to something in the request, you simply *have* to pass 
it through -- there's no getting around passing arguments to functions.

[Except, of course, there is: you could create a custom Context class 
which inherits from the RequestContext and overloads its __init__, 
inside of which you use either sys._getframe hacks (fragile) or 
threadlocal storage (more robust, but would require writing a 
middleware to do the necessary setup) to pass the request object 
implicitly.  It obfuscates your code, and for this saving I wouldn't 
have thought it worth it.  I personally do use threadlocal storage to 
make the currently logged in user available to various model methods, 
since there is no other way to do this.]

Luke

-- 
"Whoever calls on the name of the LORD will be saved." (Romans 10:13)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: how to use instance method in the validator_list of a field in model?

2006-06-01 Thread Luke Plant

On Thursday 01 June 2006 08:38, favo wrote:
> > However, you can override the 'validate' method on a model, and you
> > might be able to use that to do what you want (you will probably
> > want a validate method that looks like this:
> >
> > class Category(models.Model):
> > ## fields etc here
> > def validate(self):
> > error_dict = super(Category, self).validate()
> > # Do your validation here, adding to 'error_dict'
> > # and then:
> > return error_dict
>
> How could these happen?
> I see some code in change_stage, it will only call
> errors = manipulator.get_validation_errors(new_data)
> No one run the validate method of model?

Oh yeah, I was forgetting how this worked.  There was discussion at one 
point about moving validation to the model, but I can't remember how 
far it progressed.  Obviously not as far as getting the manipulators to 
work that way.

Luke

-- 
"Trouble: Luck can't last a lifetime, unless you die young." 
(despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Controlling Display of Foreign Key Input Fieldsets in Admin

2006-06-01 Thread Luke Plant

On Thursday 01 June 2006 13:55, Paul Childs wrote:
> Thanks Luke.
>
> I'm sure problem one is just a side effect of why two and three won't
> work.
> I'm still loving Django though!

I should have mentioned that you can provide your own version of the 
admin templates, and do so on a per model basis, which might be the 
best way of doing this.

Luke


-- 
"Trouble: Luck can't last a lifetime, unless you die young." 
(despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: how to use instance method in the validator_list of a field in model?

2006-05-31 Thread Luke Plant

On Wednesday 31 May 2006 07:36, favo wrote:
> somebody know how to use instance method in the validator_list of a
> field in model? I can't get the "self".
>
> class Category(models.Model):
> """ Inhert Category """
>
> title_en = models.CharField(maxlength=256, null=True)
>
> parent = models.ForeignKey('self',
> related_name="direct_children", null=True, blank=True,
> validator_list=[self.isValidParent]) # we want the instance method
> here
>
> def isValidParent(self, field_data, all_data):
> if field_data in self.children_ids()
> raise validators.ValidationError("u can't set your
> children as your parent, cause loop")

You can't do this -- validator functions take just field_data and  
all_data.  In fact, an instance might not even exist when the validator 
is called -- when creating a new instance, for example.

However, you can override the 'validate' method on a model, and you 
might be able to use that to do what you want (you will probably want a 
validate method that looks like this:

class Category(models.Model):
## fields etc here
def validate(self):
error_dict = super(Category, self).validate()
# Do your validation here, adding to 'error_dict'
    # and then:
return error_dict



Luke

-- 
"The truth will set your teeth free." (Calvin and Hobbes)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Tagging app

2006-05-27 Thread Luke Plant

On Sunday 28 May 2006 00:22, Ian Holsman wrote:
> Hi Luke.
> what license is this code under?

Oops, forgot to add a LICENSE file.  I was going to put it under BSD, 
same as Django, unless anyone has a compelling reason for anything 
else,

Luke

-- 
"The number you have dialed is imaginary.  Please rotate your telephone 
by 90 degrees and try again."

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Tagging app

2006-05-26 Thread Luke Plant

On Friday 26 May 2006 22:37, Jacob Kaplan-Moss wrote:

> Looking forward to seeing your code,

OK, you can now get it here:

http://files.lukeplant.fastmail.fm/public/python/lp_tagging_app_0.1.zip

or here, using bzr:

bzr branch 
http://files.lukeplant.fastmail.fm/public/python/lukeplant_me_uk/

Let me know if there are still any Python 2.4-isms, or any other 
problems obviously. A README is included.

Luke

-- 
"The first ten million years were the worst. And the second ten 
million, they were the worst too. The third ten million, I didn't enjoy 
at all. After that I went into a bit of a decline." (Marvin the 
paranoid android)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Q behavior with filter() and exclude()

2006-05-26 Thread Luke Plant

On Friday 26 May 2006 18:57, Doug Van Horn wrote:

> I posted this here to:
> http://www.djangoproject.com/documentation/db_api/
>
> It seems that when you pass a Q() object into .filter() or
> .exclude(), you end up with the same results.  That is, the context
> of the method, filter or exclude, is ignored when it receives a Q
> object.

Thanks for catching this, I've added a test and fixed this now.

Luke

-- 
"The first ten million years were the worst. And the second ten 
million, they were the worst too. The third ten million, I didn't enjoy 
at all. After that I went into a bit of a decline." (Marvin the 
paranoid android)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Please help this newbie

2006-05-26 Thread Luke Plant


Salvage wrote:

> I understand when you say I cant build those sites without having
> programing skills but are there no modules that are already pre-built
> like print this article, comment on this article, send by email, most
> popular etc. That one can call with some django tags or something like
> that? Forgive me if i sound so *not knowledgeable*. In a lot of those
> news sites, I have seen, I can notice some things they have in common,
> like podcasts, vodcasts, video files as well as those things I
> mentioned above. Are there prebuilt modules or scripts that can be
> called with the django tags into templates? Please indulge this newbie
> a little. :-)

I guess it kind of depends on what type of news sites you mean.  The
ones I thought you meant were ones built with Django like lawrence.com,
which have a lot of programming behind them.

There are other Django sites that require less programming, and their
are prebuilt modules to help out with that e.g. the 'comments' app in
contrib allows you to plug commenting onto a site easily.  Have a
search for Wilson Miners and Jeff Crofts recent blogs about the things
you can do with relatively little programming using Django.

Still other news sites (I'm not thinking of Django ones) are built
using specialised CMS applications, that come out of the box with a lot
of the features you mentioned, with point and click interfaces for
turning these things on, but usually at the expense of flexibility, a
kind of much of a muchness feel, and sometimes feature bloat that makes
it hard to actually do simple things.

Picking the right starting point for building your site is really
important.  To use the analogy of construction work, a pre-built CMS is
like a fully built house where all you have to do is do the decorating
and move the furniture around.  Django is a foundation, some wall
sections (and a few complete drop in rooms) and a set of amazing power
tools that allow you to build a house in record time.  I personally
find that the pre-built house style is great until you want to move a
wall or or change the wiring, at which point it will be a total pain,
whereas Django's approach is ideal for me.  However, if you are not
really a programmer, the pre-built house style might be more
appropriate.

Luke


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



Re: Please help this newbie

2006-05-26 Thread Luke Plant


Salvage wrote:
> I have never coded in python and even my knowledge of php is
> limited(though I can install any script with php). But I see from the
> news sites that are built with django, that it has all that i need for
> newspaper/media sites. I want to know if I django can be installed in a
> hostspace with just an ip like http://22.234.67/~newssite . So that i
> can make all the mistakes, try to learn how to use before moving to
> qualified domain names.

You can use just an ip address, but you need to ensure that your host
provider supports mod_python (assuming you are going to use mod_python
and apache).

> I also wish to know if I can use template
> designs from dreamweaver or predesigned from templatemonster to
> integrate into django.

Yes, you can use any HTML based template.  The Django templating
language, that you will need to insert dynamic content, is easy to
learn.

> Please, the tool am using now for news site is limited compared to what
> I see with the news sites built with django.

Without some programming ability, you won't be able to create news
sites like the ones you've seen.

> Also how easy is it to use
> after installation?

Not sure what you mean.  Django is not an out-of-the-box CMS - it is a
tool for building that kind of web site.  You do get the 'admin'
interface out of the box, though, and this is very easy to use.

Luke


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



Re: Slicing [-1] on objects.all()

2006-05-26 Thread Luke Plant


Jay Parlar wrote:

> Maybe a note should go into the db_api docs about -1 not working? I
> did look at those docs before sending my original message, and didn't
> see anything about that.

I think it should throw an exception saying that negative indices are
not supported (and even include a hint about reversing the ordering).
I'll get that fixed that soon, thanks.

Luke


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



Re: Tagging app

2006-05-26 Thread Luke Plant


arthur debert wrote:

> ps: how is the GenericForeignKey going to work? will it be imported
> from the tagging app's package, or will it go into trunk?

There is no guarantee that any of this stuff will go into trunk at all
- the core django devs would obviously have to be for it first.

But the GenericForeignKey class could be usefully part of the
ContentTypes contrib app.  However, one constraint of my current
project is that I have models with string primary keys. I've got a
simple 'mapper' system for dealing with this that GenericForeignKey
uses, but I'm not sure if it is such a common case that it is worth the
extra hassle - for example, the 'comments' contrib app does not handle
this case AFAICS.

Perhaps GenericForeignKeyInteger and GenericForeignKeyString could both
be created - looking at the 'comments' contrib model,
GenericForeignKeyInteger could be used to improve it - it would replace
(or augment) the get_content_object() getter method with an attribute
that handles both setting and getting.

Luke


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



Re: Tagging app

2006-05-26 Thread Luke Plant


Ivan Sagalaev wrote:

> The single target means that one tag can't be used for different models?

Yep, a single 'Tag' object is associated with just one target and one
creator.  However, you can easily tag different models and objects with
the same bit of text.

> I have chosen a different approach in my app: tags are basically just
> text labels that are linked with models with ManyToMany. This allows to
> do some interesting things. For example in my music exchange service I
> have users with tags meaning their likings like "blues", "rock",
> "hard-rock" so  one can easily search both albums and artists with these
> same tags.

You can do the same thing with my code - a search for a specific text
value will return Tags for different types of objects - the 'TagTarget'
object and related methods address that specific need.

One of the things that motivated my design was the ability to store
creation dates - i.e. you can see exactly when you (or anyone else)
tagged a specific item with a specific bit of text.  Ian's solution
goes further, and has various models, including a 'Bookmark' that
allows more information to be stored, and other models that store
summary information.

I think the problem here is analagous to the multiplicity of Python web
frameworks - Python/Django makes it so easy!  I've chatted with Ian a
bit, and while our different approaches cover the same ground, there
are reasons I couldn't use his without modification and vice-versa.
Perhaps we should set up some pages doing comparisons of the different
approaches, including code that can be downloaded.  If a clear 'winner'
drops out i.e. a solution that will fit a lot of people, it could be
suggested that it is put into contrib in Django.  But there's no
guarantee that will happen in any case, so it would be good to have
somewhere central where people can compare and make use of this code.

I'll try to tidy something up and release it tonight.  It's got a
reasonably amount of code doc, and I'll try to add some examples.

Luke


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



Tagging app

2006-05-25 Thread Luke Plant
ext' which searches for targets with a 
specific 'text' value, or several text values, and displays them in a 
paged list by decreasing popularity.

Most of my tagging related views are simple wrappers around these three.

Template tags
=
I've included a template tag for getting a list of TagSummary
objects for a target object e.g.:
  {% get_tag_summaries for post as tags %}

Templates
=
I've included a simple template for create_update, that works as is. You
can use another template, of course.

URLS

I've found that sorting out my urls for tagging has been one of the 
hardest things, especially as I'm going for a fairly complete solution 
(e.g. you can drill down to the level of a particular Member, see all 
their tags, see who tagged a particular target with a given text value 
and when etc.).  I haven't been able to abstract this into a standard 
system, so I haven't included any implementation of get_absolute_url or 
anything else to do with URLs.  I have my own custom template_tags for 
generating absolute urls for Tags in different contexts, and I also 
sometimes use the ContentType object. 

Tag.target is implemented using:
Tag.target_ct = models.ForeignKey(ContentType)
so for any specific Tag I can get tag.target_ct.name and I tend to use 
that and and Tag.target_id to generate some URLs.

Feeds
=
I normally do feeds using the same view functions as HTML pages, but 
with ?format=atom.  I've added a hook to the relevant views that allows 
this.


Resusable bits
==
Some of the stuff I implemented along the way is even more generic, 
including some 'generic foreign key' descriptors and 'generic m2m 
object' descriptors, which manage to avoid using any SQL directly, and 
so should be very robust. They depends on the ContentType model, and 
some of the utility functions.


Let me know if you are interested, I'll tidy up the code and post it 
somewhere.

Luke

-- 
Sometimes I wonder if men and women really suit each other. Perhaps 
they should live next door and just visit now and then. (Katherine 
Hepburn)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: does django go to 11?

2006-05-22 Thread Luke Plant

qhfgva wrote:

> - Is there a way to have input fields that are only available to
> certain users/groups?

> - Is there a way to have certain rows not editable based on user/group
>(e.g the mangager_signoff column is true so non manager users can't
>modify this row any more)?

See the other answer about my hacky solution, which should cover these
two.

> - Is there a way to have certain filters on as default?  (Instead of
> set to "All")

I can't think of a way to do this at the moment.

> - Is there a way to highlight certain rows with colors (e.g. if a row
> meets a certain condition - e.g. a task past a due date highlighted in
> red.)

I think you should be able to do this in javascript - I think it is the
'js' option to Admin.

> - Is there a reasonable way to add/remove buttons to/from the
> save/delete buttons at the bottom of the create/update pages?

You can override the admin templates on a per-model basis, which should
allow you to do what you want.  It's not ideal, as you'll have to copy
the whole template and then tweak the bits you need, which is a pain if
the admin templates change, but that doesn't happen very much any more.

Luke

X-Google-Language: ENGLISH,ASCII-7-bit
Received: by 10.11.53.63 with SMTP id b63mr118065cwa;
Mon, 22 May 2006 02:39:25 -0700 (PDT)
X-Google-Token: EBWqpwwAAAB4EXIwnd4uBocvG1Cd6aYZ
Received: from 217.67.53.216 by y43g2000cwc.googlegroups.com with HTTP;
    Mon, 22 May 2006 09:39:25 + (UTC)
From: "Luke Plant" <[EMAIL PROTECTED]>
To: "Django users" <django-users@googlegroups.com>
Subject: Re: does django go to 11?
Date: Mon, 22 May 2006 02:39:25 -0700
Message-ID: <[EMAIL PROTECTED]>
References: <[EMAIL PROTECTED]>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-GB; rv:1.8.0.3) 
Gecko/20060426 Firefox/1.5.0.3,gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 LEGOLAS
Mime-Version: 1.0
Content-Type: text/plain

qhfgva wrote:

> - Is there a way to have input fields that are only available to
> certain users/groups?

> - Is there a way to have certain rows not editable based on user/group
>(e.g the mangager_signoff column is true so non manager users can't
>modify this row any more)?

See the other answer about my hacky solution, which should cover these
two.

> - Is there a way to have certain filters on as default?  (Instead of
> set to "All")

I can't think of a way to do this at the moment.

> - Is there a way to highlight certain rows with colors (e.g. if a row
> meets a certain condition - e.g. a task past a due date highlighted in
> red.)

I think you should be able to do this in javascript - I think it is the
'js' option to Admin.

> - Is there a reasonable way to add/remove buttons to/from the
> save/delete buttons at the bottom of the create/update pages?

You can override the admin templates on a per-model basis, which should
allow you to do what you want.  It's not ideal, as you'll have to copy
the whole template and then tweak the bits you need, which is a pain if
the admin templates change, but that doesn't happen very much any more.

Luke


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



Re: Best way to run dev and production site concurrently on same server?

2006-05-20 Thread Luke Plant

On Thursday 18 May 2006 23:20, Rob Hudson wrote:

> Based on my virtual hosts, can I have the production site list:
> SetEnv DJANGO_SETTINGS_MODULE website.settings
> and the dev site list:
> SetEnv DJANGO_SETTINGS_MODULE website_dev.settings
> and everything work?
>
> Is there something more I need to consider?  Is anyone else doing
> something similar?

You may have to consider the 'Sites' objects.  So far, I have only come 
across these are used internally only for creating URLs in the RSS/Atom 
framework.  I think this can be taken care of by creating the necessary 
Site objects and setting the SITE_ID option correctly in your settings 
files.  Other than that I can't see any problems.

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/
X-Google-Language: ENGLISH,UTF8
Received: by 10.54.68.15 with SMTP id q15mr149925wra;
Sat, 20 May 2006 09:31:04 -0700 (PDT)
Return-Path: <[EMAIL PROTECTED]>
Received: from out3.smtp.messagingengine.com (out3.smtp.messagingengine.com 
[66.111.4.27])
by mx.googlegroups.com with ESMTP id v11si417440cwb.2006.05.20.09.31.02;
Sat, 20 May 2006 09:31:04 -0700 (PDT)
Received-SPF: neutral (googlegroups.com: 66.111.4.27 is neither permitted nor 
denied by best guess record for domain of [EMAIL PROTECTED])
Received: from frontend3.internal (frontend3.internal [10.202.2.152])
by frontend1.messagingengine.com (Postfix) with ESMTP id 589FDD62E61
for <django-users@googlegroups.com>; Sat, 20 May 2006 12:31:01 -0400 
(EDT)
Received: from heartbeat1.messagingengine.com ([10.202.2.160])
  by frontend3.internal (MEProxy); Sat, 20 May 2006 12:31:02 -0400
X-Sasl-enc: TOvXyHl5eKU8anYn8+yXqXov7e647JzvglcJ1SItoDTP 1148142661
Received: from calvin (host86-141-27-140.range86-141.btcentralplus.com 
[86.141.27.140])
by mail.messagingengine.com (Postfix) with ESMTP id B0B15132E
for <django-users@googlegroups.com>; Sat, 20 May 2006 12:31:01 -0400 
(EDT)
From: Luke Plant <[EMAIL PROTECTED]>
To: django-users@googlegroups.com
Subject: Re: Best way to run dev and production site concurrently on same 
server?
Date: Sat, 20 May 2006 17:30:30 +0100
User-Agent: KMail/1.8.3
References: <[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
X-Face: 
"N27'AmvBWpdTowy8j|{(HM:g:In+;[nNrbEv6"_B>#oJW=()=?utf-8?q?g=2EtC=3BI9=7CDrpPnB=3Ff=242=5B9V=0A=09?="eYjDWVW[PFOJj5zbG1mZm>y3P^"$Fl)(=?utf-8?q?=3Fx=5E4/rPd4SMJX=7C53PpvkyMk=5F=5CmSl=24oK=25nZf3D=0A=09d=7EK+c?=
 =?utf-8?q?f=60wDl!q=27P4JNu=5FI=25V0!l=3D1D?="]WrI4~ZZK!-|5T%

On Thursday 18 May 2006 23:20, Rob Hudson wrote:

> Based on my virtual hosts, can I have the production site list:
> SetEnv DJANGO_SETTINGS_MODULE website.settings
> and the dev site list:
> SetEnv DJANGO_SETTINGS_MODULE website_dev.settings
> and everything work?
>
> Is there something more I need to consider?  Is anyone else doing
> something similar?

You may have to consider the 'Sites' objects.  So far, I have only come 
across these are used internally only for creating URLs in the RSS/Atom 
framework.  I think this can be taken care of by creating the necessary 
Site objects and setting the SITE_ID option correctly in your settings 
files.  Other than that I can't see any problems.

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Best way to do a dynamic sidebar?

2006-05-18 Thread Luke Plant

On Tuesday 16 May 2006 22:24, Jay Parlar wrote:

> It feels like I should be able to define a template just for the
> sidebar, and insert the content of that template into whatever
> template is being rendered. I guess that the 'include' tag would do
> that, but then I'd need to explicitly pass the required sidebar
> context into every template, right?

You might find the TEMPLATE_CONTEXT_PROCESSORS setting useful:

http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext

Using this you won't have to explicitly pass the context vars every 
time.  

Luke

-- 
OSBORN'S LAW
Variables won't, constants aren't.

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Problems with ForeignKey in magic-removal

2006-05-16 Thread Luke Plant

On Tuesday 16 May 2006 02:48, Malcolm Tredinnick wrote:

> Thinking out loud a bit here, more as a reminder to myself: but I
> wonder _why_ this worked? If you have no __str__ method, it will fall
> back to __repr__, so you should have been seeing the same output
> regardless. Are we stomping on class __repr__ functions internally,
> is anybody aware?

Yeah, I wondered about this too.  The answer is that django defines both 
__str__ and __repr__ on Model, so if your class defines only __repr__, 
it never gets called.

Luke


-- 
"Oh, look. I appear to be lying at the bottom of a very deep, dark 
hole. That seems a familiar concept. What does it remind me of? Ah, I 
remember. Life."  (Marvin the paranoid android)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: How to prevent a page from being cached?

2006-05-13 Thread Luke Plant

On Friday 12 May 2006 20:56, Eric Walstad wrote:

> I looked for the string 'never_cache' in my copy of the
> 'Sargasso'(pre-agic-removal) branch but didn't find anything.  Do you
> know if this feature is available there?  Perhaps under a different
> name?

No, it's not there.  However, most of its functionality is in 
patch_response_headers, which I *guess* is in pre-magic-removal, though 
I'm not sure where.  So you could could backport the never_cache 
function and stick it in your own code somewhere pretty easily - I 
think everything you need is in these modules:

http://code.djangoproject.com/browser/django/trunk/django/views/decorators/cache.py
http://code.djangoproject.com/browser/django/trunk/django/utils/cache.py

Luke

-- 
"Mistakes: It could be that the purpose of your life is only to serve 
as a warning to others." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: How to prevent a page from being cached?

2006-05-12 Thread Luke Plant

On Thursday 11 May 2006 10:13, PythonistL wrote:

> Is there a way how to prevent a page from being cached?

from django.views.decorators.cache import never_cache

@never_cache
def myview(request):
# etc

I'm not sure if it's documented anywhere, I think it is.

Luke

-- 
"Mediocrity: It takes a lot less time, and most people don't realise 
until it's too late." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Best practice for separating Model and Control?

2006-05-11 Thread Luke Plant

On Thursday 11 May 2006 13:37, Ned Batchelder wrote:

> Is there some way to put the model and the logic in two separate
> places but somehow end up with an object class with real methods?  Am
> I making any sense?

That sounds pretty much like a mixin, and these should be possible in 
the magic-removed model classes, though I haven't tried.  There might 
be some issues getting mixins to work with new-style classes and the 
model metaclass.

Luke

-- 
"Making it up? Why should I want to make anything up? Life's bad enough 
as it is without wanting to invent any more of it." (Marvin the 
paranoid android)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Admin Functionality Enhancement

2006-05-06 Thread Luke Plant

On Saturday 06 May 2006 05:01, Chris Moffitt wrote:

> I know there's been talk about changing/enhancing the admin interface
> but I'm not sure where my idea would fit.  One thing I've noticed is
> that as you add more models to the interface, it can get a little
> more confusing about how they're categorized.  What if we created the
> capability to define the category for each module, then displayed a
> menu in the admin to allow the users to select a specific
> category/option for viewing/editing the modules.
>
> Using something like __category__ = "Blogs" in each model would add a
> link (along the menu bar?) to a blogs category which would contain
> all models related to blogs.  I think this would be useful but am
> curious what others think?  Obviously, it could default to the
> current behavior so it wouldn't be an issue for those that don't need
> it.  I suspect though that there are people out there with a dozen
> (or more) models that could benefit from this kind of feature to help
> make the admin site more manageable as it gets more complex.

The 'Django' way of handling this is to split your models into different 
'apps'.  They then get their own division automatically.  Like you I 
have a lot of models in one app (about 20), and splitting them up 
doesn't make much sense since they logically belong together, and my 
urlconf would be much harder if they were split up.

For me, simply sorting the list of models alphabetically would be a 
sufficient solution to this problem.  I had a patch for this in the 
past but it got lost.  I'll have another go -- I don't know if it would 
be good enough for your situation, but it would be a start.

Luke

-- 
"It is a truth universally acknowledged, that a single man in 
possession of a good fortune, must be in want of a wife." (Jane Austen)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: [MySQLdb] Could not load database backend: cannot import name ImmutableSet.

2006-05-06 Thread Luke Plant

On Saturday 06 May 2006 11:56, Paulo wrote:

> From my limited knowledge it seems like a MySQLdb/Django problem but
> after so much emty searching around I am still not sure how to go
> about fixing the problem. A few posts have covered exporting youe
> settings and such but nothing has worked.

The fundamental problem is probably this line:
Could not load database backend: cannot import name ImmutableSet.

I'm guessing that your PYTHONPATH isn't set up correctly, but I can't be 
sure.  It's a good place to start looking.  If it is, then you need to 
track down what it trying to import ImmutableSet, and why it is failing 
(possibly something inside MySQLdb?).  Trying the same commands from an 
interactive Python prompt is often a good way to do testing.

Also, does MySQLdb have any dependencies that you don't have installed?

Luke

-- 
"It is a truth universally acknowledged, that a single man in 
possession of a good fortune, must be in want of a wife." (Jane Austen)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Error creating SQL with string field containing a single quote.

2006-05-06 Thread Luke Plant

On Friday 05 May 2006 19:41, evenrik wrote:
> Using pre magic removal I got this error:
>
> Exception Type:   ProgrammingError
> Exception Value:  ERROR: unterminated quoted string at or near
> "'F28T8/841 T8 4'' " at character 419 select count(a.id) from
> uv2_applications as a inner join uv2_rebatableobjects as r on
> a.ro_id=r.id inner join uv2_ro_lowwatt_cms as lwt on r.id=lwt.ro_id
> inner join uv2_customers as c on a.c_id=c.id where a.objstate != 600
> and a.id != 268 and c.address_hash =
> '46d2b9507ea1f13455675013b6cb0504' and c.address_hash != '' and
> (lwt.model) = 'F28T8/841 T8 4'' Exception Location:
>   /usr/lib/python2.3/site-packages/django/core/db/base.py in execute,
> line 9
>
> The "model" field has the data F28T8/841 T8 4' that is creating the
> error.
> Has anyone a fix for this? For now I just changed the quote to ft in
> the DB.

What command are you executing that generates this?  It looks like you 
are generating your SQL manually (rather than letting Django create it 
for you), in which case you have to be sure to escape your data 
properly.  

Luke

-- 
"It is a truth universally acknowledged, that a single man in 
possession of a good fortune, must be in want of a wife." (Jane Austen)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Tutorial for MR

2006-05-05 Thread Luke Plant

On Friday 05 May 2006 11:39, Honza Král wrote:
> I agree, but at least it works...
> it would be nice to have this at least at a module level...

Yeah, I was thinking about doing that, or some other nice solution. 
Ideally it would handle it invisibly, but once you get into it, it's a 
slightly tricky problem...

Luke

-- 
"I think you ought to know I'm feeling very depressed." (Marvin the 
paranoid android)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Tutorial for MR

2006-05-04 Thread Luke Plant

On Wednesday 03 May 2006 23:52, Luke Plant wrote:

> /myproject
> /myapp
> /models
> __init__.py
> foo.py
> bar.py
>
>
> In __init__.py, I have:
> --
> from foo import Foo, SomeThingElse
> from bar import Bar, AnotherSomething
> # a few more, but no __all__ line
> --

... and the missing ingredient which makes it work is setting 
'app_label' in the model's 'Meta' class, as other people have pointed 
out.

Luke

-- 
I teleported home one night
With Ron and Sid and Meg,
Ron stole Meggie's heart away
And I got Sidney's leg
(THHGTTG)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Tutorial for MR

2006-05-03 Thread Luke Plant

On Wednesday 03 May 2006 15:39, Malcolm Tredinnick wrote:
> On Wed, 2006-05-03 at 16:29 +0200, Honza Král wrote:
> > BEGIN;
> > COMMIT;
> > is the output of manage.py sql app (empty sql script for
> > postgreSQL)
> >
> > I am fairly new to python, so I completely don't mind trivial
> > questions, in app/models/__init__.py I have:
> > 
> > # base models
> > from proj.app.models.base import *
> > # models derived from base
> > from proj.app.models.more_models import *
> >
> > # I even added
> > __all__ = [ 'List', 'Of', 'All', 'My', 'Model', 'Classes' ]
> > -
> > and it still wouldn't work
> >
> > if I run shell and try to use my models from there ( from
> > proj.app.models import * ) everything works OK, dir shows all my
> > model classes...
>
> I thought this should work, but I must admit that a quick test I did
> just now completely failed. Wait for the Earth to turn a little more
> on its axis: Luke Plant has a bit of experience in this area (every
> time it broke, he screamed), so I think we are missing something
> obvious. Give it some time and see if Luke notices this thread (or
> somebody else spots what's wrong).

The Earth turned (good 'ol Earth)...

It's strange though - the manage.py commands all work for me, and I 
remember someone else having this problem and it not being resolved.  
My setup is as follows:

/myproject
/myapp
/models
__init__.py
foo.py
bar.py


In __init__.py, I have:
--
from foo import Foo, SomeThingElse
from bar import Bar, AnotherSomething
# a few more, but no __all__ line
--

The only thing I can see there is the (rather nasty) relative imports 
instead of absolute imports.  I suspect it might be something bizarre 
to do with imports e.g. I might have happened to import something 
inside my model files which accidentally fixes it.  Also, it would be 
good to check Python versions (I'm using 2.4).

I don't have time to debug this at the moment (maybe Friday).  Debugging 
it might be slightly difficult -- it seems to be sensitive to 
environment, so debugging with 'print' will probably be the best 
option, rather than trying to use a debugger.

Hopefully this isn't a blocker -- your other code that uses models can 
import from myproject.myapp.models, rather than 
myproject.myapp.models.foo, so reorganising into multiple files later 
won't require any changes to other code.

Luke

-- 
"I spilled spot remover on my dog. Now he's gone." (Steven Wright)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Send POST data for unchecked checkboxes

2006-05-01 Thread Luke Plant

On Monday 01 May 2006 21:47, Sam Tran wrote:

> On 5/1/06, Luke Plant <[EMAIL PROTECTED]> wrote:
> > On Monday 01 May 2006 20:03, Sam Tran wrote:
> > > I am having the problem described in ticket 1045:
> > > http://code.djangoproject.com/ticket/1045
> > >
> > > Was this problem fixed in Django 0.91?
> >
> > It was closed as a WONTFIX, so I doubt it (the patch certainly has
> > not been applied).  The problem you are having is inherent in HTML
> > forms, and the solution is to have a view function that knows what
> > data should have been filled in.
>
> Hi Luke,
>
> Thank you for the information.
>
> However I am not sure how I would write such a view.

I think you would have to write a custom manipulator that knows not to 
expect certain fields.  However, I've never actually done this myself 
(I've barely used the 'forms' stuff in Django), so I can't really be 
more specific.

Luke

-- 
"In my opinion, we don't devote nearly enough scientific research to 
finding a cure for jerks." (Calvin and Hobbes)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Send POST data for unchecked checkboxes

2006-05-01 Thread Luke Plant

On Monday 01 May 2006 20:03, Sam Tran wrote:

> I am having the problem described in ticket 1045:
> http://code.djangoproject.com/ticket/1045
>
> Was this problem fixed in Django 0.91?

It was closed as a WONTFIX, so I doubt it (the patch certainly has not 
been applied).  The problem you are having is inherent in HTML forms, 
and the solution is to have a view function that knows what data should 
have been filled in.

Luke

-- 
"In my opinion, we don't devote nearly enough scientific research to 
finding a cure for jerks." (Calvin and Hobbes)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Checking if ManyToManyField is empty in pre_save function

2006-05-01 Thread Luke Plant

On Monday 01 May 2006 12:08, Dagur wrote:

> On further inspection I found out
> that the "authorised" field is set to all users before saving but is
> empty after saving.
>
> >>> t = Topic()
> >>> t.authorised.count()
>
> 2773L
>
> >>> t.save()
> >>> t.authorised.count()
>
> 0L
>
> Is this the desired behavior?

This is kind of a bug, caused by the fact that the ID of 't' is not set 
until it is saved, and 'authorised' is a dynamic attribute that does a 
database query on the many-to-many database table when you access it.  
It's impossible to evaluate .authorised properly until you have saved 
the object at least once.

It would be possible to get Django to throw an exception in this case.  
What do people think about that?

Luke

-- 
"In my opinion, we don't devote nearly enough scientific research to 
finding a cure for jerks." (Calvin and Hobbes)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: How can users only edit their own files?

2006-04-27 Thread Luke Plant

On Thursday 27 April 2006 16:27, Joseph Kocherhans wrote:

> > The idea is that the user can only delete/edit/etc their own
> > postings - anything else is denied. (This is obviously not for all
> > users, there need to be admins, etc who can edit everyones files).
> > The only way I can think of is setting up permission groups in
> > Users and maybe overwriting delete()? I haven't tried it yet, was
> > hoping someone with more mojo could shed some light.
>
> This should help, at least somewhat:
> http://lukeplant.me.uk/blog.php?id=1107301634

Also, another hack I have used is to selectively override parts of the 
admin using the url configuration, by using regexes that match URLs 
that would otherwise go straight to an admin view, and putting them 
before the main 'admin' regex:


urlpatterns = patterns('',
(r'^admin/myapp/mymodel/add/$', 'my.special.wrapper.for.add_stage'),
(r'^admin/myapp/mymodel/([^/]+)/$', 
'my.special.wrapper.for.change_stage'),
(r'^admin/', include('django.contrib.admin.urls')),
...



'my.special.wrapper' might wrap an existing admin view, or even 
duplicate large parts of it if necessary.

Luke

-- 
"I married Miss Right, I just didn't know her first name was 'Always'"

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: ZeroToMany ForeignKey

2006-04-22 Thread Luke Plant

On Saturday 22 April 2006 04:08, C. Allwardt wrote:
> You were correct in the "guessing" at what I meant :-)  It would have
> been more precise to state 0-1 to many.  In either case I tried the
> blank=True method and it seemed to get me a runtime error.  Then
> again it was late in the day and so the gremlines might have taken
> ahold.

You need both null=True (for the database) and blank=True (for the 
admin) for this to work.

Luke

-- 
"If your parents never had children, the chances are you won't either."

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: mange.py sql weirdness in MR

2006-04-21 Thread Luke Plant

On Wednesday 19 April 2006 14:53, njharman wrote:
> [Sorry if this should be on django-developer instead]
>
> r2714 of the magic-removal branch
>
> I have models/* and not a models.py in my app directory.
>
> #myapp/models/__init__.py
> from adventure import Story
> class Foo(models.Model):
> pass
>
> 'manage.py sql' produces output for Foo model but not Story model. 
> If I copy Story to __init__.py or move everything to models.py output
> is produced correctly.
>
> Is this intended?

Nope, and it works fine for me - I have the same setup, except I don't 
have the 'Foo' model, just the 'Story' model.  Of course, I do 
'manage.py sql myapp', not just 'manage.py sql' - actually I normally 
just use django_admin.py.

Luke

-- 
"If you're not part of the solution, you're part of the precipitate." 
(Steven Wright)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: problem with model (manytomany related)...

2006-04-21 Thread Luke Plant

On Friday 21 April 2006 08:15, skink wrote:

> class MyUser(meta.Model):
> name = meta.CharField(maxlength=30)
>
> def __repr__(self):
> return self.name
>
> class Note(meta.Model):
> noteText = meta.CharField(maxlength=100)
> writer = meta.ForeignKey(MyUser)
> publications = meta.ManyToManyField(MyUser)
>
> def __repr__(self):
> return self.headline
>
> but i don't know how to:
> 1 get list of Notes written by given MyUser (for user1 it'd be
> [note1, note2]
> 2. for a given Note get list of its readers (for note1 it'd be
> [user2, user3], for note2 [user3, user4])

> I think that my model is wrong...
> Could anyone point me out how my model would be?

class Note(meta.Model):
noteText = meta.CharField(maxlength=100)
writer = meta.ForeignKey(MyUser, related_name="written_notes")
publications = meta.ManyToManyField(MyUser, \
   related_name="readable_notes")

def __repr__(self):
return self.headline

related_name is important in this case because you have two 
relationships to the same model, so you need to be careful about 
disambiguating the reverse relationship.

> 1 get list of Notes written by given MyUser (for user1 it'd be
> [note1, note2]

user1.get_written_notes_list()

> 2. for a given Note get list of its readers (for note1 it'd be
> [user2, user3], for note2 [user3, user4])

note1.get_publications_list()

(NB - I think 'publications' is named confusingly - 'readers' would be 
better)

My apologies if I made some mistakes - I've been using m-r for a while 
and forgotten what the syntax was like before...

Luke

-- 
"If you're not part of the solution, you're part of the precipitate." 
(Steven Wright)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Accessing custom managers in O2M2O / using RelatedManager

2006-04-19 Thread Luke Plant


> Am I approaching the problem in the wrong way? how can i access custom
> manager functions for Bar, via baz? It throws an error complaining of
> RelatedManager...how can I write my own RelatedManager?

What error does it throw?

Luke


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



Re: possible to filter ManyToMany results?

2006-04-14 Thread Luke Plant

On Wednesday 12 April 2006 07:03, nkeric wrote:
> hi all,
>
> I've done some search, however, I guess I should ask for your helps
> here:
>
> I have the following models: (pseudo code)
>
> class ArticleType:
> name = ...
>
> class Article:
> title = ...
> article_type = meta.ForeignKey(ArticleType)
>
> class Game:
> name = ...
> articles = meta.ManyToManyField(Article)
>
> how can I retrive the articles of a certain article type of a given
> game?
>
> >>> g = games.get_object(pk=1)
> >>> g.get_article_list(article_type_id__exact=1)
>
> doesn't work, though I knew how to do this in raw sql...

As I understand it, Django should be able to do this query no problem.  
I think there may be a mistake in what you posted though - IIRC, I 
would have expected the method name to be 'get_articles_list' not 
'get_article_list', since you defined it as 'articles = 
meta.ManyToManyField(Article)'.  If you post the entire code for your 
models we may be able to find the problem.  Magic-removal branch 
doesn't really change what is possible here, it just changes the 
syntax.

Luke

-- 
"Humiliation: The harder you try, the dumber you look." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: A model which is recursively referring to itself in Magic Removal

2006-04-05 Thread Luke Plant

On Wednesday 05 April 2006 21:35, Rudolph wrote:
> Is that an inconsistancy to be removed (ie a bug)?

No, it's intended behaviour. The _set stuff is only there because for 
the 'other' end of these relationships it is possible that there is no 
name defined, so there needs to be a way of coming up with name 
automatically.  The way it is at present allows you to write stuff like 
myobject.children.filter(..etc), rather than myobject.child_set

Luke

-- 
"Despair: It's always darkest just before it goes pitch black." 
(despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Relationship with self with relationship data in app.py

2006-04-03 Thread Luke Plant

On Monday 03 April 2006 21:45, Grimboy wrote:
> I have this problem with the following code (highlight:
> http://pastebin.com/638352)
>
> Basically I want a Model that relates with itself, the relationship
> its self will also have data. (That's why I've made it a seperate
> Model).

Have a look in tests/modeltests/mutually_referential/models.py in the 
source (these tests are a very good source for how to do stuff).

Luke

-- 
"Cross country skiing is great if you live in a small country." (Steven 
Wright)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Brain fried - need help with M2M and MR

2006-04-03 Thread Luke Plant

On Monday 03 April 2006 19:12, tonemcd wrote:

> I'm using magic-removal and have a 'simple' model for a tag-based
> posting system (which will turn into a voting and image uploading
> system).
>
> Here's the model (slightly cut down to save space);
>
> class Tag(models.Model):
> slug = models.SlugField(
> 'Slug',
> prepopulate_from=("title",),
> help_text='Automatically built from the title.',
> )
> title = models.CharField('Title', maxlength=30)
> description = models.TextField(
> 'Description',
> blank = True,
> help_text='Short summary of this tag'
> )
> def __repr__(self):
> return self.title
>
> and
>
> class Post(models.Model):
> slug = models.SlugField(
> 'Slug',
> prepopulate_from=('title',),
> help_text='Automatically built from the title.',
> primary_key='True'
> )
> assoc_tags = models.ManyToManyField(Tag)
> title = models.CharField('Title', maxlength=30)
>
> What I want to do is get a list of posts that are related to a tag. 

I think it will look like this, if t is a Tag:

t.post_set.all()

If you want to change 'post_set' to something else, you need to supply a 
'related_name' keyword argument to the assoc_tags field.

By the way, if you can get ipython for your system, you should really 
try it out - it makes finding these things out really easy.

Luke

-- 
"Cross country skiing is great if you live in a small country." (Steven 
Wright)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: limit_choices_to

2006-03-29 Thread Luke Plant

On Monday 27 March 2006 16:50, [EMAIL PROTECTED] wrote:

> I've just used the first bit of Luke's wheeze- storing the user.id
> and stuffing it in the model's save method.
> I had to put 'null-True' in the model to get the user.id bit of this
> to work. Otherwise the 'if self.officer_id is None:' always failed.
> Left a comment on the web site, Luke.

Cheers - I responded on my blog.

Luke

-- 
"A man in love is incomplete until he is married. Then he is finished." 
-- Zsa Zsa Gabor, "Newsweek"

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: limit_choices_to

2006-03-29 Thread Luke Plant

On Sunday 26 March 2006 21:01, tonemcd wrote:

> I think that this http://lukeplant.me.uk/blog.php?id=1107301634 might
> be helpful. There's also been some traffic on limit_choices_to in the
> group recently (although not strictly relevent to your problem I
> think)

Note that this blog entry assumes magic-removal.  I think the middleware 
bit should work in trunk, but I don't know.  In your situation (yml), I 
think you need to create some kind of 'LazyUser' object in the style of 
LazyDate.  The LazyUser object would use my get_current_user() 
function.  Implementation is left as an exercise for the reader :-)

Also, re: limit_choices_to - it wasn't working on m-r until r2547 (March 
22), but it should be fixed now.

Regards,

Luke

-- 
"A man in love is incomplete until he is married. Then he is finished." 
-- Zsa Zsa Gabor, "Newsweek"

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Virtual hosting and CommonMiddleware redirects

2006-03-28 Thread Luke Plant

On Wednesday 29 March 2006 00:33, Luke Plant wrote:
> Hi,
>
> I'm using python-hosting which is working great so far.  I've found
> one problem with the way that CommonMiddleware does redirects.
> Python-hosting give you your own apache instance, forwarding on
> requests from the main one on the same machine (I think).  This
> means that HTTP_HOST is not set as you might expect.  

I've found that 'HTTP_X_FORWARDED_HOST' *is* set to what I expect.  Does 
anyone know if this a standard mechanism, and one that Django could use 
if it found it instead of HTTP_HOST?  A quick google suggests Rails 
does this.

Luke

-- 
"A man in love is incomplete until he is married. Then he is finished." 
-- Zsa Zsa Gabor, "Newsweek"

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Virtual hosting and CommonMiddleware redirects

2006-03-28 Thread Luke Plant

Hi,

I'm using python-hosting which is working great so far.  I've found 
one problem with the way that CommonMiddleware does redirects.  
Python-hosting give you your own apache instance, forwarding on 
requests from the main one on the same machine (I think).  This 
means that HTTP_HOST is not set as you might expect.  I've had to 
monkey patch django (magic-removal) as below to get it to work, 
but it is fragile with respect to other potential vhost 
configurations I think.  Any other ideas how to fix this -- either 
fix django or resolve the problem some other way?

Cheers,

Luke



Index: django/middleware/common.py
===
--- django/middleware/common.py (revision 2584)
+++ django/middleware/common.py (working copy)
@@ -31,6 +31,8 @@

 # Check for a redirect based on settings.APPEND_SLASH and 
settings.PREPEND_WWW
 old_url = [request.META.get('HTTP_HOST', ''), request.path]
+if old_url[0].startswith('127.0.0.1'):
+old_url[0] = ''
 new_url = old_url[:]
 if settings.PREPEND_WWW and old_url[0] and not 
old_url[0].startswith('www.'):
 new_url[0] = 'www.' + old_url[0]

-- 
"A man in love is incomplete until he is married. Then he is finished." 
-- Zsa Zsa Gabor, "Newsweek"

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: trying to get my first app up.

2006-03-24 Thread Luke Plant

On Friday 24 March 2006 16:49, sergio_101 wrote:

> but no matter what happens, i get this:
>
> ViewDoesNotExist at /opps/
> Could not import learningOpps.opps.views. Error was: cannot import
> name opps
>
> can someone tell me what i am doing wrong?

Have you created __init__.py files in the relevant directories?

Luke

-- 
A dyslexic agnostic doesn't believe in Dog 

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: magick-removal: Two questions

2006-03-14 Thread Luke Plant

On Tuesday 14 March 2006 21:43, Viktor Kerkez wrote:

> 1. Why are the generic views from list_detail package different from
> the views from create_update package.
>
> When I use create_object or update_object, I have to pass to it
> {'model' : MyModel} dict, but when I use object_list I have to do:
>
>  from django.db.models.query import QuerySet
>  info_dict = {'queryset' : QuerySet(model=MyModel)}

The list_detail is fundamentally different from create/update - the 
former is just used for displaying a set of objects (which might have 
additional filters), but the create/update views need a model class 
since they will be creating/changing instances of that class.

The way I had anticipated using the queryset parameter was:

  info_dict = {'queryset' : MyModel.objects.all() }

... so you don't have to import QuerySet.

> 2. Why does the object_list return 404 when my table is empty,
> instead of rendering the template with object_list variable beeing an
> empty list.

You can pass 'allow_empty=True' to get the behaviour you want.  I think 
personally that should be the default -- IIRC there is a ticket about 
this.

Luke

-- 
"Whom have I in heaven but You?
And there is none upon earth that I desire besides You." Psalm 73:25

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: using context_instance=DjangoContext(request) in generic view url.

2006-03-13 Thread Luke Plant

On Monday 13 March 2006 05:47, coulix wrote:

> hum to reformulate simpler,
> how can i tell in url.py to use generic.simple, and a extra_context
> which will replace
>  context_instance=DjangoContext(request) i was using in my view
> method.

Generic methods use DjangoContext anyway -- you don't have to do 
anything to achieve this.

Luke

-- 
"Where a person wishes to attract, they should always be ignorant." 
(Jane Austen)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: url config and generic views and non generic views.

2006-03-11 Thread Luke Plant

On Saturday 11 March 2006 15:34, coulix wrote:

> What's the trick ? to make them cohabit.

Hints: 
  1) the first argument to patterns() is just a prefix that is added to 
names of the view functions to avoid repeating it for every one.
  2) patterns() returns a simple list, and you can combine lists using 
just '+'

Luke

-- 
"Underachievement: The tallest blade of grass is the first to be cut by 
the lawnmower." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Can I pass a python iterator to a template?

2006-03-11 Thread Luke Plant

On Friday 10 March 2006 02:19, Mike Kent wrote:

> So, am I completely off base here?  Is what I want to do not
> possible, or is there another way I can tackle this?

This could be considered as a bug in the 'for' tag in that it does a 
len() when it perhaps doesn't need to.  If you try to patch it to 
remove len() then the following will be unavailable:

 - reversed mode
 - 'revcounter' variable
 - 'revcounter0' variable
 - 'last' variable

However, I don't see those as a big obstacle, provided it was documented 
that if the collection had no __len__ method then you wouldn't have 
those options/variables.

Luke

-- 
"Underachievement: The tallest blade of grass is the first to be cut by 
the lawnmower." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: login page

2006-03-10 Thread Luke Plant

> 
> Enter Username: 
> Enter Password: 
> 

You've duplicated 'username' there - it might be your problem (though
it seems unlikely actually).  Also make sure there isn't any
redirection going on.  You can check easily if you are running the
development server by looking at the output on the console.

Also, just to mention on the *args and **kwargs front - you don't
actually have to modify that bit in the example given in the docs.  The
*args and **kwargs are real syntax, not meta-syntax that you have to
replace.

Luke


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



Re: Django in Boo

2006-03-04 Thread Luke Plant

On Saturday 04 March 2006 05:12, wizeman wrote:

> Think about it. Python was an esoteric language in the beginning. And
> Boo isn't that esoteric, it can be thought of as an extension to the
> Python syntax.
> And virtually all .NET libraries can be used in Boo, it runs on the
> .NET/Mono runtime.

The .NET libraries are very unpythonic.  They are about the last 
libraries I'd *want* to use if I were using python or a python-like 
language.  For example: all the public method names start with capital 
letters (so they look like classes); only instances are first class 
objects; there are huge numbers of unwieldy collection classes (now in 
untyped, strongly typed and generic flavours) instead of a few good 
ones etc. etc.  The only languages I've seen that the .NET libraries 
work well with are C# and VB.NET (and VB.NET is really just C# 1.0 
without the curly braces -- yes, really).

For the same reason I'm not particularly drawn to using IronPython in my 
day job, even if I could, because I'd still have to use .NET libraries 
for the projects I work on.

Luke

-- 
"The first ten million years were the worst. And the second ten 
million, they were the worst too. The third ten million, I didn't enjoy 
at all. After that I went into a bit of a decline." (Marvin the 
paranoid android)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Ordering with respect to a function in models?

2006-03-03 Thread Luke Plant

On Friday 03 March 2006 01:01, Malcolm Tredinnick wrote:

> Unfortunately, Meta.ordering seems to want a real field, not a method
> (which Admin.list_display can take) or a property.
>
> So am I missing something, or is this even a common need for other
> people?

Meta.ordering does ordering in the database using an SQL 'ORDER BY' 
clause, so you can't use a function defined in your model to do that 
ordering.

A solution (or part of one) is available in magic-removal.  You can 
create your own custom manager, and it has a method get_query_set that 
you can override.  You could then create a subclass of QuerySet that 
has certain methods overridden to do ordering after the data is 
returned. (I think the one you'd need to override is 
QuerySet._get_data).  

The first 'Manager' to be defined is used as the default one, so your 
custom manager would work in the Admin and elsewhere.

There may still be issues in getting this to play well with other 
ordering, I'm not sure, but they should be fixable.

Luke

-- 
"The first ten million years were the worst. And the second ten 
million, they were the worst too. The third ten million, I didn't enjoy 
at all. After that I went into a bit of a decline." (Marvin the 
paranoid android)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Database API

2006-03-01 Thread Luke Plant

On Wednesday 01 March 2006 21:54, Paul Smith wrote:

>   ...to work the same way. Does this shortcut only work because the
> ManyToManyField was added to the article model, and not the author
> model, or am I doing something wrong? My authors and articles are in
> different apps.

IIRC, you have to do author.get_[article_app]_article_list().  This is 
because for this end of the relationship, Django has to work out a name 
to give it (for the other end it just uses the name of the attribute, 
'author').  You can override it using 'related_name' on the 
ManyToManyField.

Luke

-- 
"Smoking cures weight problems...eventually..." (Steven Wright)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Help with Generic Views in Magic Removal Branch

2006-02-25 Thread Luke Plant

On Saturday 25 February 2006 18:25, ChaosKCW wrote:

> A dumb question, but will objects.all() cause any kind of performance
> hit ?
>
> I mean when the code appends QuerySet.filter(pk=object_id), will it
> condense that to a SQL statement that returns one object or reutrn
> all obejcts then do the PK query ?

It creates a new SQL statement that returns one objects, without ever 
having done the original query, so there is no performance hit.  To do 
the PK query client side would mean you'd have to replicate all the 
features of the DB in Python.

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Help with Generic Views in Magic Removal Branch

2006-02-25 Thread Luke Plant

On Saturday 25 February 2006 17:43, ChaosKCW wrote:

> Just one question, I have used model.objects, not
> model.objects.all(). It appears to work and makes more sense to me.
> Any comments?

Use model.objects.all() (at least for now). model.objects will work in 
some cases, but perhaps not in others. (Technically, it's to do with 
QuerySets caching their result for efficiency, and the fact that you 
don't want 'model.objects' to cache it's result).

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Help with Generic Views in Magic Removal Branch

2006-02-25 Thread Luke Plant

On Saturday 25 February 2006 17:47, ChaosKCW wrote:
> Hi
>
> Is there some documentation on the "Sites" functionality. I have seen
> it, but not seen any docs ?

'Site' in that example was a model in my own app -- there is a Django 
model of the same name, but I don't know that much about it.

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Help with Generic Views in Magic Removal Branch

2006-02-25 Thread Luke Plant

On Saturday 25 February 2006 16:58, ChaosKCW wrote:

> Please can someone help. I am following Tutorial4 for generic views,
> plus adapting it to the magic removal instructions on the wiki page.
> As far as I can tell i followed the instructions exactly, But I get
> an error stating that 'model' is not a valid paremeter to the view.

The tutorial is now badly out of date for magic-removal.  Instead of 
taking a model and app_label, they take a 'queryset' argument, which 
should be a QuerySet object.  QuerySet objects are what you implicitly 
use in magic removal to do all lookups on the database.  For instance, 
Poll.objects.all() is a QuerySet.  Because QuerySets are 'lazy', you 
can create them in your URL conf and the data won't be retrieved at 
that point, but each time the generic view is actually called.  In my 
urls.py I have something like this:

(r'^sites/$', 'list_detail.object_list',
{'queryset': Site.objects.all(),
 'template_name': 'cciw/sites/index'
}
),
 
(r'^sites/(?P.*)/$', 'list_detail.object_detail',
{'queryset': Site.objects.all(),
 'slug_field': 'slug_name',
 'template_name': 'cciw/sites/detail'
 }
),
...

Note how I use all the 'Site' objects in the both cases, but don't worry 
-- only in the first case does it actually result in all the objects 
being retrieved from the db, in the second case the view derives a new 
QuerySet, based on the one passed in, that only gets a single object.

I personally think the new syntax is much nicer - no need for 
'extra_lookup_args' etc.  If you wanted to have a different ordering 
plus extra filtering, you could change Site.objects.all() to e.g.
Site.objects.filter(visible=True).order_by('name').

One thing - I'm not sure all the generic views have been updated yet.  I 
do know the above examples work.

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: ORDER BY on get_object?

2006-02-25 Thread Luke Plant

On Saturday 25 February 2006 14:33, Ned Batchelder wrote:

> If I omit the ordered attribute, then there is no ORDER BY clause.
> Surely the code that knows to omit the clause entirely in that case
> could be triggered in the single-object case? I know, it's foolish to
> ever guess at the structure of unknown code...

You are right, it wouldn't be hard to change -- I was thinking about it 
in the wrong way.  See Adrian's e-mail for an answer.

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: ORDER BY on get_object?

2006-02-25 Thread Luke Plant

On Saturday 25 February 2006 14:07, Ned Batchelder wrote:

> So there are SQL queries like this:
>
> SELECT field, field FROM app_model WHERE id = 50 ORDER BY date DESC
>
> Surely the ORDER BY clause can be omitted?  Is the magic-removal
> branch already fixing this?

Yep, the order by clause could be omitted.  However, in magic-removal 
(and I guess on trunk) the same mechanism is used to get single objects 
and multiple objects - for single objects you just filter on the value 
of the primary key.  So removing the ORDER BY would be more trouble 
than it's worth - you would have to add a special case for it (and the 
code to check for it might not be completely trivial), and it wouldn't 
have any effect on the results.  I can't imagine it would have much 
effect on performance either, but I don't know much about DB 
optimisation.  If you can show that it does affect performance on a 
popular DB then there would some motivation to change this.

Regards,

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Get list by Foreign Key when using generic views

2006-02-23 Thread Luke Plant

On Thursday 23 February 2006 13:53, [EMAIL PROTECTED] wrote:

> I would like to display a list of "statements" for a particular
> "account". The "account_id" is a foreign key on "statements" table.
> Is it possible, using generic views, to specify in the urlpatterns
> the  that will generate SQL query that will query on
> foreign key ("account_id") rather then primary key ("id")?
>
> In SQL terms I wish to achieve the following if possible while still
> using the generic view module:
> SELECT * FROM statements WHERE account_id=
> instead of using primary key as filter
> SELECT * FROM statements WHERE id=
>
> If this is possible, what is the key requirement for getting this to
> work?

Think about it this way:  you want to get a specify account, and then 
view all the statements for that account, right?  So use an 
'object_detail' generic view to display a single 'account' object (the 
account_id being retrieved from the URL), and in the template do 
something like this:

{% for statement in object.get_statement_list %}
   whatever
{% endfor %}

The only down side is that you are getting the 'account' object perhaps 
unnecessarily.

Luke

-- 
OSBORN'S LAW
Variables won't, constants aren't.

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: admin-logout + opera8.52?

2006-02-22 Thread Luke Plant

On Tuesday 21 February 2006 22:45, gabor wrote:

> hi,
>
> is there anyone using opera8?
>
> because for me it seems that i am unable to log out using opera8.*
> from the admin interface.
>
> so before i start digging deeper...does anyone else has this problem?

Just tried it with 8.51 .  I get a logout screen but I'm not actually 
logged out.  Logging out works correctly in at least Konqueror and 
Firefox.

Luke

-- 
O'REILLY'S LAW OF THE KITCHEN
Cleanliness is next to impossible.

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: forward references

2006-02-18 Thread Luke Plant

On Saturday 18 February 2006 13:03, Amit Upadhyay wrote:
> from django.models.myapp import articles

You will have to put thus inside the _pre_delete function, not at the 
top of the module.

Luke

-- 
"My capacity for happiness you could fit into a matchbox without taking 
out the matches first." (Marvin the paranoid android)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: ForeignKey dropdown list in custom view

2006-02-18 Thread Luke Plant

On Saturday 18 February 2006 03:12, bsnipes wrote:
> I finally see!  What is returned by get_object() is dependent upon
> the results of the __repr__ method in the model setup.  Hmmm. now
> to get it into a parsable format...

No, get_object() gets the object itself, with .name and all the other 
attributes.  What you see at an interactive prompt, or what you see if 
you just have the food object in a template like you described, depends 
on repr(), which calls __repr__() on you object.  So you detail 
template needs to look like this:

--- snip
{{ fentry.name }}
--- end snip

(or whatever).

Luke

-- 
"My capacity for happiness you could fit into a matchbox without taking 
out the matches first." (Marvin the paranoid android)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Request for ideas

2006-02-17 Thread Luke Plant

On Wednesday 15 February 2006 15:59, Eric Walstad wrote:

> Be careful about what you choose to document.  Django's magic-removal
> branch will be a significant change and there may be other backwards
> incompatible changes before Django 1.0 is born. 

I would second that. Have a look here:
http://code.djangoproject.com/wiki/VersionOneFeatures
and
http://code.djangoproject.com/wiki/RemovingTheMagic
to see just how much is going to change.  I think you can probably 
implement an app and then convert it to magic-removal without too much 
pain, but there are some things I would steer clear of (e.g. using 
subclassing, which doesn't even seem to be settled in terms of the 
aim).  

If you wanted to use the magic-removal branch, its current official 
status is 'Not for the faint of heart at this point. Still being 
heavily developed.'.  It is fairly usable at the mo', but you may find 
a fair amount of time is spent reporting bugs (which would be useful to 
the devs, of course, but might not be your aim), and some major bugs 
aren't fixed as fast as they are on trunk.

Luke

-- 
"Mistakes: It could be that the purpose of your life is only to serve 
as a warning to others." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Is context variable 'user' automatic in templates?

2006-02-11 Thread Luke Plant

On Saturday 11 February 2006 22:00, Roberto Aguilar wrote:

> I've noticed that in certain instances, in a flatpage, for example,
> the user context variable is available in my templates.  However,
> most of the time I have to explicity provide it like when using
> render_to_response.  Is this a bug, feature, or am I just not doing
> something right?

The 'user' context variable is provided by 'DjangoContext' (more 
specifically, by one of the 'processors' that DjangoContext uses:
http://www.djangoproject.com/documentation/templates_python/#subclassing-context-djangocontext
 )

DjangoContext is used by all the generic views (including flatpage). If 
you want it in your own views, just use DjangoContext instead of 
Context, passing the 'request' object into the DjangoContext 
constructor.

Regards,

Luke

-- 
Life is complex. It has both real and imaginary components. 

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: How to find the label for a value

2006-02-11 Thread Luke Plant

On Saturday 11 February 2006 10:53, PythonistL wrote:

> 
> Choice 1
> Choice2
>   
>
> It is easy to find the value( here 1 and 2) but how, in Django , can
> I find the label( here Choice 1 and Choice2) ?
> E.g. when a user chooses the first option, I need to know that the
> choosen label was Choice 1

The only piece of data that is passed back is the 'value' - this is 
standard HTML and Django doesn't do any different.  You will have to 
map the values back to choices when checking the GET/POST data. 

The clever thing to do, to obey DRY, is something like this:

view module:

CHOICES = {
1: 'Choice 1',
2: 'Choice 2',
}

view code (for creating the form):
--
context['choices'] = CHOICES.items()
# render_to_response stuff etc.


template code:
--

{% for choice in choices %}
 {{ choice.1|escape }}
{% endfor %}


view code (for parsing input):
--
try:
choice = CHOICES[request.GET['userchoice']]
except AttributeError:
# handle invalid input


Luke

-- 
Life is complex. It has both real and imaginary components. 

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: displaying a foreign key in admin list and template exception

2006-02-11 Thread Luke Plant

On Friday 10 February 2006 23:28, Andu wrote:

> Now, addinga a currency works fine. Trying to add a customdata, when
> saving, yelds a template exception. I've read on this group that this
> might be because something's wrong in the model. Any ideas?

The only thing that is unusual in your model is the use of 'to_field'.  
It is possible that there is a bug in the admin when 'to_field' is 
used.  You could try changing your example to simply remove it (so that 
the default primary key is used instead), and see if that works.  
Alternatively, change the Currency model so that 'name' is the primary 
key (in which case you can still remove the to_field in CustomData).

If it does work with those changes, then it is probably a bug with 
to_field - it would be really helpful in that case if you file a 
ticket.

Thanks,

Luke

-- 
Life is complex. It has both real and imaginary components. 

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: Problem using a related object in __repr__()

2006-02-01 Thread Luke Plant

On Wednesday 01 February 2006 22:05, [EMAIL PROTECTED] wrote:


> With this setup, I can create a Bar in the admin page, but when I hit
> "submit", it throws an exception.  Unfortunately the exception gets
> clobbered, but I added a quick one-liner hack to print it out before
> it gets clobbered, and this is the error:
>
> 'Bar' object has no attribute 'foo'
>
> What am I missing?

In trunk, you have to do self.get_foo().name, not self.foo.name 

However, this has changed in the magic-removal branch (to what you 
tried).

Luke

-- 
I never hated a man enough to give him his diamonds back. (Zsa Zsa 
Gabor)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: new here and where/how/what to cache...

2006-02-01 Thread Luke Plant

On Wednesday 01 February 2006 09:10, Bram de Jong - MTG wrote:

> Now, I have some questions about caching. Here goes:
>
> 1. how does one cache websites (with django) that have personalized
> views for the users? I.e. there's lot's of thing like
>
> if(user has voted for this item)
> display "hello  you voted /10 for this item"
> else
> display voting dropdown

If you use the SessionMiddleware, it automatically adds a 'Vary' header 
for the 'Cookie' HTTP header.  This does 2 things - internally it uses 
the session cookie as part of the cache key (so different sessions 
effectively get there own cache) and also tells other web caches that 
the content varies depending on the cookie i.e. instructs them to do 
the same thing.  So basically, this is handled for you if you use that 
middleware.

> 2. does django automatically invalidate caches when objects,
> displayed in the cached page, are changed? I.e. say a person votes
> and you want to display the page with his new vote on it. This means
> I should invalidate the cached page. Does django help me with this in
> any way, or should it be done by the coder.

No, it doesn't invalidate the cache, since it can't work out whether 
what has changed will affect the output of the page (at least, not 
without introducing a lot of overhead and tight coupling between the 
template system and the ORM).  

However, it never caches for POST requests, and only POST requests 
should have side effects.  So for adding a vote, you should use a POST 
request and this will always return a fresh page, so this example 
should work out fine.

Luke

-- 
I never hated a man enough to give him his diamonds back. (Zsa Zsa 
Gabor)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: Error when relating a model to another model more than once

2006-02-01 Thread Luke Plant

On Wednesday 01 February 2006 08:40, Rudolph wrote:

> But do you know a solution to my original problem when relating a
> model to another model more than once, which gives errors in the
> admin interface. Using 'related_name' doesn't solve it.

I think I just saw a bug filed against this, have a look on the website.  
I don't imagine it will be fixed in trunk, as the fix would just have 
to be reworked for magic-removal and (we are all hoping that) 
magic-removal will be merged in before too long.  (Don't ask for a 
clarification of 'too long'!)

Luke

-- 
I never hated a man enough to give him his diamonds back. (Zsa Zsa 
Gabor)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: Error when relating a model to another model more than once

2006-01-31 Thread Luke Plant

On Tuesday 31 January 2006 14:46, Rudolph wrote:
> Hi,
>
> I couldn't get the magic removal branch started without spending time
> on fixing some errors (createsuperuser didn't work and runserver told
> me "No module named sessions"). Could someone with a bit more Django
> experience than me, try the code on the magic removal branch? Or does
> someone know a different solution to my problem?
> I really need to get this working for a project.

Lots of things have been moved round in magic-removal, so some of the 
settings that are in the docs are now different.  I think I saw the 
error you are seeing due to an incorrect MIDDLEWARE setting.  Mine 
currently looks like this:

MIDDLEWARE_CLASSES = (
"django.middleware.common.CommonMiddleware",
#"django.middleware.cache.CacheMiddleware",
#"django.middleware.gzip.GZipMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
)

There are other settings which also need to be changed, and I'm not sure 
if django-admin in magic removal has been updated properly.

I'm afraid that, at the moment, magic removal is for those who are happy 
chasing bugs like these, and working without correct docs!  Also, you 
might want to try out r2139 of the magic-removal branch - after that 
things are pretty broken (like, don't expect the admin interface to 
work at all), due to a large syntax change. Overall, it's probably 
better to wait.

Luke

-- 
"Ineptitude: If you can't learn to do something well, learn to enjoy 
doing it poorly." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

-- 
"Ineptitude: If you can't learn to do something well, learn to enjoy 
doing it poorly." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: Question About Multi Column Keys

2006-01-31 Thread Luke Plant

On Tuesday 31 January 2006 16:59, kggroups wrote:
> I'm considering building my next web app in either Django or Rails
> because I'm sick of php.  Before I jump in though, I was wondering
> how django handles multicolumn keys.

If you need to, you can specify constraints using unique_together - see
http://www.djangoproject.com/documentation/model_api/

The Django ORM basically assumes a third normal form database design.  
It half enforces this by adding a primary key to every table (if you 
don't specify one yourself), and only allows one field to be a primary 
key in the class definition.  However, there is nothing to stop you 
adding other constraints (using unique_together or directly on the 
database), and effectively using that as your primary key.  The 
automatic primary key is needed for things like the admin interface to 
work i.e. you need a simple way of being able to specify an object to 
delete.

Luke

-- 
"Ineptitude: If you can't learn to do something well, learn to enjoy 
doing it poorly." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

-- 
"Ineptitude: If you can't learn to do something well, learn to enjoy 
doing it poorly." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: broken link in templates_python

2006-01-19 Thread Luke Plant

On Thu, 19 Jan 2006 13:54:31 - Luke Skibinski Holt wrote:

> Ordinarly the sig is plain 'Luke', however there is already one 'Luke'
> posting, so as not to defraud your good self, my posts are signed with
> my full name. Hope this didn't cause you too much confusion.

If you wanted we could come to a fairer compromise on the
disambiguation front:

from holt.skibinski import Luke as LukeH
from plant import Luke as LukeP

:-)

Luke P

-- 
If you can't answer a man's arguments, all is not lost; you can still 
call him vile names. (Elbert Hubbard)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: broken link in templates_python

2006-01-18 Thread Luke Plant

On Wed, 18 Jan 2006 16:36:00 - Luke Skibinski Holt wrote:

> Luke Skibinski Holt

Well are you called Luke or Alice?  Is this some cunning ploy to get
answers quicker, by pretending to be multiple people? :-)

Confused,

Luke

-- 
"Idiocy: Never underestimate the power of stupid people in large 
groups." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: unordered_list... explanation?

2006-01-18 Thread Luke Plant

On Wed, 18 Jan 2006 21:22:29 +0100 gabor wrote:

> i'm trying to use the unordered_list filter, with little success :(
> 
> i tried the provided example ( ['States', [['Kansas', [['Lawrence',
> []], ['Topeka', [, ['Illinois', [ ),
> and it works,
> 
> but i am unable to understand it.

It uses an empty list to indicate the end of a list, I'm not sure
exactly why :-).  There are more examples in the tests (under
'othertests').

Luke


-- 
"Idiocy: Never underestimate the power of stupid people in large 
groups." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: extra context processors

2006-01-17 Thread Luke Plant

On Tue, 17 Jan 2006 14:02:24 - Alice wrote:

> Where would I put extra processors? in /myproject/processors.py ?
> Processors are global and not an app specific one ... so where are
> others putting theirs? Just after a bit of django etiquette...

They are pretty new, so you can be the trend setter :-)

I guess it would depend on what kind of thing they contain i.e. do they
relate to a certain app, or custom tag, or model.

Luke

-- 
"I asked mom if I was a gifted child. She said they certainly wouldn't 
have paid for me." (Calvin and Hobbes)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: Passing template tags template variables

2006-01-14 Thread Luke Plant

On Sat, 14 Jan 2006 16:12:50 - Alice wrote:

> I just finished writing the tag and realized that it won't work unless
> I can access the data passed to the template. Any help in getting
> around this (probably simple) problem would be welcome.

The 'render' method of custom tag gets passed the 'context' of the
template:

class YouCustomTagNode:
def render(self, context):
...

That context is the same one passed into the template for rendering. If
the custom tag always uses the same data from the context, this is the
way to go, and is very easy.

Luke

-- 
"He knows the way I take: when he has tried me, I shall come forth as 
gold" (Job 23:10).

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: Django and MS SQL

2006-01-10 Thread Luke Plant

On Tue, 10 Jan 2006 14:33:18 -0600 Adrian Holovaty wrote:

> The problem is that the SQL Server database backend (the "adodbapi"
> library) assumes placeholders use "?" for placeholders. So the Django
> layer needs to convert all "%s" placeholders in the query to "?".
> 
> It looks like the current way this is happening (in
> django/core/db/backends/ado_mssql.py) isn't working. Could you tinker
> with this and see what you can fix?

Just adding what I know about MS SQL, in complete ignorance of adodbapi:

The best way to do it with MS SQL is to use 'Parametrised SQL'.  In
this case you have a query string that looks like

SELECT foo FROM bar WHERE baz = @baz

and you also pass in (somehow) the value of @baz (I only know how to do
this in C#/.NET - you have a Command object (whose .Text property is
the SQL) to which you add SqlParameter objects).

The advantage of this is that MS SQL can then generate a strategy for
doing the query, (in the same way it does for stored procs) and these
are cached.  Because you are not substituting in the values of @baz
directly, but letting MS SQL do it, you can get good hit ratios on the
'query strategy cache' (I can't remember the right word for it, but you
get my meaning).

I don't know how much adodbapi can do, but if you could make use of
this feature it would be very good.  Performance is one reason often
quoted for doing stored procs instead of straight SQL.  If you can use
parametrised SQL, that argument almost disappears, because MS SQL can
(and does) optimise in the same way that it does for stored procs.

Another thing to note is that the values of parameters should not be
escaped with this method (this is another reason for using parameters
- they avoid SQL injection).

Luke


-- 
"Dysfunction: The only consistent feature of all of your dissatisfying 
relationships is you." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: Using Change Manipulators to Update Only a Subset of Model Data

2005-12-30 Thread Luke Plant

On Thu, 29 Dec 2005 17:57:45 -0800 cpburmester wrote:

> I see one reccommendation described at:
> 
> http://code.djangoproject.com/wiki/CookBookManipulatorWithPostpopulatedFields
> 
> but I'm trying to do the inverse - allow the update of only, say, one
> field and keep the rest the same whereas this example is preserving a
> few and updating the majority.
> 
> The analogy in SQL would be:
> 
> update tablename set foo="bar" where id=some_id;
> 
>  - i.e. only one field is changed, the rest are preserved.
> 
> It seems that in order to use a manipulator, I have to specify all the
> fields. This is very unweildy for what I'm trying to do.

I think the purpose of manipulators is to take the donkey work out
of updating multiple fields.  If it's only one field, then why bother
with the manipulator?  Just grab the object, read the request.POST data
for the one field, update the object and save it.
myobject.foo = request.POST["foo"]
myobject.save()

The disadvantage with this is you don't get the nice validation stuff
that manipulators do.  I'm not sure if there is a way to call the
validators directly.


Luke

-- 
"A man in love is incomplete until he is married. Then he is finished." 
-- Zsa Zsa Gabor, "Newsweek"

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: weird template(?) error

2005-12-27 Thread Luke Plant

On Tue, 27 Dec 2005 12:20:23 +0300 wiz wrote:

> 
> How to deal with such errors?
> 

I think the way to do it is to turn TEMPLATE_DEBUG=False so you can see
the real error message.

I often get a similar error message when exceptions happen in certain
places and the debugging template trips up when trying to do repr() over
partly constructed objects (or something like that).

Luke

-- 
"Agony: Not all pain is gain." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: Newbie needs help with real-world example...

2005-12-01 Thread Luke Plant

On Thu, 1 Dec 2005 06:41:38 -0500 John Szakmeister wrote:

> It runs, but
> unfortunately, it complains that it can't find any pages.  Not the
> weblog, not the main page, nothing.  

I'm guessing the pages are stored in the database.  Do you have a copy
of the djangoproject.com DB?  I wouldn't have thought it was publicly 
available.

Luke

-- 
"The number you have dialed is imaginary.  Please rotate your telephone 
by 90 degrees and try again."

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


  1   2   >