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

2015-08-23 Thread Michael
I'd like to get the model instance of the Parent admin.



On Sunday, August 23, 2015 at 10:58:46 AM UTC-5, Gergely Polonkai wrote:
>
> Whose parent do you want to get? The inline, the model, or, less likely, 
> the form?
> On 23 Aug 2015 16:48, "Michael"  
> wrote:
>
>> 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...@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.
>>
>

-- 
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/bc0cf162-7ab6-415b-b711-89e79abbcc80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2015-08-23 Thread Gergely Polonkai
Whose parent do you want to get? The inline, the model, or, less likely,
the form?
On 23 Aug 2015 16:48, "Michael"  wrote:

> 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.
>

-- 
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/CACczBUJh8p9%2B0fvErxkm7nKNDHBD%2B4AO-6gGLuYZb0xy2xNurw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.