Unable to save ManyToManyField in admin panel as well as using ModelForm


class Profile(models.Model):

user = models.OneToOneField(User, on_delete=models.CASCADE)
profile_image = models.ImageField(upload_to='profile_images/', blank=True, null=True, verbose_name='Profile Picture')
bio = models.TextField(blank=True, null=True)
following = models.ManyToManyField(

def follow(self, user):

def unfollow(self, user):

def is_following(self, user):
    return self.following.filter(pk=user.pk).exists()

def __str__(self):
    return "{}".format(self.user.username)

# def save(self, *args, **kwargs):
#     super(Profile, self).save(*args, **kwargs)

class Blog(models.Model):

author = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
title = models.CharField(max_length=200)
description = models.TextField(blank=True, null=True)
blog_image = models.ImageField(upload_to='blog_images/', blank=True, null=True, verbose_name='Blog Picture')
date = models.DateTimeField(auto_now_add=True)

def __str__(self):
    return "{} {} {}".format(self.author, self.title, self.date)

class Meta:
    ordering = ["date"]


class BlogForm(forms.ModelForm):

class Meta:
    model = Blog
    fields = ('title', 'description', 'blog_image')

class ProfileForm(forms.ModelForm):

class Meta:
    model = Profile
    fields = ('profile_image', 'bio', 'following')


class CreateProfile(LoginRequiredMixin, CreateView):

model = Profile
form_class = ProfileForm
context_object_name = 'create_profile'
template_name = 'blog/create_profile.html'
success_url = reverse_lazy('home')

def form_valid (self, form):
    form = ProfileForm(self.request.POST, self.request.FILES)
    instance = form.save(commit=False)
    form.save_m2m()  # Save the ManyToManyField 'following'

    return super(CreateProfile, self).form_valid(form)

You’re going to need to provide more detail and be more descriptive about the problem you’re having.

These details need to include what you’re seeing that you don’t expect to see - or what you’re not seeing that you’re expecting to see.

Include all error messages that you may be getting in the console where you’re running runserver.

Post your ModelAdmin class that you’re saying is not working.

Side note, Don’t do this:

The form has already been instantiated from the POST data earlier in the view processing, along with having been validated.

Also, since you’re saving the form here, you should not be calling super in form_valid. After you’ve done your work here, return your HttpResponseRedirect to your success_url.

If you’re not familiar with the Classy Class-Based Views site, I suggest you take some time reading it to help you understand what each of the functions being performed do. (Personally, I find that site to be more useful than the official docs when it comes to understanding the CBVs.)