request user

20 views
Skip to first unread message

Elias Coutinho

unread,
Apr 18, 2016, 3:49:01 PM4/18/16
to Django users
Good afternoon people,

I am using django material, LayoutMixin

My view is:

class NewProfissoesPessoaView (LoginRequiredMixin, LayoutMixin,
                     extra_views.NamedFormsetsMixin,
                     extra_views.CreateWithInlinesView):
   title = "New Job"
   model = ProfissoesPessoa

    print ( 'come on line 334')

    layout = Layout (
       Row ( 'person', 'profession', 'rating'),
       # Fieldset ( 'Address'
       # Row (Span7 ( 'address'), Span5 ( 'zipcode'))
       # Row (Span5 ( 'city'), Span2 ( 'state'), Span5 ( 'country')))
       Inline ( 'Qualifications Profession', ItemInline)
   )

    def form_valid (self, form):
       print ( 'come on line 343')
       profession = self.object.save (commit = False)
       profissao.pessoa = request.user
       profissao.save ()

    def get_success_url (self):
       return self.object.get_absolute_url ()



If you look has form_valid function, I'm trying to get my registration can be done without having to manually enter the logged in user.

A View only enter if you login, but when loading the template it does not meet the user field. (This field wanted to hide)

As I am using django materials needed to create the forms.py

Can someone help me? All he wanted was to save without informing the user logged in, he seve be added without the intervention of anyone.

Avraham Serour

unread,
Apr 20, 2016, 7:07:06 AM4/20/16
to django-users
if you can get the request object you can get the current user with request.user


--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d5d3b9d5-dba6-4361-999c-e0467ad69a3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages