Django-Jet: How do I set a foreign key null, if it is autocompleted via AJAX requests?

325 Views Asked by At

I am using Django-Jet and have a model with many ForeignKey fields. For those fields I want their values retrieved dynamically via AJAX and not preloaded. One of the field is like this:

class Person(Base_Entity):
        first_name = models.ForeignKey(
                'Name',
                null = True,
                blank = True,
                default = None,
                verbose_name = _('first name of person'),
                on_delete = models.SET_NULL,
                related_name = 'is_first_name_of_%(app_label)s_%(class)s',
        )
)
@staticmethod
def autocomplete_search_fields():
        return 'first_name__name',

(The Name model has hundreds of entries, and there will be even more later)

It seems I cannot set that field to NULL in Django Admin (no line with dashes appears):

enter image description here If I turn on autocomplete (i.e. remove the autocomplete_search_fields method), I do get that NULL entry, BUT I also get all the possible values preloaded in the HTML select, and that slows down the page loading to a point it is not usable.

I am using Django 2.1.4, Django-Jet 1.0.8 (I suspect the issue is closely related to Django-Jet)

Any help is appreciated.

1

There are 1 best solutions below

0
On

I am using djangojet and this relation shows an empty value choice in admin ("-----"):

 someModel_FK= models.ForeignKey(someModel,
                                  related_name='this-model',
                                  null=True,
                                  blank=True,
                                  on_delete=models.SET_NULL)

a - Remove django-jet and check on default admin. b- Are you missing migrations ? is this "null=True,blank=True, " migrated to DB ?