As Pankaj mentioned, add a field in your model called status or something
like that. On the makemigrations set all status as 'Active'

Then, your function will not delete, will update the object.

def delete(request,id):
        employee=Employee.objects.get(id=id)
        employee.status = 'Inactive'
        return redirect('/home1')

in your listview, you should only show active records, for that add an
exclude to the queryset.

queryset = Model.objects.exclude(status='Inactive')

or with a filter

queryset = Model.objects.filter(status='Active')


If you want to use delete, I've used before django-simple-history. the
package records all history for models and objects and let you query that
information.


Regards,

Julio Cojom.




El vie., 7 de enero de 2022 9:48 a. m., Feroz Ahmed <feroz.r...@gmail.com>
escribió:

> Hi, Pankaj
> thanks for the tips!
>
> i try all the way,
> it not success , any syntax please.
> mean time i success to delete the record code as below: (but i just want
> to inactive the record of particular employee) history might need for audit
> purpose.
>
> def delete(request,id):
>         employee=Employee.objects.get(id=id)
>         employee.delete()
>         return redirect('/home1')
>
> Regards
>
>
>
> On Friday, January 7, 2022 at 7:29:18 PM UTC+5:30 pankajpal...@gmail.com
> wrote:
>
>> Then simply make that records inactive by adding one flag in table and
>> instead of deleting make It inactive
>>
>> On Fri, 7 Jan, 2022, 7:22 pm Feroz Ahmed, <feroz...@gmail.com> wrote:
>>
>>> Hi,
>>> How to delete user salary record , but want to keep history till deleted
>>> date.
>>>
>>> ex:
>>>
>>>    1. Month June
>>>    2. Month July
>>>    3. Month Aug
>>>    4. delete user record from Sep.
>>>
>>> --
>>> 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/f2ba2f5f-ed12-45e5-8d2a-d2b1b2590154n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/f2ba2f5f-ed12-45e5-8d2a-d2b1b2590154n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> 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/7ebc8721-d3c1-4f2b-8c18-384820a8483fn%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/7ebc8721-d3c1-4f2b-8c18-384820a8483fn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAHRQUHkcR3tbfrnZM_kQdCEq4Q_E3Rb1%3DOycXp3X28Ay0rWgNw%40mail.gmail.com.

Reply via email to