I am trying to edit an object through the form
All fields are edited but the image field does not change
What is the problem?
model created with signals when user create account
template
<div> <form action="{% url 'user:profile' %}" method="post" enctype="multipart/form-data"> {% csrf_token %} {{form}} <input type="submit" value="submit"> </form> </div> model
class Profile(models.Model): CHOICES = ( ('RE', 'مشاور املاک'), ('S', 'فروشنده'), ) user = models.OneToOneField(User, on_delete=models.CASCADE) real_estate = models.OneToOneField(Business , related_name='business' ,on_delete=models.CASCADE, blank=True , null=True) image = models.ImageField(blank=True) type_of_user = models.CharField(max_length=300, choices=CHOICES) phone_number = PhoneNumberField(unique = True, null = False, blank = False) form
class ProfileForm(ModelForm): class Meta: model = Profile fields = ['type_of_user' , 'phone_number' , 'image'] views
def profile(request): profile = Profile.objects.get(user=request.user) if request.method == 'POST': form = ProfileForm(request.POST , instance=profile) profile = form.save(commit=False) profile.user = request.user profile.save() redirect('busi:index') else: form = ProfileForm() context = { 'profile':profile, 'form':form } return render(request , 'user/profile.html' , context)