有没有比 ModelMultipleChoiceField 更好的解决方案?

Is there a better solution instead of ModelMultipleChoiceField?

我有一个表格,用户可以在其中创建钓鱼之旅,他们可以从注册用户(渔民)中添加多个参与者。

models.py

class Fisherman(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    fisherman_id = models.AutoField(primary_key=True)

    class Meta:
        verbose_name = "Fisherman"
        verbose_name_plural = "Fishermen"

    def __str__(self):
        return f'{self.user.username}'

class Trips(models.Model):
    lake = models.CharField("Lake", max_length=150)
    city = models.CharField("City", max_length=100, blank=True)
    s_date = models.DateTimeField("Starting Date", auto_now=False, auto_now_add=False)
    e_date = models.DateTimeField("Ending Date", auto_now=False, auto_now_add=False)
    fisherman = models.ManyToManyField(Fisherman)
    trip_id = models.AutoField(primary_key=True)
    total_catch_weight = models.DecimalField(max_digits=5, decimal_places=2, default=0)
    
    class Meta:
        verbose_name = "Trip"
        verbose_name_plural = "Trips"

    def __str__(self):
        return f"{self.lake} - {self.trip_id}"

forms.py

class TripsForm(forms.ModelForm):
    fisherman = forms.ModelMultipleChoiceField(queryset=Fisherman.objects.all().exclude(user__username="admin"), widget=forms.SelectMultiple(attrs={'class': 'form-select'}))
    class Meta:
        model = Trips
        fields = ["lake", "city", "s_date", "e_date", "fisherman"]
        widgets = {
            "lake": forms.TextInput(attrs={'type': 'text', 'class': 'form-control', 'id': 'LakeInput',}),
            "city": forms.TextInput(attrs={'type': 'text', 'class': 'form-control', 'id': 'CityInput',}),
            "s_date": forms.DateTimeInput(format='%Y-%m-%d %H:%M', attrs={'class':'datetimefield form-control', 'id': 'StartingDate',}),
            "e_date": forms.DateTimeInput(format='%Y-%m-%d %H:%M', attrs={'class':'datetimefield form-control', 'id': 'EndingDate',}),
        }

我目前使用的是 ModelMultipleChoiceField,它在表单中列出了所有现有的渔民,但我想找到一个更好的解决方案,因为我不希望用户可以看到所有已注册的渔民。

有没有办法通过输入他们的名字将更多渔民添加到行程中?在 manytomanyfield 的情况下是否可能? 我不知道“打字解决方案”如何工作,因为只能将注册的渔民添加到行程中。

在这种有很多选择的情况下,我喜欢使用 django_select2 ModelSelect2MultipleWidget

它动态加载选项并具有搜索功能。更多信息:https://django-select2.readthedocs.io/en/latest/index.html