Session key is the session 's primary key. Not the session itself.

What you want to assign to your field is a session, not its key. So use
request.session.

However.

Please very careful when using FK' s to sessions, sessions are meant to be
short lived, and could / should be deleted once they expire (ie. When the
user logs off or after a specific duration), depending on your backend.

I'm not sure what you're trying to achieve, but I think that FKing to
sessions is, at the very list, pretty risky.

Especially given that the default on delete behavior of a ForeignKey is
cascade.
Le 17 août 2012 09:59, "Sandeep kaur" <mkaurkha...@gmail.com> a écrit :

> I am using session foreign key in my table.
>
> class ClientJob(models.Model):     #models.py
>  .....................................
>          sess = models.ForeignKey(Session)
>
> And in order to save its value in database, I used ,.
>
> def add_job(request)                      #views.py
>          ...................................
>          if not request.session.exists(request.session.session_key):
>                                 request.session.create()
>          profile.sess = request.session.session_key
>          profile.save()
>
> But when I execute my form and click on submit button, I get error as :
>
> ```Cannot assign "'b593c61453d7aad199078c66b9ad6b30'":
> "ClientJob.sess" must be a "Session" instance.````
>
> I am a bit unclear about using sessions in django, so be a little
> elaborative.
>
> Thank you.
>
>
> --
> Sandeep Kaur
> E-Mail: mkaurkha...@gmail.com
> Blog: sandymadaan.wordpress.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@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-users@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