Re: Creating an object using Foreign Key for Users but filtered by group

2014-05-05 Thread Vibhu Rishi
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 wrote: > You could use the `ForeignKey.limit_choic

Re: Creating an object using Foreign Key for Users but filtered by group

2014-05-05 Thread Simon Charette
You could use the `ForeignKey.limit_choices_to` option : class Message(models.Model): moderator = models.ForeignKey(User, limit_choices_to={'groups__name': 'Moderator'}) user= models.

Re: Creating an object using Foreign Key for Users but filtered by group

2014-05-05 Thread Carlos Futino
Hi, you could change the QuerySet of the ModelChoiceField. I'd do it in the forms __init__ method. Like this: class MessageForm(forms.ModelForm): def __init__(self,*args,**kwargs): super(MessageForm,self). __init__(*args,**kwargs) self.moderator.queryset = User.objects.filter(...*Place your q

Re: Creating an object using Foreign Key for Users but filtered by group

2014-05-05 Thread Helton Alves
Hi brother, so, I don't know if understand very well. but I think that this is answer for your problems. https://docs.djangoproject.com/en/dev/ref/contrib/admin/ vlw. 2014-05-05 14:52 GMT+01:00 Vibhu Rishi : > Hi > > I have Users and based on some requirements, I have created a few User > Gro

Creating an object using Foreign Key for Users but filtered by group

2014-05-05 Thread Vibhu Rishi
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): mo