Old (current) admin URLs look like this:
/admin/blog/entries/add/
Where the "blog" is the name of the model module and "entries" is the
name of the magic module created for Entry. (Whew! Hard to explain.
Aren't you glad we're changing this?)
But in magic-removal, module_name ("entries") goes away. Plus, models
are no longer imported from "django.models.", which means they can
live anywhere (e.g. from myproject.blog.models import Entry).
With that in mind, what's the best way to specify admin URLs from now on?
One solution would be to do this:
/admin/myproject.blog.models.entry/add/
Or substitute slashes for dots:
/admin/myproject/blog/models/entry/add/
Or maybe get rid of the "models" cruft:
/admin/myproject/blog/entry/add/
The problem with "/admin/myproject.blog.models.entry/", though, is I'm
not sure it's possible to get the Python path *to* an object. For
example, given a model Entry, how do we get the string
"myproject.blog.models.entry"? A model needs to know how to calculate
its admin URL. And it's a bit of a security risk, if whatever's in the
URL is directly imported. We couldn't stop somebody from going to
/admin/path.to.nasty.module/ -- if an attacker has access to putting
objects on the Python path somehow, he could run arbitrary code.
Another solution could be "/admin/blog/entry/", where "blog" is the
app name (blog/models.py) and "entry" is a lowercased version of the
model class name. The disadvantage of this is (obviously) the app
namespace is only one-level deep. Granted, these disadvantages have
been present in the old system and haven't bitten us.
Thoughts?
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org
> /admin/myproject/blog/entry/add/
+1, most readable, most compact, most guessable.
> The problem with "/admin/myproject.blog.models.entry/", though, is I'm
> not sure it's possible to get the Python path *to* an object. For
> example, given a model Entry, how do we get the string
> "myproject.blog.models.entry"?
obj.__module__ + "." + obj.__class__.__name__
> Another solution could be "/admin/blog/entry/", where "blog" is the
> app name (blog/models.py) and "entry" is a lowercased version of the
> model class name. The disadvantage of this is (obviously) the app
> namespace is only one-level deep. Granted, these disadvantages have
> been present in the old system and haven't bitten us.
As Django matures and more apps arrive, namespace clashes are going
to becoming more likely, I think it's important to build namespace
scope in now. I fully support making everything namespaced to the
project and the app.
________________________________
Afternoon, man about the Internet -- http://aftnn.org/
ie
/forum/ calls my view
/forum/add would call the admin add view with myproject.model.forum as
a parmeter
and so on.
but to answer your specific question I would like to see
/admin/<application>/<model>/add
where application is the 'short' version.. ie 'forum' would be short
for zilbo.apps.forum
and that shorthand could live in the content-type table perhaps?
--
I...@Holsman.net -- blog: http://feh.holsman.net/ -- PH: ++61-3-9877-0909
If everything seems under control, you're not going fast enough. -
Mario Andretti
my other concern with putting the python path into the URL is would it
allow nasty thing
like
admin/init.me.and.i.format.your.hard_disk/
?
and other weird easter eggs which a unsuspecting admin doesn't realize
is on his machine?
Clearly we would want to avoid that. Before importing, it could check
that the module is in INSTALLED_APPS.
> Clearly we would want to avoid that. Before importing, it could check
> that the module is in INSTALLED_APPS.
By going with /admin/project/app/model/add/ stick with more normal
looking urls, you can do the checking at quite a fine-grained level,
plus you get a few nice things such as the ability to add pages at
intermediate points. You could stick a handy status page at /admin/
project/ for example. /admin/project/app/ would look like the current
admin home page, but with only models defined in the specified app.
Useful for bigger sites, actual admins go to /admin/ and can control
a bunch of stuff. Lesser admins, e.g. content editors, could just be
pointed at /admin/mycmsproject/cms/.
+1 for being the most readable and less cumbersome.
--
Jeroen Ruigrok van der Werven
I don't really get this - the module would not be imported by this. The
lookup would trigger the normal model loading. Then the path to it would
be resolved against the loaded models, and that resolution could only
result in a valid, loaded model class.
> Another solution could be "/admin/blog/entry/", where "blog" is the
> app name (blog/models.py) and "entry" is a lowercased version of the
> model class name. The disadvantage of this is (obviously) the app
> namespace is only one-level deep. Granted, these disadvantages have
> been present in the old system and haven't bitten us.
Also, the model namespace is only one deep, eg if you had a nested set
of model modules in your app, they would be flattened. Granted, it would
probably be pretty stupid to have conflicting class names in one app
anyway...
I think I'll try to do this last one for now as it is closest to the old
system and we can always change it later if we reach a consensus. Also,
it is the easiest to understand for the template overriding stuff in the
admin imo.
This one's my favorite.
Double points if /admin/myproject/ shows a list of models under
myproject (and /myproject/blog/ shows all the ones under
myproject.blog); triple points if there's a quick and easy way to
provide my own custom template and/or view for any of those levels.
Jacob
Also, it elides the 'models' package, which would I think be kind of odd
with a full blown object traversal thing. And this really is just for
one (important) application, so I doubt at this point we need that level
of sophistication/flexibility.
Just thought I'd mention them as references that might be applicable --
even if they're too much for this specific case, they may have some
ideas... at the moment I'm not up to speed on Django internal
admin-magic to cite anything specific I'm afraid.
>Or substitute slashes for dots:
>
> /admin/myproject/blog/models/entry/add/
I like this better. Slashes are better than dots.
Thanks,
Eugene
+1
--
"May the forces of evil become confused on the way to your house."
-- George Carlin
-rob
I figure you could pretty simply use a reserved property or method in
the module or class, something like __adminurl__.
-rob