Hi Oleg,
Thanks for your patience. I'm pretty sure I DID miss something like
you said. Here's my admin.py, with the modifications you suggested:
# admin.py
from django.contrib import admin
from django.contrib.auth.models import User
from models import Member, Address, Phone
class PhoneInline(admin.StackedInline):
model = Phone
can_delete = True
extra = 0
fields = ( 'areacode', 'number')
class AddressInline(admin.StackedInline):
model = Address
can_delete = True
extra = 0
fields = ( 'addresstype', 'address', 'city', 'state', 'postal_code')
class MemberAdmin(admin.ModelAdmin):
inlines = [ PhoneInline, AddressInline ]
fieldsets = (
(None, {
'fields': ( 'first_name', 'middle_name', 'last_name',
'areacode', 'number' )
})
)
admin.site.register(Member, MemberAdmin)
The actual error I get is:
ImproperlyConfigured at /admin/
'MemberAdmin.fieldsets[0][1]['fields']' refers to field 'areacode'
that is missing from the form.
When I add the all_phones function in the models.py and define the
list_display like you suggested, I get this error:
TemplateSyntaxError at /admin/account/member/
Caught OperationalError while rendering: (1054, "Unknown column
'account_phone.areacode' in 'field list'")
There must be a simpler way to just edit the primary model and its
related models in the admin, no?
Thanks!
Eiji
On May 7, 8:32 pm, Oleg Lomaka <
oleg.lom...@gmail.com> wrote:
> If you get the same error, the you have missed something. Show me your
> current admin.py once more.
>
> As to "I'd like to be able to access the fields from the Phone and
> Address model from the MemberAdmin model". You can access fields from Phone
> and Address from the InlineAdminModel. That is in case you want to access
> them on change/add view. As shown in my previous example.
>
> And if you want to access those fields from list view, then you can create a
> function in your Member model to format phone fields into string and include
> it in a list_display. Example
>
> # models.py
> class Member(User):
> middle_name = models.CharField(max_length=20)
>
> def all_phones(self):
> return ", ".join(["(%s) %s" % (p.areacode, p.number) for p in
> self.phone_set.all()])
>
> # admin.py
> class MemberAdmin(admin.ModelAdmin):
> list_display = ('first_name', 'middle_name', 'last_name', 'all_phones')
>