Update value in database

2019-12-19 Thread Nuno Vieira
Hi!

I have a real estate django app and i have a form to users insert a new 
property. I also have in the form several images fields that users can use 
to upload images to database whitout problem. 
The problem is if the *user want to delete one of the images field.*

I have an ajax request that sends the id of the property and the field name 
to update (delete) on database.

function delete_img(i){
  var prim_key = document.getElementById('list_id').value;
  var id_number = i.id;

   $.ajax({
  type: 'GET',
  url: '',
  data: {'csrfmiddlewaretoken' : "{{  csrf_token  }}",
'img_id':id_number , 'post_id':prim_key },
  success: function(data){
  if(data) {
   console.log(id_number + " " + prim_key);
   document.getElementById('img_' + id_number).src = 
"http://localhost:8000/media/upload_img_default.png;;
  }
   
 
}
});

In views.py i have a function that receives the data from ajax and executes 
the task.

@csrf_exempt
def delete_img(request):
if request.method=='GET' and request.is_ajax():
img_id = request.GET['img_id']
post_id = request.GET['post_id']
try:
obj = Listing.objects.get(id=post_id)
obj1 = getattr(obj,img_id) 
obj1.value = None
obj.save()
return True
except Listing.DoesNotExist:
return False
else:
return False


Can anyone help me with this situation?
Thanks for your help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9cb23263-95e4-4060-b855-09a0e30cb89d%40googlegroups.com.


Trying to add radio button and store its value in database.. Django

2019-06-02 Thread abb
https://stackoverflow.com/questions/56407153/radio-button-with-default-selection-in-django
 

Not understanding where am i going wrong here.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b54cb2eb-1de6-4619-aab6-5957a12ef4c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to Save form to mysql - How to save form field values to mysql database and get the value from database

2018-07-02 Thread Andréas Kühne
In your views file, you don't have any index method - that's what the error
is saying. So you need to solve the url mapping for your index method.

Regards,

Andréas

2018-07-02 5:55 GMT+02:00 Tamilvanan Anbalagan :

> Hi Team,
>
> I am very new to django framework, iI am trying to using simple forms to
> save into mysql database. also any samples pls send it to me, which will
> help to understand the connectivity.
>
> *see my sample code:*
>
>
> *views.py*
>
> from django.http import HttpResponseRedirect
> from django.views import View
> from django.shortcuts import render
>
> from .forms import NameForm
>
> def get_name(request):
> # if this is a POST request we need to process the form data
> if request.method == 'POST':
> # create a form instance and populate it with data from the request:
> form = NameForm(request.POST)
> # check whether it's valid:
> if form.is_valid():
> # process the data in form.cleaned_data as required
> # ...
> # redirect to a new URL:
> return HttpResponseRedirect('/thanks/')
>
> # if a GET (or any other method) we'll create a blank form
> else:
> form = NameForm()
>
> return render(request, 'portal/index.html', {'form': form})
>
>
> djangoproject/urls.py
>
> from django.contrib import admin
> from django.urls import path, include
> #from django.conf.urls import url, include
>
> urlpatterns = [
> path('admin/', admin.site.urls),
> path('portal/', include('portal.urls')),
> #url(r'^portal/', include('portal.urls'))
> ]
>
>
> *forms.py*
>
> from django import forms
>
> # class NameForm(forms.Form):
> # your_name = forms.CharField(label='Your name', max_length=100)
>
>
> *urls.py*
>
> from django.conf.urls import url
> from . import views
>
> urlpatterns = [
> url(r'^$', views.index, name='index')
> ]
>
> *Error message:*
>
>
>
> (py1) c:\TransportPortal\djangoproject>python manage.py runserver
> Performing system checks...
>
> Unhandled exception in thread started by  check_errors..wrappe
>  at 0x0355E4F8>
> Traceback (most recent call last):
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\
> utils\autoreload.py"
>  line 225, in wrapper
> fn(*args, **kwargs)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> management\comm
> nds\runserver.py", line 120, in inner_run
> self.check(display_num_errors=True)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> management\base
> py", line 364, in check
> include_deployment_checks=include_deployment_checks,
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> management\base
> py", line 351, in _run_checks
> return checks.run_checks(**kwargs)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> checks\registry
> py", line 73, in run_checks
> new_errors = check(app_configs=app_configs)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> checks\urls.py"
>  line 13, in check_url_config
> return check_resolver(resolver)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> checks\urls.py"
>  line 23, in check_resolver
> return check_method()
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\
> resolvers.py",
> ine 399, in check
> for pattern in self.url_patterns:
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\
> utils\functional.py"
>  line 36, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\
> resolvers.py",
> ine 540, in url_patterns
> patterns = getattr(self.urlconf_module, "urlpatterns",
> self.urlconf_module)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\
> utils\functional.py"
>  line 36, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\
> resolvers.py",
> ine 533, in urlconf_module
> return import_module(self.urlconf_name)
>   File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126,
> in impo
> t_module
> return _bootstrap._gcd_import(name[level:], package, level)
>   File "", line 994, in _gcd_import
>   File "", line 971, in _find_and_load
>   File "", line 955, in
> _find_and_load_unlocked
>   File "", line 665, in _load_unlocked
>   File "", line 678, in exec_module
>   File "", line 219, in
> _call_with_frames_removed
>   File "c:\TransportPortal\djangoproject\djangoproject\urls.py", line 22,
> in  dule>
> path('portal/', include('portal.urls')),
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\conf.py",
> line
> 4, in include
> urlconf_module = import_module(urlconf_module)
>   File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126,
> in impo
> t_module
> return _bootstrap._gcd_import(name[level:], package, level)
>   File "", line 994, in _gcd_import
>   File "", line 971, in _find_and_load
>   File "", line 955, in
> _find_and_load_unlocked
>   File "", line 665, in _load_unlocked
>   File "", 

Unable to Save form to mysql - How to save form field values to mysql database and get the value from database

2018-07-02 Thread Tamilvanan Anbalagan
Hi Team,

I am very new to django framework, iI am trying to using simple forms to 
save into mysql database. also any samples pls send it to me, which will 
help to understand the connectivity.

*see my sample code:*


*views.py*

from django.http import HttpResponseRedirect
from django.views import View
from django.shortcuts import render

from .forms import NameForm

def get_name(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = NameForm(request.POST)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
return HttpResponseRedirect('/thanks/')

# if a GET (or any other method) we'll create a blank form
else:
form = NameForm()

return render(request, 'portal/index.html', {'form': form})


djangoproject/urls.py

from django.contrib import admin
from django.urls import path, include
#from django.conf.urls import url, include

urlpatterns = [
path('admin/', admin.site.urls),
path('portal/', include('portal.urls')),
#url(r'^portal/', include('portal.urls'))
]


*forms.py*

from django import forms

# class NameForm(forms.Form):
# your_name = forms.CharField(label='Your name', max_length=100)


*urls.py*

from django.conf.urls import url
from . import views

urlpatterns = [
url(r'^$', views.index, name='index')
]

*Error message:*



(py1) c:\TransportPortal\djangoproject>python manage.py runserver
Performing system checks...

Unhandled exception in thread started by .wrappe
 at 0x0355E4F8>
Traceback (most recent call last):
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\utils\autoreload.py"
 line 225, in wrapper
fn(*args, **kwargs)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\management\comm
nds\runserver.py", line 120, in inner_run
self.check(display_num_errors=True)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\management\base
py", line 364, in check
include_deployment_checks=include_deployment_checks,
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\management\base
py", line 351, in _run_checks
return checks.run_checks(**kwargs)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\checks\registry
py", line 73, in run_checks
new_errors = check(app_configs=app_configs)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\checks\urls.py"
 line 13, in check_url_config
return check_resolver(resolver)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\checks\urls.py"
 line 23, in check_resolver
return check_method()
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\resolvers.py",
ine 399, in check
for pattern in self.url_patterns:
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\utils\functional.py"
 line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\resolvers.py",
ine 540, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", 
self.urlconf_module)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\utils\functional.py"
 line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\resolvers.py",
ine 533, in urlconf_module
return import_module(self.urlconf_name)
  File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126, in 
impo
t_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 994, in _gcd_import
  File "", line 971, in _find_and_load
  File "", line 955, in _find_and_load_unlocked
  File "", line 665, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 219, in 
_call_with_frames_removed
  File "c:\TransportPortal\djangoproject\djangoproject\urls.py", line 22, 
in 
path('portal/', include('portal.urls')),
  File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\conf.py", 
line
4, in include
urlconf_module = import_module(urlconf_module)
  File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126, in 
impo
t_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 994, in _gcd_import
  File "", line 971, in _find_and_load
  File "", line 955, in _find_and_load_unlocked
  File "", line 665, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 219, in 
_call_with_frames_removed
  File "c:\TransportPortal\djangoproject\portal\urls.py", line 6, in 

url(r'^$', views.index, name='index')
AttributeError: module 'portal.views' has no attribute 'index'

(py1) c:\TransportPortal\djangoproject>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 

Re: Add value to database without using forms in django

2017-09-30 Thread Mitul Tyagi
Yup did it.save() method. I wanted to know if we need to create form 
for saving or other way's are present also...I got the answer. Thanks for 
the reply

On Saturday, September 30, 2017 at 9:19:41 PM UTC+5:30, Derek wrote:
>
> Yes, its a strange question.
>
> You can of course always add a new method to the City class:
>
> class City(models.Model):
>
>...
>
> def get_cities(self):
> return ''.join([self.city1, self.city2, self.city3, self.city4, 
> self.city5]))
>
> and then store those in Name; but from a design POV, probably 
> best not to store them but just get them when you need them.
>
>
> On Saturday, 30 September 2017 15:10:45 UTC+2, Constantine Covtushenko 
> wrote:
>>
>> Hi Mitul,
>>
>> Can you clarify a little bit more your question?
>> What are you trying to resolve?
>> You asked: "How it will be done...?" It is not clear what exactly you are 
>> trying to be done.
>>
>> I guess that it my be saving cities into model 'cityval' fields. Am I 
>> correct?
>>
>> If so you can do something like that:
>>
>> Name(cityval=''.join([city.city1, city.city2, ...])).save()
>>
>> Regards,
>> Constantine C.
>>
>> On Sat, Sep 30, 2017 at 5:39 AM, Mitul Tyagi  wrote:
>>
>>> I have a model named "Name" which stores the list of all cities present 
>>> in other model named  "City". How can it be done internally in the views.py 
>>> without using forms. Here is the code of models.py
>>>
>>> "
>>> # -*- coding: utf-8 -*-
>>> from __future__ import unicode_literals
>>>
>>> from django.db import models
>>>
>>>
>>> class Detail(models.Model):
>>> username = models.CharField(max_length=100)
>>> password = models.CharField(max_length=100)
>>>
>>> def __str__(self):
>>> return str(self.username)
>>>
>>>
>>> class City(models.Model):
>>> userName = models.ForeignKey(Detail, blank=True, null=True)
>>> city1 = models.CharField(max_length=100)
>>> city2 = models.CharField(max_length=100)
>>> city3 = models.CharField(max_length=100)
>>> city4 = models.CharField(max_length=100)
>>> city5 = models.CharField(max_length=100)
>>> def __str__(self):
>>> return "Id No:" + str(self.pk)+" and Name: "+str(self.userName)
>>>
>>> class Name(models.Model):
>>> cityval=models.CharField(max_length=100)
>>> "
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/5d83ea00-e613-4b86-830f-262b1db4ce99%40googlegroups.com
>>>  
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> Sincerely yours,
>> Constantine C
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4406d4b0-cf38-41c6-a61d-3cad42b8bd7b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add value to database without using forms in django

