Would it be worthwhile to add a way to purge unused content types via
manage.py? It could look at INSTALLED_APPS and anything not installed
it removes?
-Rob
Wouldn't reset do that?
./manage.py reset auth contenttypes
--
Collin Grady
"Die? I should say not, dear fellow. No Barrymore would allow such a
conventional thing to happen to him."
-- John Barrymore's dying words
I haven't tried that but that looks like it would clear those tables
completely vs. purging only the unused tables.
Would following that with a syncdb then restore the content types for
the installed apps? I'll have to test that later.
-Rob
Even if it did the id's might have changed and any generic relations be
broken.
Greetings, David Danier
Shouldn't really be an issue with his scenario though, since he said
this was during initial dev on the data model, so he wouldn't even have
much (if any) data yet :)
--
Collin Grady
Perhaps no person can be a poet, or even enjoy poetry without a certain
unsoundness of mind.
-- Thomas Macaulay
Why not, rather than adding another option in django.core.management,
have the contenttypes app do this? The existing post_syncdb hook
could be extended to clear unused content types as well as create new
ones.
You would have to remember to run syncdb after a reset though, but
this would be better than reseting all content types or adding another
option IMHO.
Cheers,
deryck
--
Deryck Hodge
Lead Developer, Product Development
Washington Post.Newsweek Interactive
Right, but when it comes time for the next app I create in that
project, I'd want the same thing.
-Rob
After reading the code in django.contrib.contenttypes.management it
does seem the natural place. And it makes sense to me that content
types would tidy up after itself if it noticed orphaned content types.
Is this a common problem for people or just me? I don't run into it
with every app, but I do refactor my models often times and run into
this, and think it would be nice if there were a more automated way to
clean up those tables.
-Rob
I've bumped into this same problem several times. It would be nice
that contenttypes-app would know how to clean up itself from time to
time.
- VS
+1 to the idea - as noted elsewhere in the thread, this would be
handled best as an improvement to the management.py handler for the
contenttypes app.
I look forward to seeing your patch! :-)
Yours,
Russ Magee %-)
First attempt is in this ticket...
http://code.djangoproject.com/ticket/5177
I do need to test a bit further on a real project and with users who
have permissions to see how it all manages itself. Tonight I just
tested that the content types were being added and removed
successfully (and permissions were magically being handled correctly
in auth_permissions).
I'll quote the ticket since I'm not sure where this really belongs...
The first patch works but I haven't tested fully. I had assumed I
would also have to figure out how to manage the various permissions
tables but it seems to be taking care of itself. I looked to see if
the delete() on the ContentType object had some trickery to update the
permissions but didn't find anything.
This doesn't remove the orphaned model tables themselves either, which
is probably good... the idea for this patch was to avoid having to
delete rows in the contenttype and various permissions tables,
dropping a table is easy enough.
Cheers!
-Rob
I have started a tread in django-users a long time ago:
http://groups.google.com/group/django-users/browse_thread/thread/4f74fc5a98f7c8fe/
Here a old ugly code for removing unused conrenttypes:
http://paste.pocoo.org/show/1482/
Mfg. Jens Diemer