Hi Simon,

this is exactly what I was looking for ! It works perfectly.

I had gone through the documentation for limit_choices_to but I was not
able to figure out how to do the groups part.

Vibhu


On Mon, May 5, 2014 at 8:51 PM, Simon Charette <charett...@gmail.com> wrote:

> You could use the `ForeignKey.limit_choices_to` 
> option<https://docs.djangoproject.com/en/1.6/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to>
> :
>
> class Message(models.Model):
>      moderator = models.ForeignKey(User, limit_choices_to={'groups__name':
> 'Moderator'})
>
>      user= models.ForeignKey(User)
>      text = models.TextField(max_length=1000)
>       date = models.DateField(default=datetime.now())
>
>
> Le lundi 5 mai 2014 09:52:58 UTC-4, Vibhu Rishi a écrit :
>
>> Hi
>>
>> I have Users and based on some requirements, I have created a few User
>> Groups . e.g. I have a group of moderators.
>>
>> Now, I am trying to create a form where a normal user can message the
>> moderators.
>>
>> So, I have a model to be used by the form something like :
>>
>> class Message(models.Model):
>>      moderator = models.ForeignKey(User)
>>      user= models.ForeignKey(User)
>>      text = models.TextField(max_length=1000)
>>      date = models.DateField(default=datetime.now())
>>
>> I want the moderator field to have keys to only those people who are in
>> the group where name='Moderator'
>>
>> I am not sure how to filter the ForeignKey in this case.
>>
>>
>> Why I want to do this --> is so that the form will have a dropdown list
>> of moderators to choose from by the user when it is displayed. User selects
>> the moderator, and enteres the message text - and sends it.
>>
>> Regards,
>> Vibhu
>>
>> --
>> Simplicity is the ultimate sophistication. - Leonardo da Vinci
>> Life is really simple, but we insist on making it complicated. -
>> Confucius
>>
>  --
> 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/c381e096-5466-4f4a-8356-95c595b0b28c%40googlegroups.com<https://groups.google.com/d/msgid/django-users/c381e096-5466-4f4a-8356-95c595b0b28c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Simplicity is the ultimate sophistication. - Leonardo da Vinci
Life is really simple, but we insist on making it complicated. - Confucius

-- 
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/CAPiONwmS6j5Y4Q22w_n1xQQu7ZM8N_dtaCSU%3DyLe6gbFgDcPhA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to