Hi Ciuni,

Maybe your url already is path('updateTabacchi/<tabacchi_id>', I think
question is {{ form }}.
{{ form }} is to render fields without id. Add the <input /> if you want to
get the id from request.POST:

<form class="form-horizontal" role="form" method="POST">
    {% csrf_token %}

    <input name="tabacchi_id" value="{{ tabacchi.id }}" />

    {{ form}}



On Fri, Feb 8, 2019 at 4:30 PM Giuseppe Ciuni <giuseppe.ci...@gmail.com>
wrote:

> Hi guys I'm learning django and I am doing some tests with CRUD using
> crispy forms: I created a model and I can create and read data without any
> problem.
> I have problem in update. I get this error:
>
> postalgps.models.Tabacchino.DoesNotExist: Tabacchino matching query does
> not exist
>
>
>
>
>
> *In model I have:*
>
>
> class Tabacchino(models.Model):
>     nome = models.CharField(max_length=200)
>     cognome = models.CharField(max_length=200)
>     indirizzo = models.CharField(max_length=200)
>     telefono = models.CharField(max_length=30)
>     email= models.CharField(max_length=200)
>     nome_tabacchi = models.CharField(max_length=200)
>     attivo = models.BooleanField(blank=True)  #esiste anche l'opzione 
> null=True
>     pub_date = models.DateTimeField(auto_now_add=True)
>
>
>
>
> *In views.py:*
>
>
> def updateTabacchi(request):
>     query = request.POST.get('tabacchi_id')
>     tabacchi = Tabacchino.objects.get(id=query)
>     form = TabacchinoForm(instance=tabacchi)
>     if form.is_valid():
>         form.save()
>         return redirect('dashboardPage')
>     return render(request, 'tabacchino/admin/update_tabacchi_admin.html', 
> {'form': form, 'tabacchi': tabacchi })
>
>
>
>
> *In urls.py: *
>
>
> urlpatterns = [
>     ....
>     path('updateTabacchi/', views.updateTabacchi, name='updateTabacchiPage'),
>
>     ....
>
>
>
>
> *in forms.py*
>
>
> class TabacchinoForm(forms.ModelForm):
>     nome = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 
> 'xxx'}))
>     cognome = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 
> 'xxx'}))
>     indirizzo = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 
> 'xxx'}))
>     telefono = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 
> 'xxx'}))
>     email = forms.EmailField(widget=forms.TextInput(attrs={'placeholder': 
> 'xxx'}))
>     nome_tabacchi = 
> forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'xxx'}))
>     attivo = forms.BooleanField(required=False)
>     #pub_date = forms.DateTimeField(auto_now_add=True)
>
>     class Meta:
>         model = Tabacchino
>         #fields = "__all__"
>         fields = ['nome', 'cognome', 'indirizzo', 'telefono', 'email', 
> 'nome_tabacchi', 'attivo']
>
>
>
>
>
> *In the template:*
>
>
> <form class="form-horizontal" role="form" method="POST">
>     {% csrf_token %}
>     {{ form}}
>
>     <div class="form-group last">
>        <div class="col-sm-offset-5 col-sm-9">
>            <button type="submit" class="btn btn-success btn-sm">
>               submit </button>
>        </div>
>    </div>
> </form>
>
>
>
>
>
>
>
>
> When I do submit from template I get:
>
>
> postalgps.models.Tabacchino.DoesNotExist: Tabacchino matching query does not 
> exist.
>
> where is the mistake?
>
> Thanks in advance
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7278be12-9dc9-496f-b9d6-63f79fa4873d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/7278be12-9dc9-496f-b9d6-63f79fa4873d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN%2BSpDJVYTW4HDZ_JiuU9D_ih_afHcoM8R6js%2Bf4O4DxusgzOg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to