Re: Forms ForeignKeyField does not populate with initial value

2009-12-08 Thread bruno desthuilliers
On 8 déc, 13:26, Michael wrote: > ^ Thanks for that.  Have been scratching my head for a while as .id is > not a field/property for model.user, according to the doco I am > reading anyway (http://docs.djangoproject.com/en/dev/topics/auth/ > #topics-auth). When no primary

Re: Forms ForeignKeyField does not populate with initial value

2009-12-08 Thread Michael
^ Thanks for that. Have been scratching my head for a while as .id is not a field/property for model.user, according to the doco I am reading anyway (http://docs.djangoproject.com/en/dev/topics/auth/ #topics-auth). I should have just tried .id in the first place : \ ... actually you'd think

Re: Forms ForeignKeyField does not populate with initial value

2009-11-26 Thread Todd Blanchard
OK, this did lead me to the solution though. It seems that, for the ForeignKeyField the initial value should be the primary key of the record and not the object referenced. So changing >> form = IncidentForm(initial={ >>'reporter': request.user, to >> form =

Re: Forms ForeignKeyField does not populate with initial value

2009-11-26 Thread Todd Blanchard
I want it to be possible to be changed. But I also want the initial selection to be the current user. So this isn't really a solution. Thanks anyway. On Nov 26, 2009, at 10:27 AM, esatterwh...@wi.rr.com wrote: > in your IncidentForm definition set reporter to a ModelChoiceField >

Re: Forms ForeignKeyField does not populate with initial value

2009-11-26 Thread esatterwh...@wi.rr.com
in your IncidentForm definition set reporter to a ModelChoiceField (User.objects.all(), widget=forms.HiddenInput()) then it should work out ok. I usually hide fk fields to a user if i want the current request.user object, because I don't want to allow the possibility for it to be changed. On Nov

Forms ForeignKeyField does not populate with initial value

2009-11-25 Thread Todd Blanchard
I have a (simplified) model class Incident(models.Model): title = models.CharField(max_length=128) when_reported = models.DateTimeField(auto_now_add=True) reporter = models.ForeignKey(User) Where User is from auth. When used with a ModelForm, this creates a popup button with a