Django data not being saved in sqlite database

Hello. I am quite new to Django and I am working on this project. I am trying to save a recipe into the database and after correcting a few errors I get the “Success” message. However, when I open the database with the sqlite viewer it shows that the table is empty.

Here is my views file:

from django.http import HttpResponse, HttpResponseRedirect
import json
from django.http import StreamingHttpResponse
from django.shortcuts import render
from django.core.serializers import serialize
from django.http import JsonResponse
from django.template import RequestContext

from .models import StockYeast, queryset_to_indexlist,queryset_to_array, Brew, Fermentable, Miscs, RecipeYeast, Recipes, Yeast,StockFermentables
from .models import Hop,StockHop,StockMiscs

from .forms import RecipeForm, RecipeFermentableForm, RecipeHopForm, RecipeMiscForm,RecipeWaterForm, RecipeYeastForm,RecipeMashForm, StockMiscForm
from .forms import StockFermentableForm,StockHopForm,StockYeastForm, StockMiscForm
from django.forms import formset_factory

def index(request):
    return render(request, 'index.html')

def recipes(request):
    if request.method == 'POST':
        form = RecipeForm(request.POST)
        if form.is_valid():
            n = form.cleaned_data["name"]
            t = Recipes(name=n)
        return HttpResponse("Success")
        recipes = Recipes.objects.all()
        recipeFermentableFormset = formset_factory(RecipeFermentableForm, extra=1)
        recipeHopFormset = formset_factory(RecipeHopForm, extra=1)
        RecipeMiscFormSet= formset_factory(RecipeMiscForm, extra=1)
        RecipeYeastFormSet = formset_factory(RecipeYeastForm,extra=1)
        RecipeMashFormSet = formset_factory(RecipeMashForm,extra=1)
        return render(request, 'recipes.html', {'recipes':recipes,"recipe_form" :RecipeForm(auto_id="recipe_%s"), 
        "recipe_mashformset" :RecipeMashFormSet(prefix='mash'),

Here is my recipes.html:

{% block content %}
<!-- Modal -->


                <div class="card shadow-sm">
                  <div class="card-header" id="headingOne">
                    <h5 class="mb-0"> Receptas</h5>
                  <div id="card-base" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
                    <div class="card-body">
                      <div class="row">
                        <div class="col">
						<form method="post" action="/recipes">
                        {% csrf_token %}
                        <div class="row">
                          <div class="col">{{|as_crispy_field}}</div> 
                          <div class="col">{{|as_crispy_field}}</div>
                        <div class="row">
                          <div class="col">{{recipe_form.batch_size|as_crispy_field}}</div>
                          <div class="col">{{recipe_form.boile_time|as_crispy_field}}</div>
                          <div class="col">{{recipe_form.efficiency|as_crispy_field}}</div>
                        <div class="row">
                          <div class="col">{{recipe_form.primary_age|as_crispy_field}}</div>
                          <div class="col">{{recipe_form.secondary_age|as_crispy_field}}</div>
                          <div class="col">{{recipe_form.age|as_crispy_field}}</div>
                        <div class="row">
                          <div class="col">{{recipe_form.pub_date|as_crispy_field}}</div>
                        <div class="row">
                          <div class="col">{{recipe_form.notes|as_crispy_field}}</div>
					<span class="d-flex flex-row-reverse"><button class="btn btn-secondary" id="save_recipe_btn" type="submit"><i class="bi bi-save"></i></br> Saugoti</button></span>

This is going to be a many to one relationship with recipes and recipefermentables, recipehops and so on. However, for starters I am trying to save just the basic portion of recipe.

Is there something wrong with the code or what could be the reason why the data is not being saved?

You mention that you’re new to Django. How new are you?

For example, have you worked your way through either the official Django tutorial or the Django Girls tutorial?

Have you read the Working with forms docs?

The reason I’m asking is that it appears to me that you’re trying to tackle too much for “just getting started.” My first recommendation would be to scale this back to the absolute minimum. Get rid of all the formsets and everything that is not a Recipe, and focus on that first.

Once you’ve got that working, then you can add those other elements individually, knowing that you have a functional foundation on which to build your more intricate elements.

1 Like

Thank you for the suggestion.
By saying new I mean that I only have some basic knowledge.

Unfortunately, I cannot do that because I’m working on a program which is already in development for my internship. So I have to build on to what I have.

Could you maybe tell me what I would need to put my emphasis on in order to solve this issue?