Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Upcoming changes to the Django admin
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  13 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jacob Kaplan-Moss  
View profile  
 More options Feb 25 2007, 1:51 am
From: "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
Date: Sun, 25 Feb 2007 00:51:56 -0600
Local: Sun, Feb 25 2007 1:51 am
Subject: Upcoming changes to the Django admin
Howdy folks --

After a wonderful Django meetup here at PyCon (Django: the framework
that buys you pizza), a bunch of us spun off into a little ad-hoc
sprint to talk about improvements to the Django admin.

This email summarizes our plan.  It's quite long, mostly because it's
an attempt to distill both where we're going and why we're going
there. It's mostly intended as a record of our plans that we can refer
back to in the future, but it's presented here in case anyone wants to
comment, but note that we've already hashed out a *bunch* of alternate
solutions -- in-person debate works must better than in-ASCII.  Adrian
and I (and the other developers here) are pretty much in agreement
about this stuff, so please try to keep critcism to serious concerns
as opposed to syntax or sugar.

To recap: we've been talking about ways of moving the admin
declaration *out* of the model.  That's never been a semantically
correct place for the declaration (the admin's a view!), and now that
the newforms-admin allows so much more customization, it's going to
get pretty unwieldy.

To start, here's a simple model with an admin declaration as it stands
right now::

    from django.db import models
    from django.contrib.auth.models import User

    class Story(models.Model):
        reporter = models.ForeignKey(User)
        title = models.CharField()
        body = models.TextField()

        class Admin:
            list_display = ["title", "reporter"]
            search_fields = ["title"]

So: first step is to remove the admin from the model.  That means of
course we need another way to indicate that models show up in the
admin.  Here's how::

    from django.db import models
    from django.contrib import admin
    from django.contrib.auth.models import User

    class Story(models.Model):
        reporter = models.ForeignKey(User)
        title = models.CharField()
        body = models.TextField()

    admin.site.register(Story)

Of course, we still want some admin options::

    class Story(models.Model):
        reporter = models.ForeignKey(User)
        title = models.CharField()
        body = models.TextField()

    admin.site.register(Story,
        search_fields = ["title"],
        list_display  = ["title", "reporter"],
    )

OK, but we're still in the model, and one goal is decoupling the admin
from the model.  So, we should instead move the admin declaration into
another file,
``admin.py``::

    from myapp.models import Story
    from django.contrib import admin

    admin.site.register(Story,
        search_fields = ["title"],
        list_display  = ["title", "reporter"],
    )

Note that either option will be supported, but the second option --
putting admin declarations in ``admin.py`` -- will be the recommended
usage. As an added bonus: if you put the admin declaration in a
seperate file and *don't* put ``django.contrib.admin`` in
``INSTALLED_APPS``, the admin code will never get loaded into memory.
Lower memory footprint == GOOD.

Now, one of the coolest parts of the newforms admin work is that you
can easily override methods of the admin class to change the behavior
of the admin.  Let's do that for story.  For example, here's how we
could prevent users from editing any stories except their own (in
``myapp.admin.py``)::

    from django.contrib import admin
    from myapp.models import Story

    class StoryAdmin(admin.ModelAdmin):
        def has_change_permission(self, request, object):
            return request.user == object.reporter

    admin.site.register(Story, StoryAdmin)

(As the branch stands right now it's a little more difficult since
``has_change_permission`` gets ``object_id``, not ``object``, but
Adrian's going to change it for convenience.)

We can also give options to ``StoryAdmin``::

    admin.site.register(Story, StoryAdmin, list_display=["title", "reporter"])

Or give them in the admin class::

    class StoryAdmin(admin.ModelAdmin):

        list_display = ["title", "reporter"]

        def has_change_permission(self, request, object):
            return request.user == object.reporter

So, formally, ``admin.site.register`` can be called in these ways::

    admin.site.register(Model)
    admin.site.register(Model, **options)
    admin.site.register(Model, AdminClass)
    admin.site.register(Model, AdminClass, **options)

    admin.site.register(iterable)
    admin.site.register(iterable, **options)
    admin.site.register(iterable, AdminClass)
    admin.site.register(iterable, AdminClass, **options)

    admin.site.unregister(Model)
    admin.site.unregister(iterable)

(the ``admin.site.register(iterable)`` form lets you easily register
multiple models in one fell swoop.)

The final part of the equation is the ability to define mutliple admin
sites.  ``admin.site`` itself will actually be an instance of an
``AdminSite`` class. Briefly, this will let you create mutliple admin
sites will different behavior (including an admin that's not tied to
the auth system, for example).  Here's how you'd register models in
multiple sites::

    from django.contrib import admin
    from myapp.adminsite import second_admin_site

    admin.site.register(...)
    second_admin_site.register(...)

Where ``myapp.adminsite`` would have, roughly::

    class MyAdminSite(admin.AdminSite):

        def login(self, request):
            ...

        def logout(self, request):
            ...

        def index(self, request):
            ...

        def urls(self, request):
            ...

        def change_password(self, request):
            ...

        def reset_password(self, request):
            ...

    second_admin_site = MyAdminSite()

(This API's a little sketchy, but it'll get filled out).

Finally, the URLconf.  For the default case (a single admin)::

    ('^admin/', include(admin.site.urls()))

And for multiple admins::

    ('^admin/', include(admin.site.urls()))
    ('^admin2/', include(second_admin_site.urls()))

Finally, on a somewhat related note, this refactoring will including
the moving of the admin docs to a seperate contrib app.

Jacob


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kenneth Gonsalves  
View profile  
 More options Feb 25 2007, 3:03 am
From: Kenneth Gonsalves <law...@thenilgiris.com>
Date: Sun, 25 Feb 2007 13:33:53 +0530
Local: Sun, Feb 25 2007 3:03 am
Subject: Re: Upcoming changes to the Django admin

On 25-Feb-07, at 12:21 PM, Jacob Kaplan-Moss wrote:

> Finally, on a somewhat related note, this refactoring will including
> the moving of the admin docs to a seperate contrib app.

cool - cant wait

--

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Tredinnick  
View profile  
 More options Feb 25 2007, 3:36 am
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Sun, 25 Feb 2007 19:36:25 +1100
Local: Sun, Feb 25 2007 3:36 am
Subject: Re: Upcoming changes to the Django admin

I don't completely understand some of this yet, but on the whole it
looks like a good idea.

It feels like it will make a bunch of the internal code a bit easier to
separate, and hence understand and maintain, too. We have a lot of code
that works with admin features under django/db/models/ that often just
complicates reading the code (and makes it harder to find when
debugging).

Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
marcin.kaszynski@gmail.co m  
View profile  
 More options Feb 25 2007, 7:38 am
From: "marcin.kaszyn...@gmail.com" <marcin.kaszyn...@gmail.com>
Date: Sun, 25 Feb 2007 04:38:38 -0800
Local: Sun, Feb 25 2007 7:38 am
Subject: Re: Upcoming changes to the Django admin
Hi,

sounds very good to me.  Among other things, these changes should make
it much easier to implement two use cases that were always said to be
outside of the scope of admin, despite being -- at least in my opinion
-- very useful and common.

1. give some staff members permission to view instances in the admin
list view (and perhaps in a new "admin object_detail") without the
permission to change them.  If I understand it correctly, this is
precisely what has_change_permission will be used for.

2. limit the list of instances a user sees in the admin list view.
Perhaps something like this:

    class StoryAdmin(admin.ModelAdmin):
        [...]
        def get_list_queryset(self, request):
            if request.user.is_superuser:
                return Story.objects.all()
            else:
                return Story.objects.filter(reporter=request.user)

With these two changes admin suddenly gets a lot more useful: I could
use admin in a lot of places that now require writing my own, simpler
admin-like interfaces.

-mk


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
simonbun  
View profile  
 More options Feb 26 2007, 7:16 am
From: "simonbun" <simonce...@gmail.com>
Date: Mon, 26 Feb 2007 12:16:40 -0000
Local: Mon, Feb 26 2007 7:16 am
Subject: Re: Upcoming changes to the Django admin
"Now, one of the coolest parts of the newforms admin work is that you
can easily override methods of the admin class to change the behavior
of the admin."

This feature alone will solve so many of the past problems I've faced
using the admin contrib. When this gets implemented it will truly feel
like one can take full control of the way the admin behaves.

Other than that, separating the admin options from the model
declaration is a welcome improvement as well... I remember it feeling
really wrong when i first started using django.

Now for the inevitable question and probably irritating ;) question:
when are these changes scheduled to be included in the django tin?

In any case, keep up the good work guys!

regards,
Simon

On Feb 25, 7:51 am, "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
patrick k.  
View profile  
 More options Feb 26 2007, 7:21 am
From: "patrick k." <patr...@vonautomatisch.at>
Date: Mon, 26 Feb 2007 13:21:13 +0100
Local: Mon, Feb 26 2007 7:21 am
Subject: Re: Upcoming changes to the Django admin
sounds great.

are there any plans to update/change the html/css-stuff?
e.g., edit_inline is not displayed correctly.

thanks,
patrick

Am 25.02.2007 um 07:51 schrieb Jacob Kaplan-Moss:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nate Straz  
View profile  
 More options Feb 26 2007, 9:31 am
From: Nate Straz <nate-dja...@refried.org>
Date: Mon, 26 Feb 2007 08:31:00 -0600
Subject: Re: Upcoming changes to the Django admin

On Sun, Feb 25, 2007 at 12:51:56AM -0600, Jacob Kaplan-Moss wrote:
> Finally, the URLconf.  For the default case (a single admin)::

>     ('^admin/', include(admin.site.urls()))

> And for multiple admins::

>     ('^admin/', include(admin.site.urls()))
>     ('^admin2/', include(second_admin_site.urls()))

Is there going to be any facility for defining additional admin views
besides the current add, change, and delete?

Nate


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Kaplan-Moss  
View profile  
 More options Feb 26 2007, 12:03 pm
From: "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
Date: Mon, 26 Feb 2007 11:03:31 -0600
Local: Mon, Feb 26 2007 12:03 pm
Subject: Re: Upcoming changes to the Django admin
On 2/26/07, simonbun <simonce...@gmail.com> wrote:

> Now for the inevitable question and probably irritating ;) question:
> when are these changes scheduled to be included in the django tin?