2017-09-30 Thread Derek
Yes, its a strange question.

You can of course always add a new method to the City class:

class City(models.Model):

   ...

def get_cities(self):
return ''.join([self.city1, self.city2, self.city3, self.city4, 
self.city5]))

and then store those in Name; but from a design POV, probably 
best not to store them but just get them when you need them.


On Saturday, 30 September 2017 15:10:45 UTC+2, Constantine Covtushenko 
wrote:
>
> Hi Mitul,
>
> Can you clarify a little bit more your question?
> What are you trying to resolve?
> You asked: "How it will be done...?" It is not clear what exactly you are 
> trying to be done.
>
> I guess that it my be saving cities into model 'cityval' fields. Am I 
> correct?
>
> If so you can do something like that:
>
> Name(cityval=''.join([city.city1, city.city2, ...])).save()
>
> Regards,
> Constantine C.
>
> On Sat, Sep 30, 2017 at 5:39 AM, Mitul Tyagi  > wrote:
>
>> I have a model named "Name" which stores the list of all cities present 
>> in other model named  "City". How can it be done internally in the views.py 
>> without using forms. Here is the code of models.py
>>
>> "
>> # -*- coding: utf-8 -*-
>> from __future__ import unicode_literals
>>
>> from django.db import models
>>
>>
>> class Detail(models.Model):
>> username = models.CharField(max_length=100)
>> password = models.CharField(max_length=100)
>>
>> def __str__(self):
>> return str(self.username)
>>
>>
>> class City(models.Model):
>> userName = models.ForeignKey(Detail, blank=True, null=True)
>> city1 = models.CharField(max_length=100)
>> city2 = models.CharField(max_length=100)
>> city3 = models.CharField(max_length=100)
>> city4 = models.CharField(max_length=100)
>> city5 = models.CharField(max_length=100)
>> def __str__(self):
>> return "Id No:" + str(self.pk)+" and Name: "+str(self.userName)
>>
>> class Name(models.Model):
>> cityval=models.CharField(max_length=100)
>> "
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/5d83ea00-e613-4b86-830f-262b1db4ce99%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Sincerely yours,
> Constantine C
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a51afb41-e8b5-4431-a530-28ba500df3f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add value to database without using forms in django

