Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My questions are: How did you define your models? Can you get the users from the group? Can you get the groups from the user? something like that:</p> <pre><code>groups = Group.objects.get(pk=1) groups.users user = User.objects.get(pk=1) user.groups </code></pre> <p>You can do that writing this in you code:</p> <pre><code>#models.py class User(Model): name = CharField(max_length=200) class Group(Model): name = CharField(max_length=200) users = ManyToManyField(User, related_name="groups") #forms.py class ArrangeUserForm(forms.Form): def __init__(self, *args, **kwargs): super(ArrangeUserForm, self).__init__(*args, **kwargs) groups = groups.objects.filter(name="sale") user_choices = User.objects.filter(groups_in=groups) self.fields['user_field'] = forms.ChoiceField(widget=forms.Select, choices=user_choices) mobile = forms.CharField(widget=forms.TextInput, max_length=11, min_length=11) #And you views.py class ArrangeUserHandler(FormView): form_class = ArrangeUserForm template_name = 'student/student_form.html' def form_valid(self, form): #When the form is valid return super(ArrangeUserHandler, self).form_valid(form) def form_invalid(self, form): #When the form is invalid return super(ArrangeUserHandler, self).form_invalid(form) </code></pre> <p>I think that It should work fine and quickly. Will you tell me if this lines work?</p> <pre><code># ... groups = groups.objects.filter(name="sale") user_choices = User.objects.filter(groups_in=groups) # ... </code></pre> <p>I hope that helps. see the Documentation of <a href="https://docs.djangoproject.com/en/dev/topics/db/examples/many_to_many/" rel="nofollow"> ManyToMany field</a> and <a href="https://docs.djangoproject.com/en/1.5/ref/class-based-views/generic-editing/" rel="nofollow">FormView </a> if you are in django 1.5</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload