[Answer]-Field in the model does not change in django app

1👍

Here’s the canonical way to use a ModelForm to create or update a model instance:

def myview(request, pk=None):
    if pk:
        instance = get_object_or_404(Subscriber, pk=pk)
    else:
        instance = None
    if request.method == "POST":
        form = SubscriberForm(request.POST, instance=instance)
        if form.is_valid():
            instance = form.save()
            # do whatever with instance or just ignore it
            return redirect(some return url)
    else:
        form = SubscriberForm(instance=instance)
    context = {"form":form}
    return render(request, "path/to/your/template.html", context)

If your view doesn’t look something like it then you’re very probably doing it wrong. Your mention of a tshirt_size = request.POST.get('tshirt_size') in your view is a sure smell you’re doing it wrong FWIW.

Leave a comment