2017-09-30 Thread Constantine Covtushenko
Hi Mitul,

Can you clarify a little bit more your question?
What are you trying to resolve?
You asked: "How it will be done...?" It is not clear what exactly you are
trying to be done.

I guess that it my be saving cities into model 'cityval' fields. Am I
correct?

If so you can do something like that:

Name(cityval=''.join([city.city1, city.city2, ...])).save()

Regards,
Constantine C.

On Sat, Sep 30, 2017 at 5:39 AM, Mitul Tyagi  wrote:

> I have a model named "Name" which stores the list of all cities present in
> other model named  "City". How can it be done internally in the views.py
> without using forms. Here is the code of models.py
>
> "
> # -*- coding: utf-8 -*-
> from __future__ import unicode_literals
>
> from django.db import models
>
>
> class Detail(models.Model):
> username = models.CharField(max_length=100)
> password = models.CharField(max_length=100)
>
> def __str__(self):
> return str(self.username)
>
>
> class City(models.Model):
> userName = models.ForeignKey(Detail, blank=True, null=True)
> city1 = models.CharField(max_length=100)
> city2 = models.CharField(max_length=100)
> city3 = models.CharField(max_length=100)
> city4 = models.CharField(max_length=100)
> city5 = models.CharField(max_length=100)
> def __str__(self):
> return "Id No:" + str(self.pk)+" and Name: "+str(self.userName)
>
> class Name(models.Model):
> cityval=models.CharField(max_length=100)
> "
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/5d83ea00-e613-4b86-830f-262b1db4ce99%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boUvLwA4yELOr%3D%3DVqQJrT7G_n9-%3Dq%2Bqcutu%3DUrdDXf_GFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Add value to database without using forms in django

