- Author:
- writefaruq
- Posted:
- June 23, 2011
- Language:
- Python
- Version:
- 1.3
- Score:
- 0 (after 0 ratings)
In case when you need a list of related objects for particular queryset
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | """ Find deletable of objects"""
from django.conf import settings
from django.db.utils import ConnectionRouter
from django.contrib.admin.util import get_deleted_objects
from django.contrib.auth.models import User
from django.contrib.admin import AdminSite
def find_deletable_objects(queryset):
""" Get a full list of deletable objects. """
router = ConnectionRouter(settings.DATABASE_ROUTERS)
modeladmin = AccountAdmin
modeladmin.model = Account
modeladmin.admin_site = AdminSite()
using = router.db_for_write(modeladmin.model)
opts = modeladmin.model._meta
user = User.objects.get_or_create(id=1) # superuser
deletable_objects, perms_needed, protected = get_deleted_objects(
queryset, opts, user, modeladmin.admin_site, using)
from pprint import pprint
pprint(deletable_objects)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.