These first two options are really a duplicate of ticket #7539; it
isn't something that should be handled at the admin level, but at the
model level. The broad ideas behind #7539 are well established; the
patch just needs to be carried the last few steps to trunk.
> 3. replace all the related objects with an other model instance (we
> can make a user choose it with a forms.ModelChoiceField?)
> i really would like to contribute to this feature, because i need to
> do this in my admin site, but i'm new, so please help me :)
This is an interesting idea. At a raw technical level, introducing a
'pre-deletion cleanup' stage for admin deletions shouldn't be too
difficult -- the current deletion confirmation view provides a
convenient place in the workflow that could be replaced with a view
that provides options to nominate how relations should be cleaned up.
However, my concern is whether this could be made a generic
capability. If this is to become a configurable capability of the
admin interface, it needs to work with every possible model, not just
a subset of models. It isn't immediately obvious to me how you could
specify a relation substitution scheme in a completely generic way.
There's also the issue of how to handle this sort of substitution on a
bulk delete - if you're deleting a group of 50 objects using an admin
bulk action or as a result of a cascaded deletion, you don't want to
be presented with an auto-generated dialog of 50 pulldown/raw_id_admin
widgets.
I suspect the best course of action for trunk will be to make it
*possible* to easily introduce a pre-deletion stage, but not actually
provide that capability as part of core admin functionality (i.e.,
cleanup and document the mechanism by which you can define a
pre-delete view, but not actually provide a "cleanup= ('field',
'field')" definition on ModelAdmin that automatically turns into a
pre-configured deletion view.
Yours,
Russ Magee %-)
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-d...@googlegroups.com.
To unsubscribe from this group, send email to django-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
This much was already clear. My concern is about the edge cases.
Lets say we have an Author model that we are deleting. You're giving
the use case of deleting an author, and modifying all the Blog posts
that reference that author so that they point somewhere else. I have
no problems with the concept or implementation of this as you describe
it.
But:
* What if you have multiple models referring to Author? Do you assume
that every related model will be updated the same way?
* What if you have multiple foreign keys from Blog to Author? Do you
assume that every foreign key on a single model will be updated in the
same way?
* What if there is a model with a m2m relation to Author? Do you
delete the m2m relation, or do you replace it with the substituted
object?
* What if you use admin actions to delete N authors? Do we assume
that every one of the authors will be replaced with the same single
substitute?
These sorts of decisions are all business logic decisions. You may
have a good answer for your site, but I'm not convinced that there is
a universal answer that will always be correct for all users, and I'm
not convinced that it would be possible to define an easily
configurable interface to expose all possible interpretations of this
feature.
This is why I'm suggesting that the best approach here is to make it
*possible*, but not to bake this capability into Django itself. If we
provide the appropriate hooks, you (as an end user) should be able to
add whatever implementation of this feature you want.
If there are hooks on Django's admin that need to be added or
modified, then I'm happy to entertain those changes.
Yours,
Russ Magee %-)
I understand this. What you seem to be missing is that in the general
case, there isn't a single, canonical answer that will *always* be
correct.
If you are deleting 1 object, there are O(N*M) objects that need to be
updated, where N is the number of models X that have a relation to the
object being deleted, and M is the number of instances of X that have
a relation to the object being deleted.
As an example: I have an Author, Article and Address record. Article
and Address both have a FK on Author. If I delete Author "John", I
need to do something to any Article and Address record that points at
John. In my business logic, I want to update all Articles to point at
a dummy author, but I want to cascade delete all the Address records.
To complicate issues some more - lets say I want some Article records
to point at a dummy author, and some to point at a new author that is
going to take responsibility. I need to be able to select which
authors will be applied to which articles. There might even be a
programatic scheme that I can use to semi-automate this reassignment
(or automate the initial values prior to a formal confirmation by the
site admin).
Next complication -- if you're doing a bulk delete of P objects (using
an admin delete action), all the decisions that had to be done N*M
times now need to be done P*N*M times.
On top of all this, there are cascading problems. For example, lets
say Authors can belong to Teams. If I delete a team, I know I want to
cascade delete all the Authors that belong to that team. But the
Articles associated with members of those teams need to be reassigned.
Then consider the bulk deletion of teams, and so on.
The point I'm trying to make is that there is no single answer that we
can implement that will be right for all business cases. So the best
we can do is to make it *possible* to introduce pre-deletion cleanup
logic, make that interface as clean as we can, and leave it up to the
end user to implement a scheme that is appropriate for their
implementation. These are the 'hooks' that I'm referring to.
Once those hooks are in place, the simple "confirm you want to replace
all instances of X with Y" approach that you're proposing should be a
couple of lines of code, which will probably form the simple example
provided in documentation. However, it will be possible for other
users to implement more complex schemes, as appropriate.
> thanks Russ, but how to involve more people in this discussion, and
> take the discussion to a next step?
A prototype implementation would be a good start. I've been raising
design issues looking entirely from a public API perspective. I
haven't done any exploration of how this would be implemented, so I
have no idea what technical hurdles (if any) exist.
Yours,
Russ Magee %-)
I'm starting to feel like I'm repeating myself.
This isn't something that can be described as a general rule. It
requires an understanding of business logic.
Therefore, it makes no sense to implement this as a builtin feature of
admin that is available as a simple exposed setting. The best we can
hope to do is to implement a hook.
> how can i do such a prototype? i mean, how i propose to django
> comunity such a prototype?
The way this works is that you write the patch, and then we consider
it for inclusion in trunk. I've given you as much guidance as I can on
the sort of approach that will be accepted into core. It's up to you
to follow up on that guidance.
Yours,
Russ Magee %-)