Try django generic edit view (CBV).
You can use DeleteView Class to perform what you need to do..

On Sat, Jun 6, 2020, 3:48 AM Nader Elsisi <naderels...@gmail.com> 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 django-users+unsubscr...@googlegroups.com.
> 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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJepfJWUvwyMpsVCepg_ToZqbo3SjP2cuRJ4HR3hyCsVxVtEyw%40mail.gmail.com.

Reply via email to