2

I have problems with extending Django's filer, probably because my knowledge of Django is not sufficient yet.

Basically, what I would like to achieve is to extend Django filer image model to be able to add a category to images. Could someone help me with this topic?

Code example is from:
http://django-filer.readthedocs.io/en/latest/extending_filer.html#providing-custom-image-model

My code (all in myPlugins app):

models.py:

from filer.models.abstract.BaseImage

class CustomImage(BaseImage):
    category = models.CharField(max_length=20, blank=True, null=True,)

    class Meta:
        app_label = 'myPlugins'

admin.py:

from django.contrib import admin
from filer.admin.imageadmin import ImageAdmin
from filer.models.imagemodels import Image

class CustomImageAdmin(ImageAdmin):
    pass

CustomImageAdmin.fieldsets = CustomImageAdmin.build_fieldsets(
    extra_main_fields=('default_alt_text', 'default_caption', 'category'),
    extra_fieldsets=(
        ('Subject Location', {
            'fields': ('subject_location',),
            'classes': ('collapse',),
        }),
    )
)

admin.site.unregister(ImageAdmin)

admin.site.register(Image, CustomImageAdmin)

In settings.py, I've added:

FILER_IMAGE_MODEL = 'myPlugins.models.CustomImage'

I'm getting an error:

ValueError: Cannot create form field for 'image' yet, because its related model 'myPlugins.models.CustomImage' has not been loaded yet

Mike Olszak
  • 373
  • 6
  • 12
  • 1
    This might help https://stackoverflow.com/questions/17155379/django-valueerror-cannot-create-form-field-because-its-related-model-has-not-b – Luv33preet Nov 18 '17 at 07:13
  • 1
    Hi @Luv33preet, Could you tell me something more about your advise? Because I have problem with extending existing model and not touching any views in my code. – Mike Olszak Nov 18 '17 at 07:43

1 Answers1

-1

You should try to load your app before the filer app in your settings.py. Think that's the problem

Maksim
  • 1
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 01 '22 at 20:50