Wednesday, May 3, 2017

Re: How can I access obj in admin.py


On Wed, May 3, 2017 at 12:33 AM, Mike Dewhirst <miked@dewhirst.com.au> wrote:
I want to adjust inlines based on a property of the object.

class SubstanceAdmin(admin.ModelAdmin):

    class SolidInline(admin.StackedInline):
        pass
    class LiquidInline(admin.StackedInline):
        pass
    class GasInline(admin.StackedInline):
        pass

    inlines = get_inlines

    def get_inlines(self):
        obj = how_do_I_get_this(?)
        if obj.physical_state = None:
            return ((SolidInline), (LiquidInline), (GasInline))
        elif obj.physical_state = 1:
            return ((SolidInline), )
        elif obj.physical_state = 2:
            return ((LiquidInline), )
        elif obj.physical_state = 3:
            return ((GasInline), )

Many thanks for a miracle :)

Mike

--
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/a138bd6c-46fb-98c7-ba28-69a5959e5fbc%40dewhirst.com.au.
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+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/CAD4ANxWWNxfDSCGUm8GFR_ijGL2WZAC%2Bwz3NCwpA%3DyHyALfWZQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment