These are chat archives for django/django

19th
Jun 2018
Curtis Maloney
@funkybob
Jun 19 2018 00:49
you didn't include the userziptie field in your modelform... so it won't show
Paul A. Aranguren
@Paulguren
Jun 19 2018 01:37
@funkybob I’m not trying to make the userziptie show for the user on the form, because that would allow him to make an entry as a different user by picking a different user. Maybe my fundamental logic is wrong in the view?
Curtis Maloney
@funkybob
Jun 19 2018 01:44
so what was the drop-down you wanted to show?
if you want to set it to the current user, you'd typically use "obj = form.save(commit=False) ; obj.user = request.user ; obj.save()"
see the ModelForm docs for the "save" method
Paul A. Aranguren
@Paulguren
Jun 19 2018 02:20
I’m sorry I wasn’t clear. I don’t want the user to see any form. I’ll try what you just explained, thank you!
Curtis Maloney
@funkybob
Jun 19 2018 02:24
can we roll back to the start... so I can understand what the end goal is? then I might understand your solution better :)
Paul A. Aranguren
@Paulguren
Jun 19 2018 02:29
I just User X, to log in, create entry Y.
Y would then be saved to the DB and it would have a relation to X
So whenever X logs in, he can see all of his Ys
The problem I was having is that whenever I used the form to create a Y, logged in as X, the Y had no relation to X. So I logged into the admin, I could see the post, but it had no relation to X, which is my user account
Is that kind of clearer?
@funkybob
I just want*
Side note: I have yet to try your solution, since I’m not home. Will try soon
Curtis Maloney
@funkybob
Jun 19 2018 02:33
ok
yes, for any field that must be set but not by the user .... omit it from the form [as you have done] and set it on the object after using save(commit=False)
Paul A. Aranguren
@Paulguren
Jun 19 2018 05:10
It didn’t work. It actually creates a separate object, Y, that is tied to the user, however it is an entirely different object as opposed to the one containing the document/data which is uploaded as a separate entry
Curtis Maloney
@funkybob
Jun 19 2018 05:10
erm... pardon?
can you show your view, please?
Paul A. Aranguren
@Paulguren
Jun 19 2018 05:10
so to recap, when you submit the form, two entries are made, 1. with the data and no user, and 2. an empty entry with a user tied to it
sure
def create_entry(request):
    createPath = 'log1/create_entry.html'
    if request.method == 'POST': 
        form = notarizerCreateForm(request.POST, 
request.FILES)
        if form.is_valid():
            a = form.save(commit=False)
            a.user = request.user
            a.save()
        else:
in that case to the user
            print(form.errors)
        return redirect(page1)
    else:
        form = notarizerCreateForm()
    return render(request, createPath, {'form': form})
don’t mind the spacing errors, that was from copying and pasting the code on here
that “in that case to the user” is a comment i partly removed, it’s no longer in hte code
Curtis Maloney
@funkybob
Jun 19 2018 05:16
def create_entry(request):
    if request.method == 'POST': 
        form = NotarizerCreateForm(request.POST,  request.FILES)
        if form.is_valid():
            a = form.save(commit=False)
            a.user = request.user
            a.save()
            # Only redirect on success
            return redirect(page1)
    else:
        form = NotarizerCreateForm()
    return render(request, 'log1/create_entry.html', {'form': form})
now... what's this about "creates a separate object" .... separate to which object?
entirely different object as opposed to the one containing the document/data which is uploaded as a separate entry
not sure what you mean
that view creates a new instance of ... whatever model NotarizerCreateForm is for
Paul A. Aranguren
@Paulguren
Jun 19 2018 05:18
I’m sorry that was a different line of code that I had on my system earlier, which did that error, your solution still doesn’t link it
you’re right about that, that’s my mitake
Curtis Maloney
@funkybob
Jun 19 2018 05:18
...
Paul A. Aranguren
@Paulguren
Jun 19 2018 05:18
I’ll just try to restart the project one line at a time
Curtis Maloney
@funkybob
Jun 19 2018 05:18
I don't understand what's gone wrong... or what you were expecting to happen...
Paul A. Aranguren
@Paulguren
Jun 19 2018 05:20
Screen Shot 2018-06-19 at 01.20.09.png
that dash on the right, is supposed to save to the user model but it doesn’t, even with your code
I think there may be some other part of my code which is broken
which is why I want to try and rebuild the project, to see if i can retrace my steps
thank you for all the time you took though
@funkybob
Curtis Maloney
@funkybob
Jun 19 2018 05:25
wait, ... what "dash on the right"?
Curtis Maloney
@funkybob
Jun 19 2018 05:44
does your view actually require someone to be authenticated?
wait... isn't your fkey to user called userziptie or something? not user?