문제

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?

도움이 되었습니까?

해결책 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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top