Hi,

I have two models, ReleaseImageGallery and ReleaseImage as follows:

class ReleaseImageGallery(BaseImageGallery):
release = models.ForeignKey(Release, on_delete=models.CASCADE)

class Meta:
verbose_name = "release image gallery"
verbose_name_plural = "release image galleries"

and

class ReleaseImage(BaseImage):
release_image_gallery = models.ForeignKey(ReleaseImageGallery,
on_delete=models.CASCADE)
image = models.ImageField(upload_to='release-images/', blank=True, null=True
)
class Meta:
verbose_name = "release image"
verbose_name_plural = "release images"



My admin.py file is as follows:
from django.contrib import admin

from .models import ReleaseImageGallery, ReleaseImage


class ReleaseImageInline(admin.StackedInline):
model = ReleaseImage
extra = 1

class ReleaseImageGalleryAdmin(admin.ModelAdmin):
inlines = [ReleaseImageInline]
list_filter = ['date_created', 'date_modified']
search_fields = ['title']


admin.site.register(ReleaseImageGallery, ReleaseImageGalleryAdmin)

When I run the project and log into the admin site, all works fine.

While creating a new ReleaseImageGallery, I try to add a new Release object
(FK relationship) via a select list, an error is raised in the add_view as
follows:

[image: add-release-fk-object.png]

```
Environment:


Request Method: GET
Request URL:
http://127.0.0.1:8000/admin/releases/release/add/?_to_field=id&_popup=1

Django Version: 3.2.5
Python Version: 3.9.6
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'tinymce',
 'nested_inline',
 'coresite.apps.CoreSiteConfig',
 'customadminoptions.apps.CustomAdminOptionsConfig',
 'baseimagegalleries.apps.BaseImageGalleriesConfig',
 'baseusers.apps.UsersConfig',
 'userprofiles.apps.UserProfilesConfig',
 'artists.apps.ArtistsConfig',
 'artistimagegalleries.apps.ArtistImageGalleriesConfig',
 'bands.apps.BandsConfig',
 'labels.apps.LabelsConfig',
 'releaseimagegalleries.apps.ReleaseImageGalleriesConfig',
 'releases.apps.ReleasesConfig']
Installed Middleware:
('whitenoise.middleware.WhiteNoiseMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')



Traceback (most recent call last):
  File
"/Users/sd/Library/Caches/pypoetry/virtualenvs/afridisc-sWjK8x-o-py3.9/lib/python3.9/site-packages/django/db/models/options.py",
line 608, in get_field
    return self.fields_map[field_name]

During handling of the above exception ('_to_field'), another exception
occurred:
  File
"/Users/sd/Library/Caches/pypoetry/virtualenvs/afridisc-sWjK8x-o-py3.9/lib/python3.9/site-packages/nested_inline/admin.py",
line 217, in add_view
    f = opts.get_field(k)
  File
"/Users/sd/Library/Caches/pypoetry/virtualenvs/afridisc-sWjK8x-o-py3.9/lib/python3.9/site-packages/django/db/models/options.py",
line 610, in get_field
    raise FieldDoesNotExist("%s has no field named '%s'" %
(self.object_name, field_name))

During handling of the above exception (Release has no field named
'_to_field'), another exception occurred:
  File
"/Users/sd/Library/Caches/pypoetry/virtualenvs/afridisc-sWjK8x-o-py3.9/lib/python3.9/site-packages/django/core/handlers/exception.py",
line 47, in inner
    response = get_response(request)
  File
"/Users/sd/Library/Caches/pypoetry/virtualenvs/afridisc-sWjK8x-o-py3.9/lib/python3.9/site-packages/django/core/handlers/base.py",
line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File
"/Users/sd/Library/Caches/pypoetry/virtualenvs/afridisc-sWjK8x-o-py3.9/lib/python3.9/site-packages/django/contrib/admin/options.py",
line 616, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File
"/Users/sd/Library/Caches/pypoetry/virtualenvs/afridisc-sWjK8x-o-py3.9/lib/python3.9/site-packages/django/utils/decorators.py",
line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File
"/Users/sd/Library/Caches/pypoetry/virtualenvs/afridisc-sWjK8x-o-py3.9/lib/python3.9/site-packages/django/views/decorators/cache.py",
line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File
"/Users/sd/Library/Caches/pypoetry/virtualenvs/afridisc-sWjK8x-o-py3.9/lib/python3.9/site-packages/django/contrib/admin/sites.py",
line 232, in inner
    return view(request, *args, **kwargs)
  File
"/Users/sd/Library/Caches/pypoetry/virtualenvs/afridisc-sWjK8x-o-py3.9/lib/python3.9/site-packages/django/utils/decorators.py",
line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File
"/Users/sd/Library/Caches/pypoetry/virtualenvs/afridisc-sWjK8x-o-py3.9/lib/python3.9/site-packages/django/utils/decorators.py",
line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File 
"/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py",
line 79, in inner
    return func(*args, **kwds)
  File
"/Users/sd/Library/Caches/pypoetry/virtualenvs/afridisc-sWjK8x-o-py3.9/lib/python3.9/site-packages/nested_inline/admin.py",
line 218, in add_view
    except models.FieldDoesNotExist:

Exception Type: AttributeError at /admin/releases/release/add/
Exception Value: module 'django.db.models' has no attribute
'FieldDoesNotExist'
```

I have checked the class definitions and do not understand the breakage.
What am I missing?

TIA.


Regards,
~ Lloyd

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAH-SnCA62L9f4uzc2B%2BMvRNMaPnD_iDis0ED3xfeZsVWnUs2bA%40mail.gmail.com.

Reply via email to