How can I access the parent instance from the inline model admin?

My goal is to allow to add a child object only when the status of the 
parent is equal to 1 so I'm trying to override the `has_add_permission` 
function based on the status of the parent instance but I cannot get the 
parent instance. 
Is there another way to do this?


    class ChildInline(admin.TabularInline):
        model = Child
        form = ChildForm
    
        fields = (
            ...
        )
        extra = 0
    
        def has_add_permission(self, request):
            # Return True only if the parent has status == 1
            # How to get to the parent instance?
            #return True
    
    class ParentAdmin(admin.ModelAdmin):
        inlines = [ChildInline,]





-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6690f995-8978-4a95-84af-1e7a1b211727%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to