Tuesday, April 28, 2020

Re: How to use ModelChoiceField? I whould like to filter the output from a field form.

user.id надо брать из request объекта в контроллере request.user.id. В том же контроллере метод get_initial() позволяет инициализировать поля формы(указанной в аттрибуте "form_class")контроллера.
Например:
    def get_initial(self):
            # поле category формы будет установлено в результат выборки по ключу
            self.initial["category"] = Category.objects.get(pk=self.c_id)
        return self.initial.copy() # 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/11c1e6b3-f30d-4040-a7bb-cbe6ad290b8e%40googlegroups.com.

No comments:

Post a Comment