Django UpdateView without form to update object
I am using class based views with django 1.9 and I am trying to figure out how to update an object(After clicking a button) without using the form. I do not need any user input to update the object. Can you help me?
In models.py
class State(models.Model):
stateID = models.SmallIntegerField(primary_key=True)
isOpen = models.BooleanField(default=True, help_text='Designates whether the registration is open.', verbose_name='active')
def __unicode__(self):
return bool(self.isOpen)
In views.py
class OpenTournament(View):
model = State
def get(self, request, *args, **kwargs):
queryset = State.objects.all()
if queryset.count() != 1:
State(stateID=1, isOpen=True).save()
return HttpResponseRedirect('/success_url/')
else:
#need to update the table from a button click
return HttpResponseRedirect("/updated/")
python mysql django
|
show 3 more comments
I am using class based views with django 1.9 and I am trying to figure out how to update an object(After clicking a button) without using the form. I do not need any user input to update the object. Can you help me?
In models.py
class State(models.Model):
stateID = models.SmallIntegerField(primary_key=True)
isOpen = models.BooleanField(default=True, help_text='Designates whether the registration is open.', verbose_name='active')
def __unicode__(self):
return bool(self.isOpen)
In views.py
class OpenTournament(View):
model = State
def get(self, request, *args, **kwargs):
queryset = State.objects.all()
if queryset.count() != 1:
State(stateID=1, isOpen=True).save()
return HttpResponseRedirect('/success_url/')
else:
#need to update the table from a button click
return HttpResponseRedirect("/updated/")
python mysql django
We need a little bit more context. Do you want to update the object through an AJAX call? Please update the question with all the details in order to get a response.
– Alex
Nov 23 '18 at 9:15
You need to post the code and the error.
– Daniel Roseman
Nov 23 '18 at 9:21
There is a table with a boolean field in my models.py. I need to change that field's value from a button click. Thanks in advance.
– Chamoda Jeewantha
Nov 23 '18 at 9:25
That does not help at all. You need to show the code.
– Daniel Roseman
Nov 23 '18 at 9:27
@DanielRoseman Edited the question with the code.
– Chamoda Jeewantha
Nov 23 '18 at 9:36
|
show 3 more comments
I am using class based views with django 1.9 and I am trying to figure out how to update an object(After clicking a button) without using the form. I do not need any user input to update the object. Can you help me?
In models.py
class State(models.Model):
stateID = models.SmallIntegerField(primary_key=True)
isOpen = models.BooleanField(default=True, help_text='Designates whether the registration is open.', verbose_name='active')
def __unicode__(self):
return bool(self.isOpen)
In views.py
class OpenTournament(View):
model = State
def get(self, request, *args, **kwargs):
queryset = State.objects.all()
if queryset.count() != 1:
State(stateID=1, isOpen=True).save()
return HttpResponseRedirect('/success_url/')
else:
#need to update the table from a button click
return HttpResponseRedirect("/updated/")
python mysql django
I am using class based views with django 1.9 and I am trying to figure out how to update an object(After clicking a button) without using the form. I do not need any user input to update the object. Can you help me?
In models.py
class State(models.Model):
stateID = models.SmallIntegerField(primary_key=True)
isOpen = models.BooleanField(default=True, help_text='Designates whether the registration is open.', verbose_name='active')
def __unicode__(self):
return bool(self.isOpen)
In views.py
class OpenTournament(View):
model = State
def get(self, request, *args, **kwargs):
queryset = State.objects.all()
if queryset.count() != 1:
State(stateID=1, isOpen=True).save()
return HttpResponseRedirect('/success_url/')
else:
#need to update the table from a button click
return HttpResponseRedirect("/updated/")
python mysql django
python mysql django
edited Nov 23 '18 at 9:35
Chamoda Jeewantha
asked Nov 23 '18 at 9:08
Chamoda JeewanthaChamoda Jeewantha
177
177
We need a little bit more context. Do you want to update the object through an AJAX call? Please update the question with all the details in order to get a response.
– Alex
Nov 23 '18 at 9:15
You need to post the code and the error.
– Daniel Roseman
Nov 23 '18 at 9:21
There is a table with a boolean field in my models.py. I need to change that field's value from a button click. Thanks in advance.
– Chamoda Jeewantha
Nov 23 '18 at 9:25
That does not help at all. You need to show the code.
– Daniel Roseman
Nov 23 '18 at 9:27
@DanielRoseman Edited the question with the code.
– Chamoda Jeewantha
Nov 23 '18 at 9:36
|
show 3 more comments
We need a little bit more context. Do you want to update the object through an AJAX call? Please update the question with all the details in order to get a response.
– Alex
Nov 23 '18 at 9:15
You need to post the code and the error.
– Daniel Roseman
Nov 23 '18 at 9:21
There is a table with a boolean field in my models.py. I need to change that field's value from a button click. Thanks in advance.
– Chamoda Jeewantha
Nov 23 '18 at 9:25
That does not help at all. You need to show the code.
– Daniel Roseman
Nov 23 '18 at 9:27
@DanielRoseman Edited the question with the code.
– Chamoda Jeewantha
Nov 23 '18 at 9:36
We need a little bit more context. Do you want to update the object through an AJAX call? Please update the question with all the details in order to get a response.
– Alex
Nov 23 '18 at 9:15
We need a little bit more context. Do you want to update the object through an AJAX call? Please update the question with all the details in order to get a response.
– Alex
Nov 23 '18 at 9:15
You need to post the code and the error.
– Daniel Roseman
Nov 23 '18 at 9:21
You need to post the code and the error.
– Daniel Roseman
Nov 23 '18 at 9:21
There is a table with a boolean field in my models.py. I need to change that field's value from a button click. Thanks in advance.
– Chamoda Jeewantha
Nov 23 '18 at 9:25
There is a table with a boolean field in my models.py. I need to change that field's value from a button click. Thanks in advance.
– Chamoda Jeewantha
Nov 23 '18 at 9:25
That does not help at all. You need to show the code.
– Daniel Roseman
Nov 23 '18 at 9:27
That does not help at all. You need to show the code.
– Daniel Roseman
Nov 23 '18 at 9:27
@DanielRoseman Edited the question with the code.
– Chamoda Jeewantha
Nov 23 '18 at 9:36
@DanielRoseman Edited the question with the code.
– Chamoda Jeewantha
Nov 23 '18 at 9:36
|
show 3 more comments
1 Answer
1
active
oldest
votes
Yes. I found it. Access the State by primary key
open = State.objects.get(id=1)
open.isOpen = True
post.save()
add a comment |
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%2f53443578%2fdjango-updateview-without-form-to-update-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yes. I found it. Access the State by primary key
open = State.objects.get(id=1)
open.isOpen = True
post.save()
add a comment |
Yes. I found it. Access the State by primary key
open = State.objects.get(id=1)
open.isOpen = True
post.save()
add a comment |
Yes. I found it. Access the State by primary key
open = State.objects.get(id=1)
open.isOpen = True
post.save()
Yes. I found it. Access the State by primary key
open = State.objects.get(id=1)
open.isOpen = True
post.save()
answered Nov 23 '18 at 10:22
Chamoda JeewanthaChamoda Jeewantha
177
177
add a comment |
add a comment |
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%2f53443578%2fdjango-updateview-without-form-to-update-object%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
We need a little bit more context. Do you want to update the object through an AJAX call? Please update the question with all the details in order to get a response.
– Alex
Nov 23 '18 at 9:15
You need to post the code and the error.
– Daniel Roseman
Nov 23 '18 at 9:21
There is a table with a boolean field in my models.py. I need to change that field's value from a button click. Thanks in advance.
– Chamoda Jeewantha
Nov 23 '18 at 9:25
That does not help at all. You need to show the code.
– Daniel Roseman
Nov 23 '18 at 9:27
@DanielRoseman Edited the question with the code.
– Chamoda Jeewantha
Nov 23 '18 at 9:36