Re: filtering drop downs according to logged in user
test On Apr 21, 7:10 pm, "Szabo, Patrick \(LNG-VIE\)"wrote: > Hi, > > I want to filter the dropdownlists that are automatically used to select > a foreign-key in forms (in my views). > > Normally that could easily be done with "class Meta" in the Modelform. > > Thing is i want to filter by an attribute of the current > userspecificly the groups that the user is assigned to. > > So how do i do that ?! > > Can i acces request.user in the models somehow ?! > > Kind regards > > . . . . . . . . . . . . . . . . . . . . . . . . . . > Patrick Szabo > XSLT Developer > LexisNexis > Marxergasse 25, 1030 Wien > > mailto:patrick.sz...@lexisnexis.at > Tel.: +43 (1) 534 52 - 1573 > Fax: +43 (1) 534 52 - 146 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: filtering drop downs according to logged in user
On Apr 21, 7:10 pm, "Szabo, Patrick \(LNG-VIE\)"wrote: > Hi, > > I want to filter the dropdownlists that are automatically used to select > a foreign-key in forms (in my views). > > Normally that could easily be done with "class Meta" in the Modelform. > > Thing is i want to filter by an attribute of the current > userspecificly the groups that the user is assigned to. > > So how do i do that ?! > > Can i acces request.user in the models somehow ?! > > Kind regards > > . . . . . . . . . . . . . . . . . . . . . . . . . . > Patrick Szabo > XSLT Developer > LexisNexis > Marxergasse 25, 1030 Wien > > mailto:patrick.sz...@lexisnexis.at > Tel.: +43 (1) 534 52 - 1573 > Fax: +43 (1) 534 52 - 146 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: filtering drop downs according to logged in user
I have set the choices list in the view: choices = SomeModel.objects.filter(user=request.user).values_list('id','label') Then, after the form is instantiated, modify the choices attribute of the ChoiceField: form = SomeOtherModelForm() form.fields['model_dropdown'].choices = choices Works in a similar fashion with a ModelChoiceField and the queryset attribute. On Apr 21, 10:10 am, "Szabo, Patrick \(LNG-VIE\)"wrote: > Hi, > > I want to filter the dropdownlists that are automatically used to select > a foreign-key in forms (in my views). > > Normally that could easily be done with "class Meta" in the Modelform. > > Thing is i want to filter by an attribute of the current > userspecificly the groups that the user is assigned to. > > So how do i do that ?! > > Can i acces request.user in the models somehow ?! > > Kind regards > > . . . . . . . . . . . . . . . . . . . . . . . . . . > Patrick Szabo > XSLT Developer > LexisNexis > Marxergasse 25, 1030 Wien > > mailto:patrick.sz...@lexisnexis.at > Tel.: +43 (1) 534 52 - 1573 > Fax: +43 (1) 534 52 - 146 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: filtering drop downs according to logged in user
Completely off topic but, what exactly does an "XSLT Developer" do? On Thu, Apr 21, 2011 at 3:10 PM, Szabo, Patrick (LNG-VIE) < patrick.sz...@lexisnexis.at> wrote: > Hi, > > > > I want to filter the dropdownlists that are automatically used to select a > foreign-key in forms (in my views). > > Normally that could easily be done with „class Meta“ in the Modelform. > > Thing is i want to filter by an attribute of the current user….specificly > the groups that the user is assigned to. > > > > So how do i do that ?! > > Can i acces request.user in the models somehow ?! > > > > Kind regards > > . . . . . . . . . . . . . . . . . . . . . . . . . . > > ** > > Patrick Szabo > XSLT Developer > > LexisNexis > Marxergasse 25, 1030 Wien > > patrick.sz...@lexisnexis.at > > Tel.: +43 (1) 534 52 - 1573 > > Fax: +43 (1) 534 52 - 146 > > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: filtering drop downs according to logged in user
As an option, you can pass a request.user to form's __init__ method from your view. Example: class YourForm(forms.ModelForm): def __init__(self, user, *args, **kwargs): self.user = user super(YourForm, self).__init__(*args, **kwargs) # here you can modify any self.fields depends on your user in view def your_view(request): form = YourForm(request.user, request.POST) On Thu, Apr 21, 2011 at 5:10 PM, Szabo, Patrick (LNG-VIE) < patrick.sz...@lexisnexis.at> wrote: > Hi, > > > > I want to filter the dropdownlists that are automatically used to select a > foreign-key in forms (in my views). > > Normally that could easily be done with „class Meta“ in the Modelform. > > Thing is i want to filter by an attribute of the current user….specificly > the groups that the user is assigned to. > > > > So how do i do that ?! > > Can i acces request.user in the models somehow ?! > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.