Get context from another CBV with DjangoHow to get the current time in PythonDoes Django scale?How do I get the number of elements in a list in Python?Django UpdateView with ImageField attributeDjango REST Updateview with PUT POSTDisplay a ListView inside a TabView with DjangoDjango 1.11 TypeError at / context must be a dict rather than unicodeDjango how to save time to the forms?Django 1.11 - CreateView - invalid form raises error for nonexistent object attributeDjango problem with having slug in my url while using a class
Was the picture area of a CRT a parallelogram (instead of a true rectangle)?
Curses work by shouting - How to avoid collateral damage?
Teaching indefinite integrals that require special-casing
How could Frankenstein get the parts for his _second_ creature?
Is HostGator storing my password in plaintext?
Is it correct to write "is not focus on"?
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
Implement the Thanos sorting algorithm
Is there a problem with hiding "forgot password" until it's needed?
Have I saved too much for retirement so far?
Student evaluations of teaching assistants
What would happen if the UK refused to take part in EU Parliamentary elections?
Bash method for viewing beginning and end of file
What to do with wrong results in talks?
Is a roofing delivery truck likely to crack my driveway slab?
Opposite of a diet
How to be diplomatic in refusing to write code that breaches the privacy of our users
Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?
How does it work when somebody invests in my business?
Should my PhD thesis be submitted under my legal name?
How do I rename a LINUX host without needing to reboot for the rename to take effect?
Lay out the Carpet
Failed to fetch jessie backports repository
Mapping a list into a phase plot
Get context from another CBV with Django
How to get the current time in PythonDoes Django scale?How do I get the number of elements in a list in Python?Django UpdateView with ImageField attributeDjango REST Updateview with PUT POSTDisplay a ListView inside a TabView with DjangoDjango 1.11 TypeError at / context must be a dict rather than unicodeDjango how to save time to the forms?Django 1.11 - CreateView - invalid form raises error for nonexistent object attributeDjango problem with having slug in my url while using a class
I would like to get your help in order to use context from a Django CBV in another CBV through get_context_data()
.
Objective:
Basically, I have a django ListView()
with pagination
. I pick up the current page in get_context_data()
. Then, I would like to edit an object, so I'm going to UpdateView()
.
When I post the edit, it should return to the previous pagination. For example, if the object was on page 32, after the POST request
, I need to be redirected to page 32.
My code:
class DocumentListView(AdminMixin, CustomListSearchView):
""" Render the list of document """
def get_context_data(self, **kwargs):
context = super(DocumentListView, self).get_context_data(**kwargs)
actual_page = self.request.GET.get('page', 1)
if actual_page:
context['actual_page'] = actual_page
return context
class DocumentFormView(CustomPermissionRequiredMixin, DocumentListView, UpdateView):
def get_current_page(self, **kwargs):
context = super(DocumentListView, self).get_context_data(**kwargs)
actual_page = context['actual_page']
return actual_page
def get_context_data(self, **kwargs):
context = super(DocumentFormView, self).get_context_data(**kwargs)
print(self.get_current_page())
...
return context
def post(self, request, pk=None):
...
return render(request, 'app/manage_document_form.html', context)
Issue:
I don't overcome to get the actual_page
in my class DocumentFormView
.
I got this issue :
AttributeError: 'DocumentFormView' object has no attribute 'object'
I tried to add in my post()
function :
self.object = self.get_object()
But it doesn't solve the issue.
Do you have any idea ?
python django django-views django-pagination
add a comment |
I would like to get your help in order to use context from a Django CBV in another CBV through get_context_data()
.
Objective:
Basically, I have a django ListView()
with pagination
. I pick up the current page in get_context_data()
. Then, I would like to edit an object, so I'm going to UpdateView()
.
When I post the edit, it should return to the previous pagination. For example, if the object was on page 32, after the POST request
, I need to be redirected to page 32.
My code:
class DocumentListView(AdminMixin, CustomListSearchView):
""" Render the list of document """
def get_context_data(self, **kwargs):
context = super(DocumentListView, self).get_context_data(**kwargs)
actual_page = self.request.GET.get('page', 1)
if actual_page:
context['actual_page'] = actual_page
return context
class DocumentFormView(CustomPermissionRequiredMixin, DocumentListView, UpdateView):
def get_current_page(self, **kwargs):
context = super(DocumentListView, self).get_context_data(**kwargs)
actual_page = context['actual_page']
return actual_page
def get_context_data(self, **kwargs):
context = super(DocumentFormView, self).get_context_data(**kwargs)
print(self.get_current_page())
...
return context
def post(self, request, pk=None):
...
return render(request, 'app/manage_document_form.html', context)
Issue:
I don't overcome to get the actual_page
in my class DocumentFormView
.
I got this issue :
AttributeError: 'DocumentFormView' object has no attribute 'object'
I tried to add in my post()
function :
self.object = self.get_object()
But it doesn't solve the issue.
Do you have any idea ?
python django django-views django-pagination
This isn't at all what you want to do. It doesn't make any sense to usesuper
like that, let alone have two separate methods calling two separate super methods. But quite apart from anything else, the data is coming from the request; if you need the value from thepage
parameter in the form view, it needs to be present in the request for that view.
– Daniel Roseman
Mar 8 at 9:51
@DanielRoseman Ok, but if I understand well the url according to my form view doesn't display any information from pagination inListView()
. So I don't see how I can pick up data from url through aGET
request. In myListView()
, the url looks like this :http://localhost:8000/crud/document/list/?page=72
and in myUpdateView()
:http://localhost:8000/crud/document/update/150/
– Essex
Mar 8 at 9:59
If it's not in the URL there is no way your view can get it. Your code is doubly mistaken in that case. You need to actually include the parameter in the URL you use for the form view.
– Daniel Roseman
Mar 8 at 10:05
Hum ok I have to see how I can do that. Thank you for your explanation anyway !
– Essex
Mar 8 at 10:08
add a comment |
I would like to get your help in order to use context from a Django CBV in another CBV through get_context_data()
.
Objective:
Basically, I have a django ListView()
with pagination
. I pick up the current page in get_context_data()
. Then, I would like to edit an object, so I'm going to UpdateView()
.
When I post the edit, it should return to the previous pagination. For example, if the object was on page 32, after the POST request
, I need to be redirected to page 32.
My code:
class DocumentListView(AdminMixin, CustomListSearchView):
""" Render the list of document """
def get_context_data(self, **kwargs):
context = super(DocumentListView, self).get_context_data(**kwargs)
actual_page = self.request.GET.get('page', 1)
if actual_page:
context['actual_page'] = actual_page
return context
class DocumentFormView(CustomPermissionRequiredMixin, DocumentListView, UpdateView):
def get_current_page(self, **kwargs):
context = super(DocumentListView, self).get_context_data(**kwargs)
actual_page = context['actual_page']
return actual_page
def get_context_data(self, **kwargs):
context = super(DocumentFormView, self).get_context_data(**kwargs)
print(self.get_current_page())
...
return context
def post(self, request, pk=None):
...
return render(request, 'app/manage_document_form.html', context)
Issue:
I don't overcome to get the actual_page
in my class DocumentFormView
.
I got this issue :
AttributeError: 'DocumentFormView' object has no attribute 'object'
I tried to add in my post()
function :
self.object = self.get_object()
But it doesn't solve the issue.
Do you have any idea ?
python django django-views django-pagination
I would like to get your help in order to use context from a Django CBV in another CBV through get_context_data()
.
Objective:
Basically, I have a django ListView()
with pagination
. I pick up the current page in get_context_data()
. Then, I would like to edit an object, so I'm going to UpdateView()
.
When I post the edit, it should return to the previous pagination. For example, if the object was on page 32, after the POST request
, I need to be redirected to page 32.
My code:
class DocumentListView(AdminMixin, CustomListSearchView):
""" Render the list of document """
def get_context_data(self, **kwargs):
context = super(DocumentListView, self).get_context_data(**kwargs)
actual_page = self.request.GET.get('page', 1)
if actual_page:
context['actual_page'] = actual_page
return context
class DocumentFormView(CustomPermissionRequiredMixin, DocumentListView, UpdateView):
def get_current_page(self, **kwargs):
context = super(DocumentListView, self).get_context_data(**kwargs)
actual_page = context['actual_page']
return actual_page
def get_context_data(self, **kwargs):
context = super(DocumentFormView, self).get_context_data(**kwargs)
print(self.get_current_page())
...
return context
def post(self, request, pk=None):
...
return render(request, 'app/manage_document_form.html', context)
Issue:
I don't overcome to get the actual_page
in my class DocumentFormView
.
I got this issue :
AttributeError: 'DocumentFormView' object has no attribute 'object'
I tried to add in my post()
function :
self.object = self.get_object()
But it doesn't solve the issue.
Do you have any idea ?
python django django-views django-pagination
python django django-views django-pagination
asked Mar 8 at 9:45
EssexEssex
2,73512159
2,73512159
This isn't at all what you want to do. It doesn't make any sense to usesuper
like that, let alone have two separate methods calling two separate super methods. But quite apart from anything else, the data is coming from the request; if you need the value from thepage
parameter in the form view, it needs to be present in the request for that view.
– Daniel Roseman
Mar 8 at 9:51
@DanielRoseman Ok, but if I understand well the url according to my form view doesn't display any information from pagination inListView()
. So I don't see how I can pick up data from url through aGET
request. In myListView()
, the url looks like this :http://localhost:8000/crud/document/list/?page=72
and in myUpdateView()
:http://localhost:8000/crud/document/update/150/
– Essex
Mar 8 at 9:59
If it's not in the URL there is no way your view can get it. Your code is doubly mistaken in that case. You need to actually include the parameter in the URL you use for the form view.
– Daniel Roseman
Mar 8 at 10:05
Hum ok I have to see how I can do that. Thank you for your explanation anyway !
– Essex
Mar 8 at 10:08
add a comment |
This isn't at all what you want to do. It doesn't make any sense to usesuper
like that, let alone have two separate methods calling two separate super methods. But quite apart from anything else, the data is coming from the request; if you need the value from thepage
parameter in the form view, it needs to be present in the request for that view.
– Daniel Roseman
Mar 8 at 9:51
@DanielRoseman Ok, but if I understand well the url according to my form view doesn't display any information from pagination inListView()
. So I don't see how I can pick up data from url through aGET
request. In myListView()
, the url looks like this :http://localhost:8000/crud/document/list/?page=72
and in myUpdateView()
:http://localhost:8000/crud/document/update/150/
– Essex
Mar 8 at 9:59
If it's not in the URL there is no way your view can get it. Your code is doubly mistaken in that case. You need to actually include the parameter in the URL you use for the form view.
– Daniel Roseman
Mar 8 at 10:05
Hum ok I have to see how I can do that. Thank you for your explanation anyway !
– Essex
Mar 8 at 10:08
This isn't at all what you want to do. It doesn't make any sense to use
super
like that, let alone have two separate methods calling two separate super methods. But quite apart from anything else, the data is coming from the request; if you need the value from the page
parameter in the form view, it needs to be present in the request for that view.– Daniel Roseman
Mar 8 at 9:51
This isn't at all what you want to do. It doesn't make any sense to use
super
like that, let alone have two separate methods calling two separate super methods. But quite apart from anything else, the data is coming from the request; if you need the value from the page
parameter in the form view, it needs to be present in the request for that view.– Daniel Roseman
Mar 8 at 9:51
@DanielRoseman Ok, but if I understand well the url according to my form view doesn't display any information from pagination in
ListView()
. So I don't see how I can pick up data from url through a GET
request. In my ListView()
, the url looks like this : http://localhost:8000/crud/document/list/?page=72
and in my UpdateView()
: http://localhost:8000/crud/document/update/150/
– Essex
Mar 8 at 9:59
@DanielRoseman Ok, but if I understand well the url according to my form view doesn't display any information from pagination in
ListView()
. So I don't see how I can pick up data from url through a GET
request. In my ListView()
, the url looks like this : http://localhost:8000/crud/document/list/?page=72
and in my UpdateView()
: http://localhost:8000/crud/document/update/150/
– Essex
Mar 8 at 9:59
If it's not in the URL there is no way your view can get it. Your code is doubly mistaken in that case. You need to actually include the parameter in the URL you use for the form view.
– Daniel Roseman
Mar 8 at 10:05
If it's not in the URL there is no way your view can get it. Your code is doubly mistaken in that case. You need to actually include the parameter in the URL you use for the form view.
– Daniel Roseman
Mar 8 at 10:05
Hum ok I have to see how I can do that. Thank you for your explanation anyway !
– Essex
Mar 8 at 10:08
Hum ok I have to see how I can do that. Thank you for your explanation anyway !
– Essex
Mar 8 at 10:08
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060524%2fget-context-from-another-cbv-with-django%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060524%2fget-context-from-another-cbv-with-django%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This isn't at all what you want to do. It doesn't make any sense to use
super
like that, let alone have two separate methods calling two separate super methods. But quite apart from anything else, the data is coming from the request; if you need the value from thepage
parameter in the form view, it needs to be present in the request for that view.– Daniel Roseman
Mar 8 at 9:51
@DanielRoseman Ok, but if I understand well the url according to my form view doesn't display any information from pagination in
ListView()
. So I don't see how I can pick up data from url through aGET
request. In myListView()
, the url looks like this :http://localhost:8000/crud/document/list/?page=72
and in myUpdateView()
:http://localhost:8000/crud/document/update/150/
– Essex
Mar 8 at 9:59
If it's not in the URL there is no way your view can get it. Your code is doubly mistaken in that case. You need to actually include the parameter in the URL you use for the form view.
– Daniel Roseman
Mar 8 at 10:05
Hum ok I have to see how I can do that. Thank you for your explanation anyway !
– Essex
Mar 8 at 10:08