I'm guessing sometime between "tomorrow" and "when Perl 6 ships".

With any luck it'll be closer to the former :)

Jacob


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom  
View profile  
 More options Mar 1 2007, 8:11 pm
From: "Tom" <th.freudenb...@googlemail.com>
Date: Fri, 02 Mar 2007 01:11:38 -0000
Local: Thurs, Mar 1 2007 8:11 pm
Subject: Re: Upcoming changes to the Django admin
Hi it seemed to be a good change to give the admin its own space. Btw
what about the field specific items like

edit_inline, max_num_in_admin, ...

an so on. Have you made any decision where this should be set in
future or if this will be left in the model?

Tom


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Kaplan-Moss  
View profile  
 More options Mar 2 2007, 12:28 pm
From: "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
Date: Fri, 2 Mar 2007 11:28:03 -0600
Local: Fri, Mar 2 2007 12:28 pm
Subject: Re: Upcoming changes to the Django admin
On 3/1/07, Tom <th.freudenb...@googlemail.com> wrote:

> Hi it seemed to be a good change to give the admin its own space. Btw
> what about the field specific items like

> edit_inline, max_num_in_admin, ...

> an so on. Have you made any decision where this should be set in
> future or if this will be left in the model?

Edit-inline is also going to be moved out into the admin declaration,
and all the num_in_admin stuff just going to go away (to be replaced
with an interface that doesn't rely on that crutch).

We haven't fully worked out the new syntax for edit-inline, but it'll
be pretty similar in "spirit" to what we've already worked out.

Jacob


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ivan Sagalaev  
View profile  
 More options Mar 3 2007, 1:40 pm
From: Ivan Sagalaev <Man...@SoftwareManiacs.Org>
Date: Sat, 03 Mar 2007 21:40:48 +0300
Local: Sat, Mar 3 2007 1:40 pm
Subject: Re: Upcoming changes to the Django admin

Jacob Kaplan-Moss wrote:
> Edit-inline is also going to be moved out into the admin declaration,

Edit-inline was also useful outside of the admin, in manipulators. Are
there any plans to have newforms handling this or this will become a
purely admin functionality?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joseph Kocherhans  
View profile  
 More options Mar 3 2007, 1:54 pm
From: "Joseph Kocherhans" <jkocherh...@gmail.com>
Date: Sat, 3 Mar 2007 12:54:40 -0600
Local: Sat, Mar 3 2007 1:54 pm
Subject: Re: Upcoming changes to the Django admin
On 3/3/07, Ivan Sagalaev <Man...@softwaremaniacs.org> wrote:

> Jacob Kaplan-Moss wrote:
> > Edit-inline is also going to be moved out into the admin declaration,

> Edit-inline was also useful outside of the admin, in manipulators. Are
> there any plans to have newforms handling this or this will become a
> purely admin functionality?

I'm working on it at the moment and barring any objections from
Adrian, yes, something similar to edit-inline will be available
outside of the admin.

Joseph


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nicolas E. Lara G.  
View profile  
 More options Mar 15 2007, 8:00 pm
From: "Nicolas E. Lara G." <nicolasl...@gmail.com>
Date: Fri, 16 Mar 2007 00:00:24 -0000
Local: Thurs, Mar 15 2007 8:00 pm
Subject: Re: Upcoming changes to the Django admin
Hello,
I'm planning on submitting a google summer of code project related to
the admin for rich media support that includes integrating filebrowser
and tinyMCE, deleting multiple items at once, friendly large files
support, etc. As the admin is being re-designed/written right now I
was wondering if working on this redesign was acceptable and if it was
going to be backward compatible (So I can work on the new-admin branch
without problems).

Nicolas

On Feb 25, 2:51 am, "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »