Discussion:
a few questions about django
Florian Apolloner
2006-11-07 16:45:40 UTC
Permalink
I have a few questions about django, where I didn't found the answer in
the docu.

Here they are:

1.) In the admin-area you can use filters ( list_filter = ('is_staff',
'is_superuser') ), which show by default all entries. Now I want to
have the entries prefilterd (let's say i have a boolean field, and want
all entries with true filtered out).
Which way is the easiest way to do so?

2.) Is there a hook or something to execute custom functions, if
someone clicks save in the admin area?

3.) Lets assume I have a model with an integerfield position. In the
admin-area I would like to be able to set this field to something, that
would get me two arrows (up and down) to change place with the next
item. Is there a way to do so? (Like a navigation-admin where I want to
get 'Home' from bottom to top, or 'contact' after 'Forum' and not
before it....)

I apologize for my bad English.

Kind regards Florian Apolloner


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
James Bennett
2006-11-07 17:08:40 UTC
Permalink
Post by Florian Apolloner
1.) In the admin-area you can use filters ( list_filter = ('is_staff',
'is_superuser') ), which show by default all entries. Now I want to
have the entries prefilterd (let's say i have a boolean field, and want
all entries with true filtered out).
Which way is the easiest way to do so?
list_filter should produce a list of links in the sidebar you can
click on to filter according to the values of the field; for example;
using 'is_staff' in list_filter for the auth.User model lets you click
to see either all users who are staff, or all users who aren't.
Post by Florian Apolloner
2.) Is there a hook or something to execute custom functions, if
someone clicks save in the admin area?
For custom save functionality, your model class can supply a custom
'save' method which executes anything you like; the documentation has
some simple examples:
http://www.djangoproject.com/documentation/model_api/#overriding-default-model-methods
Post by Florian Apolloner
3.) Lets assume I have a model with an integerfield position. In the
admin-area I would like to be able to set this field to something, that
would get me two arrows (up and down) to change place with the next
item. Is there a way to do so? (Like a navigation-admin where I want to
get 'Home' from bottom to top, or 'contact' after 'Forum' and not
before it....)
There's nothing built in to Django which does this, and building it
into the admin would probably involve quite a bit of work. Writing
your own custom view which handles it probably wouldn't be too hard,
though. The biggest problem you'll run into is that performance will
be bad -- to do this, every save of an instance of the model will have
to SELECT all instances of that model and run UPDATE against a
potentially large number of them.

If you want to set that up, though, a manager method is probably the
best way to go (e.g., a method on the model's manager class which
takes an instance and a new value for its "order", and then works out
which other instances need to change).
--
"May the forces of evil become confused on the way to your house."
-- George Carlin

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Florian Apolloner
2006-11-07 19:30:53 UTC
Permalink
Post by James Bennett
Post by Florian Apolloner
1.) In the admin-area you can use filters ( list_filter = ('is_staff',
'is_superuser') ), which show by default all entries. Now I want to
have the entries prefilterd (let's say i have a boolean field, and want
all entries with true filtered out).
Which way is the easiest way to do so?
list_filter should produce a list of links in the sidebar you can
click on to filter according to the values of the field; for example;
using 'is_staff' in list_filter for the auth.User model lets you click
to see either all users who are staff, or all users who aren't.
Yes I see this box, but I (for example) don't won't to see all users
and have to klick on is_staff->yes, I want this to be preselected
(which means I don't want to see all by default) to show only
is_staff->yes, unless I klick no, or all.
Post by James Bennett
Post by Florian Apolloner
2.) Is there a hook or something to execute custom functions, if
someone clicks save in the admin area?
For custom save functionality, your model class can supply a custom
'save' method which executes anything you like; the documentation has
http://www.djangoproject.com/documentation/model_api/#overriding-default-model-methods
Post by Florian Apolloner
2.) Is there a hook or something to execute custom functions, if
someone clicks save in the admin area?
...
#anything you want to do before
model.save(self)
#anything you want to do after
Thanks for the quick answers :)

Florian Apolloner


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
James Bennett
2006-11-07 19:41:35 UTC
Permalink
Post by Florian Apolloner
Yes I see this box, but I (for example) don't won't to see all users
and have to klick on is_staff->yes, I want this to be preselected
(which means I don't want to see all by default) to show only
is_staff->yes, unless I klick no, or all.
If you want to have it always go to that filtered view when you click
from the admin index page, go to the unfiltered list and click to
filter it, and make a note of the URL (which should have some GET
parameters in it which control the filtering). Then you can set up a
custom admin index template (see the 'adminindex' option to
manage.py[1] for details on how to do this easily; it will give you
the full HTML, which you can then edit to have a link to the filtered
-- instead of unfiltered -- view and drop into place to be used as the
main admin page template).

[1] http://www.djangoproject.com/documentation/django_admin/#adminindex-appname-appname
--
"May the forces of evil become confused on the way to your house."
-- George Carlin

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Florian Apolloner
2006-11-07 20:21:03 UTC
Permalink
Post by James Bennett
Post by Florian Apolloner
Yes I see this box, but I (for example) don't won't to see all users
and have to klick on is_staff->yes, I want this to be preselected
(which means I don't want to see all by default) to show only
is_staff->yes, unless I klick no, or all.
If you want to have it always go to that filtered view when you click
from the admin index page, go to the unfiltered list and click to
filter it, and make a note of the URL (which should have some GET
parameters in it which control the filtering). Then you can set up a
custom admin index template (see the 'adminindex' option to
manage.py[1] for details on how to do this easily; it will give you
the full HTML, which you can then edit to have a link to the filtered
-- instead of unfiltered -- view and drop into place to be used as the
main admin page template).
[1] http://www.djangoproject.com/documentation/django_admin/#adminindex-appname-appname
Nice this would solve my problem, although my apps have to be added
static to the admin frontpage :(

Thanks, Florian Apolloner


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

Frankie Robertson
2006-11-07 17:12:37 UTC
Permalink
Post by Florian Apolloner
I have a few questions about django, where I didn't found the answer in
the docu.
1.) In the admin-area you can use filters ( list_filter = ('is_staff',
'is_superuser') ), which show by default all entries. Now I want to
have the entries prefilterd (let's say i have a boolean field, and want
all entries with true filtered out).
Which way is the easiest way to do so?
2.) Is there a hook or something to execute custom functions, if
someone clicks save in the admin area?
If you want to do it whenever a new model is created then you do this:

class foo(model):
...
def save(self):
#anything you want to do before
model.save(self)
#anything you want to do after
Post by Florian Apolloner
3.) Lets assume I have a model with an integerfield position. In the
admin-area I would like to be able to set this field to something, that
would get me two arrows (up and down) to change place with the next
item. Is there a way to do so? (Like a navigation-admin where I want to
get 'Home' from bottom to top, or 'contact' after 'Forum' and not
before it....)
I think you'd have to do quite a bit of hacking to get this into the
admin. Personally I've not found any good documentation on this but if
you read the code you should be able to get a grip on what's going on
and imitate it.
Post by Florian Apolloner
I apologize for my bad English.
Kind regards Florian Apolloner
--
http://grimboy.co.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-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Continue reading on narkive:
Loading...