Monday, October 31, 2016

Updating mixin subclassed instances

Hi,

I am using my custom permission mixin on several of my apps's models (not all).

For the case when I need to merge from the "old - context" permission to the "new - context" permission I want to have function which changes the corresponding permission reference attribute in all models, which subclassed this mixin.

How do I know which models subclassed this permission mixin and that they have the inherited permission reference attribute?

In fact I want to have such function in my mixin:

@classmethod
def merge_to(cls, from_perm_context, to_perm_context):

    perm_context_models = []  # How to get this?

    try:
        with transaction.atomic():
            for model in perm_context_models:
                model.objects.filter(
                    perm_context=from_perm_context,
                ).update(perm_context=to_perm_context)
    except IntegrityError as e:  # or DatabaseError
        raise e



Thanks, 

Radek

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/576474f7-dace-4986-b121-0eb2e5428122%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment