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 key is explicitely defined in a model, the ORM
automagically adds one with name "id" and type "integer auto
increment".

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




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 child tables of auth_user would be very, very
common, an example would be good on above doco me thinks.

.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




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 = IncidentForm(initial={
>>'reporter': request.user.id,


makes it work OK.  Seems counter-intuitive given the the ForeignKeyField wants 
to work with objects rather than keys though.



On Nov 26, 2009, at 12:33 PM, Todd Blanchard wrote:

> 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
>> (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 25, 10:32 pm, Todd Blanchard  wrote:
>>> 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 list of users.  I want it to default to the currently logged 
>>> in user so in my view I have:
>>> 
>>> def new_incident(request):
>>>   form = IncidentForm(initial={
>>>'reporter': request.user,
>>>'title': 'New Incident',
>>>'when_reported' : datetime.now(),
>>>})
>>> 
>>>media = form.media
>>>return render_to_response('incidents/new.html',{'form': form, 'media': 
>>> media},context_instance=RequestContext(request))
>>> 
>>> However the popup button's selection is never set to the current logged in 
>>> user.  I have rendered the current logged in user's name elsewhere on the 
>>> page, it is set.  But the popup selector isn't getting its selection set 
>>> right.  Any tips?  
>>> 
>>> -Todd Blanchard
>> 
>> --
>> 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>> 
>> 
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




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
> (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 25, 10:32 pm, Todd Blanchard  wrote:
>> 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 list of users.  I want it to default to the currently logged 
>> in user so in my view I have:
>> 
>> def new_incident(request):
>>form = IncidentForm(initial={
>> 'reporter': request.user,
>> 'title': 'New Incident',
>> 'when_reported' : datetime.now(),
>> })
>> 
>> media = form.media
>> return render_to_response('incidents/new.html',{'form': form, 'media': 
>> media},context_instance=RequestContext(request))
>> 
>> However the popup button's selection is never set to the current logged in 
>> user.  I have rendered the current logged in user's name elsewhere on the 
>> page, it is set.  But the popup selector isn't getting its selection set 
>> right.  Any tips?  
>> 
>> -Todd Blanchard
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




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 25, 10:32 pm, Todd Blanchard  wrote:
> 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 list of users.  I want it to default to the currently logged in 
> user so in my view I have:
>
> def new_incident(request):
>    form = IncidentForm(initial={
>             'reporter': request.user,
>             'title': 'New Incident',
>             'when_reported' : datetime.now(),
>             })
>
>     media = form.media
>     return render_to_response('incidents/new.html',{'form': form, 'media': 
> media},context_instance=RequestContext(request))
>
> However the popup button's selection is never set to the current logged in 
> user.  I have rendered the current logged in user's name elsewhere on the 
> page, it is set.  But the popup selector isn't getting its selection set 
> right.  Any tips?  
>
> -Todd Blanchard

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




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 list of users.  I want it to default to the currently logged in 
user so in my view I have:

def new_incident(request):
   form = IncidentForm(initial={
'reporter': request.user,
'title': 'New Incident',
'when_reported' : datetime.now(),
})

media = form.media
return render_to_response('incidents/new.html',{'form': form, 'media': 
media},context_instance=RequestContext(request))

However the popup button's selection is never set to the current logged in 
user.  I have rendered the current logged in user's name elsewhere on the page, 
it is set.  But the popup selector isn't getting its selection set right.  Any 
tips?  

-Todd Blanchard

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.