I'm also somewhat of a beginner, but here goes...
You might want to separate your model from your view a bit more.

http://dpaste.com/hold/100082/


On Dec 17, 11:08 am, abidibo <abid...@gmail.com> wrote:
> Hi all,
> I'm a beginenr with Django and Python and I'e have a problem I didn't
> reached to solved myself, here is the question:
> I'd like to have a DB table like POST, that contains a title, a text
> and an author. I'd like the field author to be filled with the id of
> the user which is writing the form, so i tried to set it as a default
> value in the models.py this way:
>
>   from django.db import models
>   from django.contrib.sessions.models import Session
>   from django.http import HttpRequest
>
>   request = HttpRequest()
>
>   cookies = request.COOKIES
>
>   session = Session.objects.get(session_key=session_key)
>
>   class Post(models.Model):
>     topic = models.ForeignKey(Topic)
>     title = models.CharField(max_length=50)
>     pub_date = models.DateTimeField(True, False, 'date published')
>     author = models.IntegerField('author')
>     author.default = session.get_decoded().get('_auth_user_id')
>     text = models.TextField()
>     def __unicode__(self):
>         return self.title
>
> but the problem, i think, is that the array cookies has no elements,
> even if with my browser tool i may see the cookie with key 'sessionid'
> setted.
> Anyone can help me? How may I implement this easy situation?
> Thanks all
--~--~---------~--~----~------------~-------~--~----~
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