This doesn't do anything. I still get the same error. I'd like to be able to access the fields from the Phone and Address model from the MemberAdmin model. I still cannot do this. Any other way?
Eiji On May 7, 7:22 am, Oleg Lomaka <[email protected]> wrote: > Move fields from ModelAdmin to appropriate InlineModelAdmin > > #admin.py > 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 = ('address', 'city', 'state', 'zip') > > class MemberAdmin(admin.ModelAdmin): > inlines = [ PhoneInline, AddressInline ] > fieldsets = ( > (None, { > 'fields': ( 'username', 'first_name', 'middle_name', > 'last_name') > }), > ) > > admin.site.register(Member, MemberAdmin) > > On Sat, May 7, 2011 at 10:44 AM, Eiji Kobayashi <[email protected]>wrote: > > > > > > > > > Hi! > > > I'm having trouble figuring out what to do. > > I have multiple models linked together using foreignkey, like the > > following: > > > # models.py > > class Member(User): > > middle_name = models.CharField(max_length=20) > > > class Phone(models.Model): > > owner = models.ForeignKey(Member) > > areacode = models.CharField(max_length=5) > > number = models.CharField(max_length=12) > > > class Address(models.Model): > > owner = models.ForeignKey(Member) > > address = models.CharField(max_length=50) > > city = models.CharField(max_length=50) > > state = models.CharField(max_length=30) > > zip = models.CharField(max_length=20) > > > I want to be able to create the form that uses all three of the models in > > the admin section, so I did this: > > > # 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 > > > class AddressInline(admin.StackedInline): > > model = Address > > can_delete = True > > extra = 0 > > > class MemberAdmin(admin.ModelAdmin): > > inlines = [ PhoneInline, AddressInline ] > > fieldsets = ( > > (None, { > > 'fields': ( 'first_name', 'middle_name', 'last_name', 'areacode', > > 'number' ) > > }), > > ('Address', { > > 'fields': ( 'address', 'state', 'city', 'state', 'zip' ) > > }) > > ) > > > admin.site.register(Member, MemberAdmin) > > > When I runserver, it throws the following error: > > > ImproperlyConfigured at /admin > > > 'MemberAdmin.fields' refers to field 'areacode' that is missing from the > > form. > > > If I take out 'areacode', 'number' from the None fieldset and remove the > > 'Address' fieldset, leaving only > > > 'first_name', 'middle_name', and 'last_name', it works fine. So, how can I > > access the fields that are linked by foreign key? > > > This is driving me crazy!!! > > > Thanks! > > > Eiji > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

