Getting user's old image if no image is selected

Getting user's old image if no image is selected

I have a form that takes in user data like bio, profile picture, gender, etc. and upon submission either creates this new row about the user or updates the existing row. This will only work if the user uploads an image. If no image is uploaded for the profile picture, then the form doesn't submit. How can I make it so that if the user didn't upload a profile picture, then it'll keep the user's previous profile picture and still submit?

I have a form that takes in user data like bio, profile picture, gender, etc. and upon submission either creates this new row about the user or updates the existing row. This will only work if the user uploads an image. If no image is uploaded for the profile picture, then the form doesn't submit. How can I make it so that if the user didn't upload a profile picture, then it'll keep the user's previous profile picture and still submit?

Here's my code:

class ProfileSettings(UpdateView):
    model = Profile
    template_name = 'blog/settings.html'
    form_class = ProfileForm
    success_url = reverse_lazy('blog:settings')

def post(self, request, *args, **kwargs):
    form = self.form_class(request.POST, request.FILES)

    if form.is_valid():
        bio = form.cleaned_data['bio']
        gender = form.cleaned_data['gender']
        avatar = form.cleaned_data['avatar']

        Profile.objects.update_or_create(user=self.request.user, defaults={'avatar':avatar, 'bio':bio, 'gender':gender})

    return HttpResponseRedirect(self.success_url)


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Python Django Tutorial | Django Course

🔥Intellipaat Django course: https://intellipaat.com/python-django-training/ 👉This Python Django tutorial will help you learn what is django web development &...

How to Integrate Django to any Javascript Front End // Django to React // Django to Angular

Learn the basic technique to Integrate Django to any Javascript Front End // Django to React // Django to Angular

Django

Well i used django ... i want to know after completing all the coding stuff, can i make all the codes online ?