Re: if statement in django
On 04/05/2014 11:08 PM, Anthony Smith wrote: Hi I have a small project and I have been unable to get the following statement to work. Any help would great.User inputs can either self_sale_head which is a $ value,if a $ value is not add a self.estimated_weight_hd is used to get the total weight, the code below should return a estimated_weight_total which can be used for the total sale price. All works when I add the estimated_weight_total manually. I am lost as why. |def calc_estimated_weight_total(self): if self.sale_head<= 0: amount= (self.number* self.estimated_weight_hd) return amount def save(self): self.estimated_total_weight= self.calc_estimated_weight_total() super(SaleNote, self).save()| Anthony, In your first function, when the if condition evaluates to False it not return anything. A possible version is: def calc_estimated_weight_total(self): if self.sale_head <= 0: amount = self.number * self.estimated_weight_hd else: amount = 0 # (or your default value or other code to calculate amount) return amount Another version def calc_estimated_weight_total(self): amount = 0 if self.sale_head <= 0: amount = self.number * self.estimated_weight_hd return amount Both versions will return a value not matter whether the test condition evaluates to True or False. The second version assumes the default value is 0 -- Jay Lozier jsloz...@gmail.com -- 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/5340E423.2070700%40gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: python manage.py runserver error
virtualenv works, this for the link. On Sunday, July 21, 2013 10:09:59 PM UTC-4, Jay Lozier wrote: > > I get the following error when run python manage.py runserver: > > OS openSUSE 12.3 > django 1.7 > > > boopers@linux-nss6:~/myfirstsite> python manage.py runserver > Traceback (most recent call last): > File "manage.py", line 10, in > execute_from_command_line(sys.argv) > File "/home/boopers/django-trunk/django/core/management/__init__.py", line > 397, in execute_from_command_line > utility.execute() > File "/home/boopers/django-trunk/django/core/management/__init__.py", line > 390, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File "/home/boopers/django-trunk/django/core/management/__init__.py", line > 261, in fetch_command > app_name = get_commands()[subcommand] > File "/home/boopers/django-trunk/django/core/management/__init__.py", line > 107, in get_commands > apps = settings.INSTALLED_APPS > File "/home/boopers/django-trunk/django/conf/__init__.py", line 54, in > __getattr__ > self._setup(name) > File "/home/boopers/django-trunk/django/conf/__init__.py", line 50, in > _setup > self._configure_logging() > File "/home/boopers/django-trunk/django/conf/__init__.py", line 68, in > _configure_logging > from django.utils.log import DEFAULT_LOGGING > File "/home/boopers/django-trunk/django/utils/log.py", line 7, in > from django.views.debug import ExceptionReporter, > get_exception_reporter_filter > File "/home/boopers/django-trunk/django/views/debug.py", line 10, in > > from django.http import (HttpResponse, HttpResponseServerError, > File "/home/boopers/django-trunk/django/http/__init__.py", line 4, in > > from django.http.response import (HttpResponse, StreamingHttpResponse, > File "/home/boopers/django-trunk/django/http/response.py", line 16, in > > from django.utils import six, timezone > File "/home/boopers/django-trunk/django/utils/timezone.py", line 11, in > > import pytz > File "/usr/lib/python2.7/site-packages/pytz/__init__.py", line 35, in > > from pkg_resources import resource_stream > File > "/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", > > line 3027, in > add_activation_listener(lambda dist: dist.activate()) > File > "/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", > > line 741, in subscribe > callback(dist) > File > "/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", > > line 3027, in > add_activation_listener(lambda dist: dist.activate()) > File > "/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", > > line 2514, in activate > list(map(declare_namespace, self._get_metadata('namespace_packages.txt'))) > File > "/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", > > line 2094, in declare_namespace > _handle_ns(packageName, path_item) > File > "/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", > > line 2059, in _handle_ns > raise TypeError("Not a package:", packageName) > TypeError: ('Not a package:', 'cgi') > > > The sys paths are > > /usr/lib/python2.7/site-packages/pymongo-2.5.1-py2.7-linux-x86_64.egg > /usr/lib/python2.7/site-packages/bottle-0.11.6-py2.7.egg > /usr/lib/python2.7/site-packages/translationstring-1.1-py2.7.egg > /usr/lib/python2.7/site-packages/venusian-1.0a8-py2.7.egg > /usr/lib/python2.7/site-packages/zope.deprecation-4.0.2-py2.7.egg > /usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg > /home/boopers/django-trunk > /usr/lib/python27.zip > /usr/lib64/python2.7 > /usr/lib64/python2.7/plat-linux2 > /usr/lib64/python2.7/lib-tk > /usr/lib64/python2.7/lib-old > /usr/lib64/python2.7/lib-dynload > /usr/lib64/python2.7/site-packages > /usr/lib64/python2.7/site-packages/FontTools > /usr/lib64/python2.7/site-packages/PIL > /usr/local/lib64/python2.7/site-packages > /usr/local/lib/python2.7/site-packages > /usr/lib64/python2.7/site-packages/gst-0.10 > /usr/lib64/python2.7/site-packages/gtk-2.0 > /usr/lib64/python2.7/site-packages/input-pad-1.0 > /usr/lib/python2.7/site-packages > /usr/lib64/python2.7/site-packages/wx-2.9.4-gtk2 > -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: django-admin.py startproject mysite error
virtualenv seems to work well and I can get django tamed. On Saturday, July 20, 2013 5:55:21 PM UTC-4, Jay Lozier wrote: > > Using openSUSE 12.3 > python 2.7.3 > django 1.5.1 installed manually and verified > > When I enter "django-admin.py startproject mysite" at the command prompt I > get the following traceback: > > Traceback (most recent call last): > File "/usr/bin/django-admin.py", line 5, in > management.execute_from_command_line() > File > "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line > 453, in execute_from_command_line > utility.execute() > File > "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line > 392, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File > "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line > 272, in fetch_command > klass = load_command_class(app_name, subcommand) > File > "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line > 77, in load_command_class > module = import_module('%s.management.commands.%s' % (app_name, name)) > File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line > 35, in import_module > __import__(name) > File > "/usr/lib/python2.7/site-packages/django/core/management/commands/startproject.py", > > line 2, in > from django.core.management.templates import TemplateCommand > File > "/usr/lib/python2.7/site-packages/django/core/management/templates.py", > line 20, in > from django.template import Template, Context > File "/usr/lib/python2.7/site-packages/django/template/__init__.py", line > 53, in > from django.template.base import (ALLOWED_VARIABLE_CHARS, BLOCK_TAG_END, > File "/usr/lib/python2.7/site-packages/django/template/base.py", line 18, > in > from django.utils.formats import localize > File "/usr/lib/python2.7/site-packages/django/utils/formats.py", line 5, > in > from django.utils import dateformat, numberformat, datetime_safe > File "/usr/lib/python2.7/site-packages/django/utils/dateformat.py", line > 25, in > from django.utils.timezone import is_aware, is_naive > File "/usr/lib/python2.7/site-packages/django/utils/timezone.py", line 11, > in > import pytz > File "/usr/lib/python2.7/site-packages/pytz/__init__.py", line 35, in > > from pkg_resources import resource_stream > File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2978, in > > add_activation_listener(lambda dist: dist.activate()) > File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 709, in > subscribe > callback(dist) > File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2978, in > > add_activation_listener(lambda dist: dist.activate()) > File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2465, in > activate > map(declare_namespace, self._get_metadata('namespace_packages.txt')) > File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2045, in > declare_namespace > _handle_ns(packageName, path_item) > File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2010, in > _handle_ns > raise TypeError("Not a package:", packageName) > TypeError: ('Not a package:', 'cgi') > > How do I fix this? > -- 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. For more options, visit https://groups.google.com/groups/opt_out.
python manage.py runserver error
I get the following error when run python manage.py runserver: OS openSUSE 12.3 django 1.7 boopers@linux-nss6:~/myfirstsite> python manage.py runserver Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "/home/boopers/django-trunk/django/core/management/__init__.py", line 397, in execute_from_command_line utility.execute() File "/home/boopers/django-trunk/django/core/management/__init__.py", line 390, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/boopers/django-trunk/django/core/management/__init__.py", line 261, in fetch_command app_name = get_commands()[subcommand] File "/home/boopers/django-trunk/django/core/management/__init__.py", line 107, in get_commands apps = settings.INSTALLED_APPS File "/home/boopers/django-trunk/django/conf/__init__.py", line 54, in __getattr__ self._setup(name) File "/home/boopers/django-trunk/django/conf/__init__.py", line 50, in _setup self._configure_logging() File "/home/boopers/django-trunk/django/conf/__init__.py", line 68, in _configure_logging from django.utils.log import DEFAULT_LOGGING File "/home/boopers/django-trunk/django/utils/log.py", line 7, in from django.views.debug import ExceptionReporter, get_exception_reporter_filter File "/home/boopers/django-trunk/django/views/debug.py", line 10, in from django.http import (HttpResponse, HttpResponseServerError, File "/home/boopers/django-trunk/django/http/__init__.py", line 4, in from django.http.response import (HttpResponse, StreamingHttpResponse, File "/home/boopers/django-trunk/django/http/response.py", line 16, in from django.utils import six, timezone File "/home/boopers/django-trunk/django/utils/timezone.py", line 11, in import pytz File "/usr/lib/python2.7/site-packages/pytz/__init__.py", line 35, in from pkg_resources import resource_stream File "/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", line 3027, in add_activation_listener(lambda dist: dist.activate()) File "/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", line 741, in subscribe callback(dist) File "/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", line 3027, in add_activation_listener(lambda dist: dist.activate()) File "/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", line 2514, in activate list(map(declare_namespace, self._get_metadata('namespace_packages.txt'))) File "/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", line 2094, in declare_namespace _handle_ns(packageName, path_item) File "/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", line 2059, in _handle_ns raise TypeError("Not a package:", packageName) TypeError: ('Not a package:', 'cgi') The sys paths are /usr/lib/python2.7/site-packages/pymongo-2.5.1-py2.7-linux-x86_64.egg /usr/lib/python2.7/site-packages/bottle-0.11.6-py2.7.egg /usr/lib/python2.7/site-packages/translationstring-1.1-py2.7.egg /usr/lib/python2.7/site-packages/venusian-1.0a8-py2.7.egg /usr/lib/python2.7/site-packages/zope.deprecation-4.0.2-py2.7.egg /usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg /home/boopers/django-trunk /usr/lib/python27.zip /usr/lib64/python2.7 /usr/lib64/python2.7/plat-linux2 /usr/lib64/python2.7/lib-tk /usr/lib64/python2.7/lib-old /usr/lib64/python2.7/lib-dynload /usr/lib64/python2.7/site-packages /usr/lib64/python2.7/site-packages/FontTools /usr/lib64/python2.7/site-packages/PIL /usr/local/lib64/python2.7/site-packages /usr/local/lib/python2.7/site-packages /usr/lib64/python2.7/site-packages/gst-0.10 /usr/lib64/python2.7/site-packages/gtk-2.0 /usr/lib64/python2.7/site-packages/input-pad-1.0 /usr/lib/python2.7/site-packages /usr/lib64/python2.7/site-packages/wx-2.9.4-gtk2 -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: django-admin.py startproject mysite error
I get this note: I have completely deleted any django packages on the my system and could get any version but the dev version to even get past the first step. the dev 1.7 version would run django-admin.py startproject myfirstsite but now python manage.py runserver does not work error in line 10 /usr/lib/python2.7/site-packages/pymongo-2.5.1-py2.7-linux-x86_64.egg /usr/lib/python2.7/site-packages/bottle-0.11.6-py2.7.egg /usr/lib/python2.7/site-packages/translationstring-1.1-py2.7.egg /usr/lib/python2.7/site-packages/venusian-1.0a8-py2.7.egg /usr/lib/python2.7/site-packages/zope.deprecation-4.0.2-py2.7.egg /usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg /home/boopers/django-trunk /usr/lib/python27.zip /usr/lib64/python2.7 /usr/lib64/python2.7/plat-linux2 /usr/lib64/python2.7/lib-tk /usr/lib64/python2.7/lib-old /usr/lib64/python2.7/lib-dynload /usr/lib64/python2.7/site-packages /usr/lib64/python2.7/site-packages/FontTools /usr/lib64/python2.7/site-packages/PIL /usr/local/lib64/python2.7/site-packages /usr/local/lib/python2.7/site-packages /usr/lib64/python2.7/site-packages/gst-0.10 /usr/lib64/python2.7/site-packages/gtk-2.0 /usr/lib64/python2.7/site-packages/input-pad-1.0 /usr/lib/python2.7/site-packages /usr/lib64/python2.7/site-packages/wx-2.9.4-gtk2 On Saturday, July 20, 2013 5:55:21 PM UTC-4, Jay Lozier wrote: > > Using openSUSE 12.3 > python 2.7.3 > django 1.5.1 installed manually and verified > > When I enter "django-admin.py startproject mysite" at the command prompt I > get the following traceback: > > Traceback (most recent call last): > File "/usr/bin/django-admin.py", line 5, in > management.execute_from_command_line() > File > "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line > 453, in execute_from_command_line > utility.execute() > File > "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line > 392, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File > "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line > 272, in fetch_command > klass = load_command_class(app_name, subcommand) > File > "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line > 77, in load_command_class > module = import_module('%s.management.commands.%s' % (app_name, name)) > File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line > 35, in import_module > __import__(name) > File > "/usr/lib/python2.7/site-packages/django/core/management/commands/startproject.py", > > line 2, in > from django.core.management.templates import TemplateCommand > File > "/usr/lib/python2.7/site-packages/django/core/management/templates.py", > line 20, in > from django.template import Template, Context > File "/usr/lib/python2.7/site-packages/django/template/__init__.py", line > 53, in > from django.template.base import (ALLOWED_VARIABLE_CHARS, BLOCK_TAG_END, > File "/usr/lib/python2.7/site-packages/django/template/base.py", line 18, > in > from django.utils.formats import localize > File "/usr/lib/python2.7/site-packages/django/utils/formats.py", line 5, > in > from django.utils import dateformat, numberformat, datetime_safe > File "/usr/lib/python2.7/site-packages/django/utils/dateformat.py", line > 25, in > from django.utils.timezone import is_aware, is_naive > File "/usr/lib/python2.7/site-packages/django/utils/timezone.py", line 11, > in > import pytz > File "/usr/lib/python2.7/site-packages/pytz/__init__.py", line 35, in > > from pkg_resources import resource_stream > File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2978, in > > add_activation_listener(lambda dist: dist.activate()) > File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 709, in > subscribe > callback(dist) > File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2978, in > > add_activation_listener(lambda dist: dist.activate()) > File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2465, in > activate > map(declare_namespace, self._get_metadata('namespace_packages.txt')) > File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2045, in > declare_namespace > _handle_ns(packageName, path_item) > File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2010, in > _handle_ns > raise TypeError("Not a package:", packageName) > TypeError: ('Not a package:', 'cgi') > > How do I fix this? > -- 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. For more options, visit https://groups.google.com/groups/opt_out.
django-admin.py startproject mysite error
Using openSUSE 12.3 python 2.7.3 django 1.5.1 installed manually and verified When I enter "django-admin.py startproject mysite" at the command prompt I get the following traceback: Traceback (most recent call last): File "/usr/bin/django-admin.py", line 5, in management.execute_from_command_line() File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line utility.execute() File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command klass = load_command_class(app_name, subcommand) File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class module = import_module('%s.management.commands.%s' % (app_name, name)) File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/usr/lib/python2.7/site-packages/django/core/management/commands/startproject.py", line 2, in from django.core.management.templates import TemplateCommand File "/usr/lib/python2.7/site-packages/django/core/management/templates.py", line 20, in from django.template import Template, Context File "/usr/lib/python2.7/site-packages/django/template/__init__.py", line 53, in from django.template.base import (ALLOWED_VARIABLE_CHARS, BLOCK_TAG_END, File "/usr/lib/python2.7/site-packages/django/template/base.py", line 18, in from django.utils.formats import localize File "/usr/lib/python2.7/site-packages/django/utils/formats.py", line 5, in from django.utils import dateformat, numberformat, datetime_safe File "/usr/lib/python2.7/site-packages/django/utils/dateformat.py", line 25, in from django.utils.timezone import is_aware, is_naive File "/usr/lib/python2.7/site-packages/django/utils/timezone.py", line 11, in import pytz File "/usr/lib/python2.7/site-packages/pytz/__init__.py", line 35, in from pkg_resources import resource_stream File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2978, in add_activation_listener(lambda dist: dist.activate()) File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 709, in subscribe callback(dist) File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2978, in add_activation_listener(lambda dist: dist.activate()) File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2465, in activate map(declare_namespace, self._get_metadata('namespace_packages.txt')) File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2045, in declare_namespace _handle_ns(packageName, path_item) File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2010, in _handle_ns raise TypeError("Not a package:", packageName) TypeError: ('Not a package:', 'cgi') How do I fix this? -- 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. For more options, visit https://groups.google.com/groups/opt_out.