Answer the question
In order to leave comments, you need to log in
Passing the current user to Forms.py - what's wrong?
Actually, there was already an answer here that it is necessary to use __init__, but I apparently do not fully understand how it works at all and my code does not start.
from django import forms
from .models import Container
from .my_defs import tree_parse
class ContainerForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user',None)
super(ContainerForm, self).__init__(*args, **kwargs)
in_container_id = forms.ChoiceField(choices=tree_parse(0, 'choice', user))
class Meta:
model = Container
fields = ('title', 'descripton', 'in_container_id')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question