Thanks for the response. I actually will already have the PK, and am
trying to avoid grabbing an instance of the actual item object.

On May 12, 11:26 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On May 12, 4:04 pm, Nick Serra <nickse...@gmail.com> wrote:
>
>
>
>
>
> > Sorry for the confusing title. Here is a simple example to illustrate
> > my question:
>
> > class Item(models.Model):
> >     name = models.CharField()
>
> > class Manager(models.Model):
> >     item = models.ForeignKey(Item)
>
> > On a POST I have the PK of the Item I want to link to a new instance
> > of the Manager object. I am saving a new Manager object that will be
> > linked to the Item with the PK i have. So I can do:
>
> > item_pk = request.POST.get('item')
> > item = Item.objects.get(pk=item_pk)
> > new_manager = Manager(item=item)
> > new_manager.save()
>
> > ...but I don't like the idea of grabbing the item object first. Is
> > there any way to just save the new Manager object with just the PK of
> > the Item, thus avoiding the database call to grab the Item object?
>
> > Thanks!
>
> You should just be able to do
>     manager = Manager(item=item_pk)
> but in general, you can always refer to item_id, as the underlying
> database field representing the foreign key value.
> --
> DR.
>
> --
> 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 
> athttp://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.

Reply via email to