TL;DR: I want to save a foreign key using a CreateView class -- I can get my User groups to save, but not my own model objects.
Context: I am writing a Django-App that deals with Groups, Posts, and Users. Post entries contain a foreign key for both Group and User (a post must belong to a group and a user). I want the user to be able to add a post to a group from the group page itself -- i.e. when they access the CreateView form for this new post, there should be no 'Group' field.
My Problem: I want to save a new post object with a CreateView class with a behind-the-scenes insertion of the Group (from a slug) and User (from self.request.user). Usually, I use the form_valid() method to do this, and it works just fine for inserting the User object; however, I cannot figure out why my Group object won't save.
Some other information:
- I know that I am able to successfully grab the Group object from the slug in the kwargs. I have assigned this object to the variable self.form_group in the get() method and I have confirmed the 'type' of the object is the correct instance of my Group class. 
- I have tried 'getting' the Group object in the form_valid() method itself: still no luck. 
- I have tried both the commented and uncommented blocks of code in the form_valid() method, respectively. 
Models:
class Post(models.Model):
    user = models.ForeignKey(User, on_delete = models.CASCADE, related_name = 'posts')
    title = models.CharField(max_length = 100,default = '')
    created_at = models.DateTimeField(auto_now = True)
    post_text = models.TextField()
    post_text_html = models.TextField(editable = False) 
    group = models.ForeignKey(Group, on_delete = models.CASCADE, related_name = 'posts', null = True, blank = True)
-
class Group(models.Model):
     name = models.CharField(max_length = 255, unique = True)
     slug = models.SlugField(allow_unicode = True, unique = True)
     description = models.CharField(max_length = 5000, blank = True, default = '')
     description_html = models.TextField(editable = False, blank = True, default = '')  # Cannot be Edited
     members = models.ManyToManyField(User, through = 'GroupMember')
Views.py
 class CreatePostInGroup(LoginRequiredMixin, SelectRelatedMixin, generic.CreateView):
    model = Post
    fields = ['title', 'post_text']
    template_name = 'posts/post_in_group_form.html'
    def get(self, request, *args, **kwargs):
        print(self.kwargs)
        print(type(self.request.user))
        self.form_group = get_object_or_404(Group, slug=self.kwargs.get('slug'))
        print(type(self.form_group))
        return super(CreatePostInGroup, self).get(request, *args, **kwargs)
    def form_valid(self, form):
        form.instance.user = self.request.user
        try:
            form.instance.group = self.form_group
        except:
            return Http404
        return super(CreatPostInGroup, self).form_valid(form)
    def get_context_data(self, *args, **kwargs):
        context = super(CreatePostInGroup, self).get_context_data(*args, **kwargs)
        context['group'] = Group.objects.get(slug=self.kwargs.get('slug'))
        return context
Thank you for any help, this has been driving me nuts!
 
    