2017-09-30 Thread Mitul Tyagi
I have a model named "Name" which stores the list of all cities present in 
other model named  "City". How can it be done internally in the views.py 
without using forms. Here is the code of models.py

"
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models


class Detail(models.Model):
username = models.CharField(max_length=100)
password = models.CharField(max_length=100)

def __str__(self):
return str(self.username)


class City(models.Model):
userName = models.ForeignKey(Detail, blank=True, null=True)
city1 = models.CharField(max_length=100)
city2 = models.CharField(max_length=100)
city3 = models.CharField(max_length=100)
city4 = models.CharField(max_length=100)
city5 = models.CharField(max_length=100)
def __str__(self):
return "Id No:" + str(self.pk)+" and Name: "+str(self.userName)

class Name(models.Model):
cityval=models.CharField(max_length=100)
"

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5d83ea00-e613-4b86-830f-262b1db4ce99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: no value in database

2013-09-30 Thread Satinderpal Singh
On Mon, Sep 30, 2013 at 10:07 PM, Harjot Mann  wrote:
> Here is the code to my view,
> http://tny.cz/57446220
> After filing form when I click on submit button , I am getting this
> error "SsupenceEditJob matching query does not exist" and not getting

I think it must be SuspenceEditJob.

-- 
Satinderpal Singh

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BiK19%2BP8TCort0RKRJDLuAO6e0s0szT4VsLkTKeJz2XQZvSmw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


no value in database

2013-09-30 Thread Harjot Mann
Here is the code to my view,
http://tny.cz/57446220
After filing form when I click on submit button , I am getting this
error "SsupenceEditJob matching query does not exist" and not getting
any values in database.
Help me please.

-- 
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/
Daily Dairy: http://harjotmann.wordpress.com/daily-diary/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB0GQhC%3DXNo6tBYQKwOagBmEBz70zUy0imMmMS8b7m2ygEbAnw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Getting last or max "id" value from database

2010-09-05 Thread Jagdeep Singh Malhi



> Given that the ModelForm save() method actually returns the Input object
> it has just created, wouldn't you be better simply saying
>
>     p = form.save()
>
Problem solved
Thanks Sir.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting last or max "id" value from database

