[Answered ]-Checkmark is not shown in django form

1👍

The selection box is empty because there are no values in the Location model. Many-to-many models are for cases where you will be dynamically create instances that can be linked via the M2M relation, rather than static choices as you’ve created in LOCATION_INHOME. If you want to have a select multiple form field with static options, you’ll need to use a 3rd party package like https://pypi.org/project/django-select-multiple-field/. If you want to use dynamic choices with a M2M relation, you’ll need to populate those options in the Location model first.

0👍

You need to attach the form on the .form attribute [Django-doc] of the ModelAdmin:

from django.contrib import admin


@admin.register(Contact)
class ContactAdmin(admin.ModelAdmin):
    form = ContactForm
    list_filter = ('location_in_home', )

It will of course only render options if there is at least one location you have constructed.

otherwise you just constructed a form. But you can create zero, one, or multiple ModelForms for the same model, these do not do anything unless you use these in a view, admin, etc.

Leave a comment