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













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




2,73512159












  • 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

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived