0

When I include 'caption', I get an error saying EntryAdmin.fieldsets[1][1]['fields']' refers to field 'caption' that is missing from the form

In the admin.py; I have imported the classes from joe.models import Entry,Image

Is that because my class from models.py is not getting imported properly ?

Need help in resolving this issue.

Thanks.

models.py

class Image(models.Model): image = models.ImageField(upload_to='joe') caption = models.CharField(max_length=200) imageSrc = models.URLField(max_length=200) user = models.CharField(max_length=20) class Entry(models.Model): image = models.ForeignKey(Image) mimeType = models.CharField(max_length=20) name = models.CharField(max_length=200) password = models.URLField(max_length=50) 

admin.py

class EntryAdmin(admin.ModelAdmin): fieldsets = [ ('File info', {'fields': ['name','password']}), ('Upload image', {'fields': ['image','caption']})] list_display = ('name', 'mimeType', 'password') admin.site.register(Entry, EntryAdmin) admin.site.register(Image) 
2
  • Caption is a field related to Image and you are trying to add it against Entry. Try image__caption instead Commented Aug 25, 2014 at 16:18
  • I tried that. I did not work. Commented Aug 25, 2014 at 16:26

1 Answer 1

1

You can't edit fields from related models directly in fieldsets.

I suspect you have your foreign key the wrong way round. If you had a FK from Image pointing to Entry, you could use inline admins:

class ImageInlineAdmin(admin.TabularInline): model = Image class EntryAdmin(admin.ModelAdmin): fieldsets = [('File info', {'fields': ['name','password']})] inlines = ImageInlineAdmin list_display = ('name', 'mimeType', 'password') admin.site.register(Entry) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.