Get context from another CBV with Django The 2019 Stack Overflow Developer Survey Results Are InHow 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
What to do when moving next to a bird sanctuary with a loosely-domesticated cat?
What did it mean to "align" a radio?
What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?
Worn-tile Scrabble
Delete all lines which don't have n characters before delimiter
Button changing it's text & action. Good or terrible?
Resizing object distorts it (Illustrator CC 2018)
Why do some words that are not inflected have an umlaut?
How can I autofill dates in Excel excluding Sunday?
Have you ever entered Singapore using a different passport or name?
What does ひと匙 mean in this manga and has it been used colloquially?
Do these rules for Critical Successes and Critical Failures seem Fair?
Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?
Where to refill my bottle in India?
Pokemon Turn Based battle (Python)
Why can Shazam fly?
What do the Banks children have against barley water?
FPGA - DIY Programming
Is flight data recorder erased after every flight?
If a Druid sees an animal’s corpse, can they wild shape into that animal?
Can a rogue use sneak attack with weapons that have the thrown property even if they are not thrown?
Why isn't airport relocation done gradually?
Identify boardgame from Big movie
What is the accessibility of a package's `Private` context variables?
Get context from another CBV with Django
The 2019 Stack Overflow Developer Survey Results Are InHow 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
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
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,80212260
2,80212260
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