Hi,

New to Django, and am really really struggling which something maybe others 
may find really easy..

I've created a custom database model, and the subsequent modelform template 
to enable creating a record and storing to database.
However I am struggling to create two instances, where the user, retrieves 
a specific record created by them and can edit or delete this via a 
template.

My setup is as follows:

I have a url. In the body I have called each of the record to display with 
the objects. I then added a button for edit and delete to each record.

My thought process was if the user presses the edit button, the user is 
directed to a URL which enables them to edit any of the existing objects 
details
specifically around that record, and the edit url recognises the PK, and 
takes the user to only edit that record with that PK.
Once in the modelform, they can see all the object related data, i.e name = 
John , Surname = Smith ... they can then change the data, and submit it 
to the database. The record is then stored with new data and same PK, into 
the databse and the user is then 
redirected  to the records overview page, to determine the next step, edit 
another record or delete.


-- This is my button setup for the edit -

template.

<div>
  <a href="{% /editbusiness %}" type="button" class="btn btn-primary 
btn-sm">Edit</button"></a>


--- This is url path to get to the edit record url ---


path('Business register/Business management/Admin/Edit or remove 
business/editbusiness', views.editbusiness, name='editbusiness'),

--- This is the view I have created to extract retrieve the post request 
and render it to the editing template, 


def editbusiness(request):
data = Businessownercreate.objects.all() 
if request.method == "POST": 
form = Businessownercreate(request.POST, instance=instance)

if form.is_valid():
form.save()
return redirect("accounts:editremovebusiness")
else:
form =  forms.Businessownercreate()
args = { "form": form }
return render(request, 'editbusiness.html', args)

--- This is the template that allows the user to edit the record via a 
modelform, based on the original Businessownercreate form, which just 
creates the nentity record.

{% load static %}


    <div class="container">
    <br>

        <form method="POST">
            {% csrf_token %}
                {{form.as_p}}

    <br>                
        <button class="btn" type = "submit">submit</button>    
    </form>

Sorry for the long mail, and the detail, but it's tough starting out with a 
project, and im jut trying to grow and learn.
Please can anyone provide any guidance on how I can resolve to pull the 
data to the edit modelform from the database and save the data, with final 
redirect.

Best,

K


-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/451152f3-3582-4e91-a2ba-3cf56e89329e%40googlegroups.com.

Reply via email to