FieldError at /ajouter_centre Cannot resolve keyword 'name' into field. Choices are: categorie, centredeformation, date_de_crea, id

39 views
Skip to first unread message

Baye SALIOU DIAW

unread,
Sep 25, 2023, 4:44:50 PM9/25/23
to Django users
def ajouterCentre(request):
    form = FormCentre()
    regions = Region.objects.all()
    centrecategories = CentreCategorie.objects.all()
    if request.method == 'POST':

       
        categorie_name = request.POST.get('categorie')
        categorie, created = CentreCategorie.objects.get_or_create(name=categorie_name)

        region_name = request.POST.get('region')
        region, created = Region.objects.get_or_create(name=region_name)
       
        CentreDeFormation.objects.create(
            categorie=request.categorie,
            region = region,
            nom = request.POST.get('nom'),
            description = request.POST.get('description'),
            adresse = request.POST.get('adresse'),
            telephone = request.POST.get('telephone'),
        )

        return redirect('home')


    context = {
        'form': form,
        'regions': regions,
        'centrecategories': centrecategories,
    }
    return render(request, 'blog/ajoutercentre.html', context)

Dino P.Russe

unread,
Sep 25, 2023, 8:04:53 PM9/25/23
to django...@googlegroups.com
Si tu pouvais aussi envoyer le code du modèle et du formulaire,  je pense bien que ton problème sera très rapidement 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8a202205-cf75-4445-9642-e995fec56833n%40googlegroups.com.

Muhammed Lawal

unread,
Sep 25, 2023, 8:35:25 PM9/25/23
to django...@googlegroups.com
Have you confirmed there is a 'name' field in your CentreCategorie and Region models? 

--

Baye SALIOU DIAW

unread,
Sep 26, 2023, 9:58:58 AM9/26/23
to Django users
J'ai finalement résolu le problème. Merci bien!! 
Reply all
Reply to author
Forward
0 new messages