That's a great solution. Much better than messing around with the metaclass :)
On Jun 27, 5:47 am, Lee Hinde <leehi...@gmail.com> wrote: > On Fri, Jun 25, 2010 at 2:54 PM, patjenk <patj...@gmail.com> wrote: > > In our application, we have a Model that has a boolean field named > > "deleted". When the delete() method is called, we set the deleted > > field to 1 and then save the model. We would like to create an admin > > site where we can manage the deleted and non deleted instances > > separately. > > > We could accomplish our goal by defining a queryset function for the > > ModelAdmin that restricts the instances returned to deleted=0. > > However, AFAIK this would eliminate the ability to undelete instances > > via the admin. Another option is to allow all instances to be shown > > and include delete as a value in the list_filter list for the admin > > but that clutters up our UI and requires an extra click. It would be > > nice if we could specify that the default admin view for this model > > has a list_filter of deleted=0 but I don't think this is currently > > possible. > > > I think a good solution would be to create two ModelAdmins. One to > > display active instances and one to display deleted instances. With > > this approach we could define a queryset function for each ModelAdmin > > and when an instance is deleted it would automatically move to the > > correct ModelAdmin. This is explicitly denied in django/contrib/admin/ > > sites.py. Simply removing this check does not solve our problem but > > overwrites the first ModelAdmin for the model with the second via the > > dictionary "_registered" in the AdminSite class. From my brief dive > > into the admin site, there doesn't appear to be a real need for a one > > to one relationship between ModelAdmins and Models. If you allowed > > ModelAdmins to specify their own name I think it would be possible to > > have more than one ModelAdmin for a Model. I am not a Django expert > > but I don't see a reason that this scenario should be excluded. > > > Can anyone recommend a way to accomplish either of the approaches I > > outlined above or propose a new approach that does not violate the > > AdminSite rules? Also, if anyone knows why the ModelAdmin needs to > > have a one to one relationship with Model please let me know. > > I recently clipped this for future reference. I believe it will help > you do what you want: > > http://www.mahner.org/posts/separating-staff-and-user-accounts-in-dja... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.