Wednesday, August 19, 2015

Re: 'self' is not define

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJV1HfpAAoJEH2EY3tf/UcFq4MP/0Wu9yf92+0lIuwBQzEbUhMl
ULWR1RP7debOGPQMgyIx5IiHDY8+xEMuwRLKTI4GMX+qooshFs6gJLtVA4W4ejYF
mMd/J3vaWHYzodSTALaBc9uiPWqgwyzpBgBh2u2JON49yyCuLZx3IT88wL6dadcn
rfFBd8/0Bfu4I/J2bSvV+b8qgaMVciYYoXJ8lqxawtEMW4do4Th/AfIOunW0w7hX
ulEO6LbJTOgoBVDoRR6V13cFiFQyyBQE7CgKojUxGn9UyBQFzYEa70pGXCeivNQ9
vSYb4u6bJ/hnfTYTco6lx+7kghNyPaz/X/XY2YZwI26s7TT13HcY/BJMBJ86pTqV
xwoyoVBvbVAn+FIEtaQPY+Jhvg1sih1mvzBJCHE9cdCbqkzyzcHORiZR0k1kIbVk
+yuB409Sad/Hf8fZKVCQ4g6zXVOQsllktARLZzMnQX3NdyYrwbQRGyGJDm8LLQhf
1tp3rnkHmjiSY6s7yATJ8LBuivmRBxhIekiV9Dic1j3wDmA/GiOTFPrV1ukyltdh
p8LsPP0+h2jD+KOoUDEKRaRLky/WwIOarCtd3YJ5POce22Sqld0ehbsXJJ8RKrZN
Igz90f89t4+VV6Y9ED2N6dus3tlSnTBDcPkXPTRnWcIileb51g7hxrncDiaor/4h
AXBm6EiVl5xdo88Q/l4h
=HRB6
-----END PGP SIGNATURE-----
On 19/08/15 13:25, Remaze Vs wrote:
> username=self.request.user.username

What do you want to accomplish with this line?
This cannot work.
Where should self and self.request come from?

You probably want to us a ForeignKey to the User model.
(user = models.ForeignKey(User))
Afterwards you have to add request.user to the product in your view
where you save it.

Use something like
product = form.save(commit=False) # [0]
product.user = request.user
product.save()

And you should move your form to forms.py and add a view to views.py.

-- Florian

[0]
https://docs.djangoproject.com/en/1.8/topics/forms/modelforms/#the-save-method

--
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/55D477E8.1010802%40ist-total.org.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment