Single records but from listview

On Sun, Jun 7, 2020, 8:30 AM wongX Ndeso <[email protected]> wrote:

> So what you mean is bulk delete?  Is that what you asking?
>
> On Sun, Jun 7, 2020, 6:48 PM Nader Elsisi <[email protected]> wrote:
>
>> Thanks I hope you get what I am asking for. I want to be able to delete
>> from the list. Not one object. Also, l want one function for different
>> models.
>> I am doing it now but I need to improve it. So l asked for help.
>>
>> On Sun, Jun 7, 2020, 6:40 AM wongX Ndeso <[email protected]> wrote:
>>
>>> If you use django to perform some delete action, or others like create
>>> or update, please make sure you have csrf_token in your html form file, and
>>> then you should filter if the form is valid or not, then you can process
>>> the data that send from delete page.
>>>
>>>
>>> On Sat, Jun 6, 2020, 3:48 AM Nader Elsisi <[email protected]> wrote:
>>>
>>>> I have just posted
>>>>
>>>>
>>>> https://stackoverflow.com/questions/62218886/django-tables-2-delete-column-and-delete-item-for-inherited-tables
>>>>
>>>>
>>>> and didn't get any feedback yet. So I appreciate anyone who can help me
>>>>
>>>> about passing data.
>>>>
>>>>
>>>> I want to have one abstract function for all my tablelists (one for
>>>> each model) and (one delete_item) function in view.
>>>>
>>>> I don't know how to make the delete (column in this table) and pass the
>>>> model to the delete_item function in the view
>>>>
>>>> *Tables.py*
>>>>
>>>>
>>>>     ############ Abstract Table
>>>>     class abs_Table(tables.Table):
>>>>
>>>>     SN = tables.Column(empty_values=(), orderable=False)
>>>>     delete = tables.LinkColumn('delete_item', args=[A('pk'), 
>>>> ?????Model???],  attrs={
>>>>          'a': {'class': 'btn btn-small btn-dark'}
>>>>     # })
>>>>
>>>>
>>>>     def __init__(self, *args, **kwargs):
>>>>         super(abs_Table, self).__init__(*args, **kwargs)
>>>>         self.counter = itertools.count(1)
>>>>
>>>>
>>>>     def render_SN(self, record):
>>>>
>>>>         pg = getattr(self, 'paginator', None)
>>>>         if pg:
>>>>             v = next(self.counter)
>>>>             return v + self.paginator.per_page * (self.page.number-1)
>>>>         else:
>>>>             return next(self.counter)
>>>>
>>>>
>>>>     class Meta:
>>>>         model = None
>>>>         fields = [ 'SN', 'id',  'delete', ]
>>>>
>>>>         attrs = {"class": "table-striped table-bordered", 'width': '100%'}
>>>>         empty_text = "There are no Records matching the search criteria..."
>>>>
>>>> Then for model Table
>>>>
>>>> *Tables.py*
>>>>
>>>>
>>>>     class ModelTable(abs_Table):
>>>>
>>>>
>>>>     class Meta(abs_Table.Meta):
>>>>         model = modelname
>>>>         fields = abs_Table.Meta.fields+[selected_model_fields]
>>>>
>>>> *Views.py*
>>>>
>>>>
>>>>
>>>>       def delete_item(request, pk, delmodel):
>>>>         obj = get_object_or_404(delmodel, id=pk)
>>>>
>>>>
>>>>         if request.method == "POST":
>>>>
>>>>                     obj.delete()
>>>>
>>>>             return redirect("../")
>>>>         else:
>>>>             pass
>>>>
>>>>
>>>>         context = {
>>>>             'object': obj
>>>>         }
>>>>
>>>>         return render(request, '/delete_confirmation.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 [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CA%2BkREvqnPgZ9z9j93PVd32F6dGcdtFe1dNuPkA--qx6YecJEOQ%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CA%2BkREvqnPgZ9z9j93PVd32F6dGcdtFe1dNuPkA--qx6YecJEOQ%40mail.gmail.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 [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAJepfJUUe3t59Hav99ZD-CaVyvMUCOg4CVr2pC9Yknjyqh8-ZA%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAJepfJUUe3t59Hav99ZD-CaVyvMUCOg4CVr2pC9Yknjyqh8-ZA%40mail.gmail.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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CA%2BkREvq6%2B5OE60rmPLEULmP1pnteuKgy5fsb4OZf6P4ETcTJpQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CA%2BkREvq6%2B5OE60rmPLEULmP1pnteuKgy5fsb4OZf6P4ETcTJpQ%40mail.gmail.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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJepfJWBkfuttxHRQ9iJNg_AFjEytP7jWZQ4q-83i%2BFS-Aq6mQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAJepfJWBkfuttxHRQ9iJNg_AFjEytP7jWZQ4q-83i%2BFS-Aq6mQ%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BkREvqOof%2BR%3DErYthFJAj4rRo4c8we80dG0eUxNthBnWgK7Lw%40mail.gmail.com.

Reply via email to