0

Is it possible to somehow adapt something similar to my problem?

I would like a list to appear in the form based on data from another list Select from the second field - filtering data - (contents) depending on the received values of the first field. For example. London Cafe London Restaurant London Fast Food Manchester Pizzeria Manchester Burgers

I select a city in the form field and the second field is filtered by establishments.

How to select from the second field in the form - filtering data depending on the values of the first field?

class ExcludedDateForm(ModelForm): class Meta: model = models.ExcludedDate exclude = ('user', 'recurring',) def __init__(self, user=None, **kwargs): super(ExcludedDateForm, self).__init__(**kwargs) if user: self.fields['category'].queryset = models.Category.objects.filter(user=user) class FilterByUserMixin(LoginRequiredMixin): """ Filters the queryset with `self.request.user` in a specified `user_field` field. `user_field` defaults to "user". """ user_field = "user" def get_queryset(self, *args, **kwargs): return ( super() .get_queryset(*args, **kwargs) .filter(**{self.user_field: self.request.user}) ) class Book(models.Model): author = models.ForeignKey(MyUser, on_delete=models.RESTRICT) number_pages = models.PositiveIntegerField() title = models.CharField(max_length=1000) class BookUpdateView(FilterByUserMixin, UpdateView): model = Book template_name = "book/my_book_update_template.html" fields = ["number_pages", "title"] success_url = reverse_lazy("book-update-success") user_field = "author" 

. . .. .. ........

1
  • Make a GET request with a selected value (e.g., from a dropdown), filter a Django model using that value, and return filtered data to populate another dropdown. Commented Jun 20 at 7:44

1 Answer 1

0

Maybe this can help to solve your problem:

https://django-formset.fly.dev/selectize/#filtering-select-options

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.