title: How do you create model objects in a Django view?
body: <p>I know how to create model objects via a submitted form, but I'm wondering how to create objects in a view without having to go through a form. I'm aware that this can be done via the shell, but I have different reasons for doing it in the view.</p>
  <p>As an example let's say I have a blog table that has a title and a body. How would I create a new object that sets the fields of the title and body?</p>
  <pre><code>def create_blog(request):
      # Create a new blog object.
      blog_obj.title= &quot;First Blog&quot;
      blog_obj.body= &quot;This is the body&quot;
  </code></pre>
  <p>Update:
  Here is my model.py</p>
  <pre><code>from django.db import models 
  
  class Rating(models.Model):
      movie_name= models.CharField(max_length=100)
      total_ratings = models.IntegerField()
      total_rating_value = models.IntegerField()
      rating_average = models.DecimalField(max_digits=2, decimal_places=2)
  </code></pre>
  <p>Update 2:
  when I try saving my object it returns an error (class 'decimal.InvalidOperation'). rating_average is a Decimal_field.
  This is my actual object:</p>
  <pre><code>rating_obj = Rating(movie_name=&quot;Test Movie&quot;, total_ratings=1, total_rating_value= 5, rating_average= 5.0)
  </code></pre>