How do I let forms.models.ModelChoiceField.queryset relate on request.user?

2015-11-01 Thread Axel Rau
User should see only choices related to him in a ModelChoiceField.
Do I need a fresh form per request?
What would be the best approach?

Thanks, Axel
---
PGP-Key:29E99DD6  ☀ +49 160 9945 7889  ☀ computing @ chaos claudius

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/728C3EDF-62BB-4450-920B-BB7376417D9C%40Chaos1.DE.
For more options, visit https://groups.google.com/d/optout.


Re: How do I let forms.models.ModelChoiceField.queryset relate on request.user?

2015-11-02 Thread Vijay Khemlani
At least what I do in those cases is to add a constructor (__init__) to the
form class which takes the user as a parameter, modify the choicefield
queryset, and then call the original constructor of the form.

On Sun, Nov 1, 2015 at 3:50 PM, Axel Rau  wrote:

> User should see only choices related to him in a ModelChoiceField.
> Do I need a fresh form per request?
> What would be the best approach?
>
> Thanks, Axel
> ---
> PGP-Key:29E99DD6  ☀ +49 160 9945 7889  ☀ computing @ chaos claudius
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/728C3EDF-62BB-4450-920B-BB7376417D9C%40Chaos1.DE
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei0v3POcwmw9s0beYyGXK15ybwDPooPsYDm%3D1_0XvpStpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I let forms.models.ModelChoiceField.queryset relate on request.user?

2015-11-04 Thread Axel Rau
Thanks, I will try this,
Axel

> Am 02.11.2015 um 13:50 schrieb Vijay Khemlani :
> 
> At least what I do in those cases is to add a constructor (__init__) to the 
> form class which takes the user as a parameter, modify the choicefield 
> queryset, and then call the original constructor of the form.
> 
> On Sun, Nov 1, 2015 at 3:50 PM, Axel Rau  wrote:
> User should see only choices related to him in a ModelChoiceField.
> Do I need a fresh form per request?
> What would be the best approach?
> 
> Thanks, Axel
> ---
> PGP-Key:29E99DD6  ☀ +49 160 9945 7889  ☀ computing @ chaos claudius
> 
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/728C3EDF-62BB-4450-920B-BB7376417D9C%40Chaos1.DE.
> For more options, visit https://groups.google.com/d/optout.
> 
> 
> -- 
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CALn3ei0v3POcwmw9s0beYyGXK15ybwDPooPsYDm%3D1_0XvpStpQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/48C6118F-168C-43C9-A2B1-30047225B354%40Chaos1.DE.
For more options, visit https://groups.google.com/d/optout.


Re: How do I let forms.models.ModelChoiceField.queryset relate on request.user?

2015-11-16 Thread Axel Rau
Any idea how to add __init__() to a form class, created by modelform_factory () 
?

Axel

Am 02.11.2015 um 13:50 schrieb Vijay Khemlani :

> At least what I do in those cases is to add a constructor (__init__) to the 
> form class which takes the user as a parameter, modify the choicefield 
> queryset, and then call the original constructor of the form.
> 
> On Sun, Nov 1, 2015 at 3:50 PM, Axel Rau  wrote:
> User should see only choices related to him in a ModelChoiceField.
> Do I need a fresh form per request?
> What would be the best approach?
> 
> Thanks, Axel
> ---
> PGP-Key:29E99DD6  ☀ +49 160 9945 7889  ☀ computing @ chaos claudius
> 
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/728C3EDF-62BB-4450-920B-BB7376417D9C%40Chaos1.DE.
> For more options, visit https://groups.google.com/d/optout.
> 
> 
> -- 
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CALn3ei0v3POcwmw9s0beYyGXK15ybwDPooPsYDm%3D1_0XvpStpQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

---
PGP-Key:29E99DD6  ☀ +49 160 9945 7889  ☀ computing @ chaos claudius

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1B5822AC-4F06-4466-8DD0-4996BAC6ABF2%40Chaos1.DE.
For more options, visit https://groups.google.com/d/optout.


Re: How do I let forms.models.ModelChoiceField.queryset relate on request.user?

2015-11-17 Thread Axel Rau
Instead off writing an __init__ for the form class, I ended up with this 
get_form()
in my view class:

def get_form(self, form_class=None):
form = self.get_form_class()
pk = self.request.user.pk
self.object = Account.objects.get(pk=pk)
form_instance = form(instance=self.object)
self.filter_modelChoices(form_instance)
return form_instance

def filter_modelChoices(self, form_instance):
"""
Changes the model choice fields to be correctly filtered
 as required by request.user.
"""
opts = self.model._meta
for formfield_name in form_instance.fields:
formfield = form_instance.fields[formfield_name]
if isinstance(formfield, ModelChoiceField):
[modelfield] = 
[f for f in opts.fields if f.name == formfield_name]
qs = userVisibleFilterQS(
self.request.user.pk, 
False,
modelfield.related_model())
if qs:
formfield.queryset = formfield.queryset.filter(qs)


Am 16.11.2015 um 18:38 schrieb Axel Rau :

> Any idea how to add __init__() to a form class, created by modelform_factory 
> () ?


Axel
---
PGP-Key:29E99DD6  ☀ +49 160 9945 7889  ☀ computing @ chaos claudius

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/30621D2F-064C-4734-8669-FECACD1F3083%40Chaos1.DE.
For more options, visit https://groups.google.com/d/optout.


Re: How do I let forms.models.ModelChoiceField.queryset relate on request.user?

2015-11-18 Thread 'Tom Evans' via Django users
On Mon, Nov 16, 2015 at 5:38 PM, Axel Rau  wrote:
>
> Any idea how to add __init__() to a form class, created by modelform_factory 
> () ?
>
> Axel
>

modelform_factory takes many arguments, one of which is for the base
form class to use. You can provide a different base class from the
default ModelForm, make sure to derive the new base class from
ModelForm.

https://docs.djangoproject.com/en/1.8/ref/forms/models/#django.forms.models.modelform_factory

Cheers

Tom

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1LCk_oH4HLMW_7KhjtARkZxESxgQGBUrCeHx1D24h%3DpdQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I let forms.models.ModelChoiceField.queryset relate on request.user?

2015-11-18 Thread Axel Rau

> Am 18.11.2015 um 15:28 schrieb 'Tom Evans' via Django users 
> :
> 
> modelform_factory takes many arguments, one of which is for the base
> form class to use. You can provide a different base class from the
> default ModelForm, make sure to derive the new base class from
> ModelForm.
> 
Ah, thanks for the explanation,
Axel
---
PGP-Key:29E99DD6  ☀ +49 160 9945 7889  ☀ computing @ chaos claudius

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6458ED0A-FB91-4DA7-BC45-188C5A4CD3E4%40Chaos1.DE.
For more options, visit https://groups.google.com/d/optout.