2010-09-05 Thread Steve Holden
On 9/5/2010 3:12 AM, Jagdeep Singh Malhi wrote:
> I try to get the max value of id from database using max() function
> but a face this error.
> {
> TypeError at /add_db/
> 
> 'builtin_function_or_method' object is not iterable
> 
> Request Method:   POST
> Request URL:  http://localhost/django/add_db/
> Django Version:   1.2.1
> Exception Type:   TypeError
> Exception Value:  'builtin_function_or_method' object is not iterable
> 
> Exception Location:   /home/jagdeep/mysite/add_db/views.py in add_db,
> line 19
> Python Executable:/usr/bin/python
> }
> 
> model.py
> from django.db import models
> from django.forms import ModelForm
> 
> class Input(models.Model):
> input1 = models.FloatField()
> input2 = models.FloatField()
> 
> class Output(models.Model):
>   out = models.ForeignKey(Input)
>   output = models.FloatField()
> 
> class InputForm(ModelForm):
> class Meta :
> model = Input
> 
> class OutputForm(ModelForm):
> class Meta :
> model = Output
> 
> 
> 
> View.py
> from django.http import HttpResponseRedirect
> from django.shortcuts import render_to_response, get_object_or_404
> from mysite.add_db.models import *
> from django.template import RequestContext
> from django.core.urlresolvers import reverse
> 
> 
> def add_db(request):
> if request.method == 'POST':
> form = InputForm(request.POST)
> if form.is_valid():
> cd = form.cleaned_data
> input1 = cd['input1']
> input2 = cd['input2']
> form.save()
>   form_output = OutputForm()
>   output = input1 + input2
>   p = get_object_or_404(Input, pk=max(id))
> form_output_final = p.output_set.create(output=output)
> return render_to_response('add_db/output.html', {'form':
> form, 'input1':input1, 'input2':input2, 'output':output},
> context_instance=RequestContext(request))
> else:
> form = InputForm()
> return render_to_response('add_db/add.html', {'form': form},
> context_instance=RequestContext(request))
> 
> 
> I want to get the latest or maximum  "Id" value of INPUT table from
> database.
> 
> please help
> 
I'm not fully up to speed on the aggregate stuff, but I *think* what you
are trying to do is

from django.db.models import Max
maxid = Input.objects.aggregate(Max('id'))
p = Input.objects.get(pk=maxid)

No need to worry about the possibility of an exception, since the maxid
value is guaranteed to exist (as long as there's at least one row in the
table). This does, however, rely on the assumption that auto-increment
primary keys will be monotonically increasing.

Given that the ModelForm save() method actually returns the Input object
it has just created, wouldn't you be better simply saying

p = form.save()

and throwing away the code that does the database searching? Or have I
misunderstood the purpose of your code?

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Getting last or max "id" value from database

2010-09-05 Thread Jagdeep Singh Malhi
I try to get the max value of id from database using max() function
but a face this error.
{
TypeError at /add_db/

'builtin_function_or_method' object is not iterable

Request Method: POST
Request URL:http://localhost/django/add_db/
Django Version: 1.2.1
Exception Type: TypeError
Exception Value:'builtin_function_or_method' object is not iterable

Exception Location: /home/jagdeep/mysite/add_db/views.py in add_db,
line 19
Python Executable:  /usr/bin/python
}

model.py
from django.db import models
from django.forms import ModelForm

class Input(models.Model):
input1 = models.FloatField()
input2 = models.FloatField()

class Output(models.Model):
out = models.ForeignKey(Input)
output = models.FloatField()

class InputForm(ModelForm):
class Meta :
model = Input

class OutputForm(ModelForm):
class Meta :
model = Output



View.py
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from mysite.add_db.models import *
from django.template import RequestContext
from django.core.urlresolvers import reverse


def add_db(request):
if request.method == 'POST':
form = InputForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
input1 = cd['input1']
input2 = cd['input2']
form.save()
form_output = OutputForm()
output = input1 + input2
p = get_object_or_404(Input, pk=max(id))
  form_output_final = p.output_set.create(output=output)
return render_to_response('add_db/output.html', {'form':
form, 'input1':input1, 'input2':input2, 'output':output},
context_instance=RequestContext(request))
else:
form = InputForm()
return render_to_response('add_db/add.html', {'form': form},
context_instance=RequestContext(request))


I want to get the latest or maximum  "Id" value of INPUT table from
database.

please help

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: change a value of database

2008-07-16 Thread Alfredo Alessandrini

solved...


from GAME.models import Game

p = Game.objects.get(id=1)

p.name = '2'

p.save()

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



change a value of database

2008-07-16 Thread Alfredo Alessandrini

I've a simple a question...

How can I update a single value of database??

I've try this:

from GAME.models import Game

Game.objects.filter(id=1)

p.name='2'

but don't update...It's add a row.


thanks in advance,

Alfredo

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---