Question

I have a field in a Django model, and I want there to be a small (~20) set of possibilities (which are strings) which can be autocompleted (preferably with django-autocomplete-light, which I am using already) in django-admin. Should I make this a foreign key field and create a model containing just these 20 possibilities? or is there a better way?

Was it helpful?

Solution 2

The only way to do this is to have a separate model with only those possibilities and to make the field we want to limit into a foreign key field.

OTHER TIPS

django orm limit should be done something like:

Entry.objects.all()[:5]

so creating a new model for limiting number of results would not make sense.

I've looked at django-autocomplete-light and saw limit_choices here (didn't give it a try.

in any case it should be something like line 77 in this snippet.

I hope this is helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top