You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a model with a optional many to many relationship to another model.
class Author(models.Model):
name = models.Charfield(max_length=255, unique=True)
...
class Article(models.Model):
name = models.Charfield(max_length=255, unique=True)
authors = models.ManyToManyField(Author, blank=True, null=True)
...
I want to use django-autocomplete-light to allow auto-completion for authors on my article creation view, so I create a model form.
class ArticleForm(autocomplete_light.ModelForm):
class Meta:
model = Article
fields = ['name', 'authors', ...]
That works great in my view, just as expected. The author field is optional, and auto suggestions work. But now I want to limit the authors that are suggested, so I create a new autocomplete and register it:
class AuthorAutocomplete(autocomplete_light.AutocompleteModelBase):
search_fields = ['^name']
def choices_for_request(self):
# build the queryset and return it
And then alter the form to use it:
class ArticleForm(autocomplete_light.ModelForm):
authors = autocomplete_light.ModelMultipleChoiceField('AuthorAutocomplete')
class Meta:
model = Article
fields = ['name', 'authors', ...]
Now auto-completion works, the suggested authors are limited to the choices I want, but the authors field is required on the form. Where do I specify that the authors field is still optional?
The text was updated successfully, but these errors were encountered:
I have a model with a optional many to many relationship to another model.
I want to use django-autocomplete-light to allow auto-completion for authors on my article creation view, so I create a model form.
That works great in my view, just as expected. The author field is optional, and auto suggestions work. But now I want to limit the authors that are suggested, so I create a new autocomplete and register it:
And then alter the form to use it:
Now auto-completion works, the suggested authors are limited to the choices I want, but the authors field is required on the form. Where do I specify that the authors field is still optional?
The text was updated successfully, but these errors were encountered: