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;








0















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 ?










share|improve this question






















  • 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











  • 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

















0















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 ?










share|improve this question






















  • 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











  • 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













0












0








0








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 ?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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











  • 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












  • @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











  • 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












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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved