Saturday, November 30, 2013

Re: How to use primary key as an attribute

I'm not sure what you are trying to accomplish. Since the 'pk' field
is going to be defined on your instances anyway, do you need a
'thread_pk' field?

On Sat, Nov 30, 2013 at 3:38 PM, Aamu Padi <aamupadi@gmail.com> wrote:
> This may be a lame question, but how do I use the primary key as a default
> value for an attribute?
>
> This is my models.py:
>
> class Thread(models.Model):
> thread_pk = models.PositiveIntegerField(default=self.pk)
>
> This gives me an error:
>
> self is not defined
>
> How do I go about using the pk as a default value of an attribute? Any help
> will be grateful. Thank you.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHSNPWs3NSQtzciqYL%2B7C7FL3Ybu1SAQv-L73EL2DNCMpJn7tA%40mail.gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
MLHIM VIP Signup: http://goo.gl/22B0U
============================================
Timothy Cook, MSc +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B%3DOU3UTGKqCM8gtFSGFKat-PYB3u7RzfVyXzA-8mhuLrKmp%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment