I have just postedÂ
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BkREvqnPgZ9z9j93PVd32F6dGcdtFe1dNuPkA--qx6YecJEOQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJepfJUUe3t59Hav99ZD-CaVyvMUCOg4CVr2pC9Yknjyqh8-ZA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BkREvq6%2B5OE60rmPLEULmP1pnteuKgy5fsb4OZf6P4ETcTJpQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJepfJWBkfuttxHRQ9iJNg_AFjEytP7jWZQ4q-83i%2BFS-Aq6mQ%40mail.gmail.com.