How to Update Database

16 views
Skip to first unread message

Aayush Bhattarai

unread,
Apr 26, 2019, 9:53:20 AM4/26/19
to Django users
How can I update database. I am not using forms.py and I am using function based view. Can you how example and link for docs. Thanks for help.

Matthew Pava

unread,
Apr 26, 2019, 10:01:10 AM4/26/19
to django...@googlegroups.com

You would use the data from request.POST or request.GET.

Here’s everything you need to know about views:

https://docs.djangoproject.com/en/2.2/topics/http/views/

 

Here’s an example:

 

def my_view(request):

               if request.POST:

                              field1 = request.POST.get(‘field1’)

                              field2 = request.POST.get(‘field2’)

                              model = MyModel.objects.create(field1=field1, field2=field2)

                              return redirect(model.get_absolute_url())

               return whatever

--
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 post to this group, send email to django...@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/41384b09-ed76-4485-9518-8dc10e26f2fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages