how to access the parent instance from the Inline model admin?

215 views
Skip to first unread message

Michael

unread,
Aug 23, 2015, 10:48:49 AM8/23/15
to Django users
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,]





Gergely Polonkai

unread,
Aug 23, 2015, 11:58:46 AM8/23/15
to Django users

Whose parent do you want to get? The inline, the model, or, less likely, the form?

--
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...@googlegroups.com.
To post to this group, send email to django...@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.

Michael

unread,
Aug 23, 2015, 12:18:59 PM8/23/15
to Django users
I'd like to get the model instance of the Parent admin.
Reply all
Reply to author
Forward
0 new messages