Tuesday, September 26, 2023

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

J'ai finalement résolu le problème. Merci bien!! 

Le lundi 25 septembre 2023 à 20:35:25 UTC, Muhammed Lawal a écrit :
Have you confirmed there is a 'name' field in your CentreCategorie and Region models? 

On Mon, 25 Sep 2023, 5:44 p.m. Baye SALIOU DIAW, <bayesalio...@gmail.com> wrote:
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)

--
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.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/84da2aca-062f-4c10-9f7f-4bdf3e48c0ffn%40googlegroups.com.

No comments:

Post a Comment