0

I have a django model, NewsItem, which has several fields, including date, text, and foreign key fields. One foreign key field is:

editor = models.ForeignKey(User, verbose_name="Editor", related_name='editors', 
                           limit_choices_to=_editors)

For some reason, the foreign key fields do not show up in the "add an item" form in the django admin interface (at http://[hostname]/admin/[app name]/newsitem/add/. However, all the other fields do. I can't save any items because editor is a required field.

I have checked to make sure that there is a user satisfying the constraint:

>>> User.objects.filter(groups__name__iexact='editors')
[<User: testeditor>]

I can't find any reason that these fields wouldn't show up in the admin. Do I need to specify a widget for them in the NewsItemAdmin class? Do I need to tell the admin to display them? If so, how?

Jakob Weisblat
  • 7,450
  • 9
  • 37
  • 65
  • 1
    lets see your code for _editors. perhaps it isn't return anything. or look at this question for some other ways to do it: http://stackoverflow.com/questions/232435/how-do-i-restrict-foreign-keys-choices-to-related-objects-only-in-django – warath-coder Jan 07 '15 at 01:03
  • Oops it's the code i run in the second block. It returns one object. – Jakob Weisblat Jan 07 '15 at 01:04
  • Post your admin.py, _editors. Start taking pieces away to debug. Remove `limit_choices_to`: what happens? If the form appears, we now know it has something to do with limiting choices. Though I'd expect an empty select, not a field being gone entirely. Remove pieces from ModelAdmin (don't even use `ModelAdmin`.. just straight register `admin.site.register(MyModel)` -- see what happens. If it doesn't appear without any `ModelAdmin` customization, it means it's something to do with the field definition itself.. and so on. – Yuji 'Tomita' Tomita Jan 07 '15 at 02:08

1 Answers1

0

You should make sure the user you're creating this with has permission to change the editor. [facepalm]

Jakob Weisblat
  • 7,450
  • 9
  • 37
  • 65