[Answered ]-Trouble Inheriting a function that renders data in a class containg a django generic view

1👍

You can’t do it like this.

What indexx does is render the template entries/entries.html with the context {"ents" : entry} and return that as an HttpResponse object.

It’s basically a ListView.

I’m not sure from the description what you want to accomplish. A CreateView is creating a new object. If you want to display all objects of that type including the new one after it is created, you would add to the CreateView a get_success_url method to redirect to the list view:

def get_success_url(self):
    return reverse( 'app:indexx_url_name')

or since this doesn’t have any args or kwaygs it can be simplified to

success_url = reverse_lazy( 'app:indexx_url_name')

(If you use plain reverse, you are likely to get horrible circular import errors, quite possible later when you edit something with no obvious connection to this cause)

The other thing you might do if you want a display of a list of objects which do exist while creating the new one, is to render the list in the template of the create view. You’ll need to pass the list of objects as ents to the create view’s context:

def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['ents'] = Entry.objects.all()
     return context

and then you can do the same in the CreateView as you did in indexx’s template using Django template language.

Leave a comment