this is my code and weirdly it creates new entry instead of updating the 
passed one in instance argument, don't know if that because of m2m 
relationship in Entry model or my code is broken!
what could be the cause?

### my edit view
@login_required
def edit_entry_view(request, entry_id):
        
    try:
        entry = Entry.objects.get(pk=entry_id, is_visible=True)
    except ObjectDoesNotExist:
        return render(request, 'entry/entry.html', {'no_enties': True})

    if request.method == 'POST':
        entry.owner = request.user
        entry.id = entry_id
        form = EntryForm(data=request.POST, instance=entry)
        if form.is_valid():
          form.save()
          return redirect('entry')
    else:
        form = EntryForm(instance=entry)
    return render(request, 'entry/edit_entry.html', {'form': form})

###my form
class EntryForm(ModelForm):
    
    class Meta:
        model = Entry
        exclude = ('owner')

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/MQ8mh7qDPHYJ.
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