﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28831	Document that InlineModelAdmin methods' obj argument is the parent object.	Artem Skoretskiy	Parth Patil	"When I use `ModelAdmin.get_fieldsets`, I receive current object. In my example that would be -- when I call `AccountAdmin.get_fieldsets` -- I receive `Account`. That enable me to generate different field sets for different cases.

BUT when I use `InlineModelAdmin.get_fieldsets`, I receive parent object. In my example that would be -- when I call 
`AccountInline.get_fieldsets` -- I receive `Customer` object instead of `Account. That prevents me from configuring formsets to the account I have.

If I received `Account`, I could extract `Customer` from it. But if I receive `Customer`, I cannot adapt form for each row. 

Also, it seems strange that class explicitly linked to `Account` receives `Customer` object as input.

Code:

{{{
# in models.py

class Customer(models.Model):
    num = models.IntegerField()


class Account(models.Model):
    ACCOUNT_TYPES = (
        (1, 'A'),
        (2, 'B'),
    )
    customer = models.ForeignKey(Customer)
    account_type = models.IntegerField(choices=ACCOUNT_TYPES)

    a = models.CharField(max_length=255, blank=True) # should be edited when type = ""A""
    b = models.CharField(max_length=255, blank=True) # should be edited when type = ""B""

# in admin.py

class AccountInline(admin.TabularInline):
    model = models.Account

    def get_fieldsets(self, request, obj=None):
        print(repr(obj)) # => <Customer>
        """"""
        if obj and obj.account_type == 1:
            return ((None, {'fields': ('account_type', 'a')}),)
        elif obj and obj.account_type == 2:
            return ((None, {'fields': ('account_type', 'b')}),)
        """"""
        return ((None, {'fields': ('account_type',)}),)

@admin.register(models.Customer)
class CustomerAdmin(admin.ModelAdmin):
    inlines = (AccountInline,)

@admin.register(models.Account)
class AccountAdmin(admin.ModelAdmin):
    def get_fieldsets(self, request, obj=None):
        print(repr(obj)) # => <Account>
        if obj and obj.account_type == 1:
            return ((None, {'fields': ('account_type', 'a')}),)
        elif obj and obj.account_type == 2:
            return ((None, {'fields': ('account_type', 'b')}),)
        return ((None, {'fields': ('account_type',)}),)

}}}"	Cleanup/optimization	closed	Documentation	dev	Normal	fixed		tonn81@… Manel Clos	Accepted	1	0	0	0	0	0
