django-1.8

Disable choice list in Django admin, only for editing

Deadly 提交于 2019-12-20 05:46:08
问题 I want to disable some fields when I am editing an object. I have managed to do this for text fields, but it's been impossible for a dropdown list (choice list). I am doing this action in the constructor of the form. class OrderModelForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(forms.ModelForm, self).__init__(*args, **kwargs) instance = getattr(self, 'instance', None) if instance and instance.pk: self.fields['description'].widget.attrs['readonly'] = True self.fields['city

What should I use instead of syncdb in Django 1.9?

亡梦爱人 提交于 2019-12-17 08:34:08
问题 Take a look at this: $ pypy ./manage.py syncdb /usr/lib64/pypy-2.4.0/site-packages/django/core/management/commands/syncdb.py:24: RemovedInDjango19Warning: The syncdb command will be removed in Django 1.9 warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning) (cut) I ran a quick google search, but could not find the answer - what should I be using instead of syncdb ? 回答1: syncdb is deprecated because of the migration system, introduced with django 1.7. Now

Django 1.8.2 — Tutorial Chapter 3 — Error: NoReverseMatch at /polls/ — Python 3.4.3

蹲街弑〆低调 提交于 2019-12-13 18:13:29
问题 I've been following the official tutorial exactly. It's located here: https://docs.djangoproject.com/en/1.8/intro/tutorial03/ It's been going well, but suddenly I'm getting this error: Reverse for 'detail' with arguments '(1,)' and keyword arguments '{}' not found. 0 pattern(s) tried: [] It happened as soon as I changed this line: <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li> to this new version: <li><a href="{% url 'detail' question.id %}">{{ question.question

Configure WSGI with Django on OpenShift

会有一股神秘感。 提交于 2019-12-13 07:21:18
问题 I tried to configure WSGI with wsgi.py in my project folder import os import sys sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'])) os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings' virtenv = os.environ['OPENSHIFT_HOMEDIR'] + 'python/virtenv/' os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.7/site-packages') virtualenv = os.path.join(virtenv, 'bin/activate_this.py') try: execfile(virtualenv, dict(__file__=virtualenv)) except IOError: pass # # IMPORTANT

Django Admin Page missing CSS in IIS

懵懂的女人 提交于 2019-12-13 06:02:49
问题 I am getting a similar error to this post, but it only happens when I go to the website I set up in IIS 2012R2. I am following this tutorial to start a web app, and I used this video to set up Django with IIS. I successfully set up the Django using IIS, but I a missing the CSS on the admin page. Note that the admin page displays the CSS items if I run the page using runserver command. python manage.py runserver But if I run it through http://127.0.0.1:8003/admin/ in IE (setup through IIS), I

Pyinstaller + Django = No module named 'django.core.context_processors'

柔情痞子 提交于 2019-12-12 12:28:27
问题 I am trying to package my django app with pyinstaller and I created this pyinstaller spec file for this purpose: # -*- mode: python -*- block_cipher = None a = Analysis(['manage.py'], pathex=['/home/gero/PycharmProjects/gen-optimizer-precision'], binaries=None, datas=None, hiddenimports=[], hookspath=None, runtime_hooks=None, excludes=['matplotlib'], win_no_prefer_redirects=None, win_private_assemblies=None, cipher=block_cipher) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE

update_all_contenttypes seemingly not working with Django 1.8

China☆狼群 提交于 2019-12-12 12:22:28
问题 I was getting the following error upon running a certain function: django.contrib.contenttypes.models.DoesNotExist: ContentType matching query does not exist. Based upon ContentType matching query does not exist on post_syncdb I tried doing from django.contrib.contenttypes.management import update_all_contenttypes update_all_contenttypes() # make sure all content types exist at the beginning of that function. Of course, as ImportError: cannot import name update_all_contenttypes mentions,

Django OneToOne reverse relationship does not allow null values

旧城冷巷雨未停 提交于 2019-12-12 01:51:56
问题 I have this architecture (very simplified) from django.db import Models class MainClass(models.Model): a = models.IntegerField() b = models.CharField() class OtherClass(models.Model): c = models.IntegerField() main = models.OneToOneField(MainClass, primary_key=True) Which means my MainClass object has an attribute named otherclass, because of the existence of the reverse relationship between these models . My problem is if I specify valid values for MainClass.a and MainClass.b, but None for

Django 1.8 conditional annotation results in INNER JOIN instead of LEFT OUTER JOIN

那年仲夏 提交于 2019-12-11 04:05:11
问题 The models: class Bar(GenericModel): ... class Foo(GenericModel): bar = models.ForeignKey(Bar, related_name='foo_bar') The query: bars = Bar.objects .prefetch_related('foo_bar') .annotate(sum_foo=Sum( Case( When(foo_bar__is_deleted=False, then='foo_bar__amount'), default=Value(0), output_field=IntegerField() ) ) ) The former results in an inner join: SELECT ... FROM "bar" INNER JOIN "foo" ON ( "bar"."id" = "foo"."bar_id" ) ... What I intend to obtain is a LEFT OUTER JOIN (a full list of "bar"

Django - 'datetime.date' object has no attribute 'tzinfo'

风格不统一 提交于 2019-12-10 03:26:33
问题 Here is my code that I use to make the datetime timezone aware. I tried to use the recommended approach from the Django docs. tradeDay = day.trade_date + timedelta(hours=6) td1 = pytz.timezone("Europe/London").localize(tradeDay, is_dst=None) tradeDay = td1.astimezone(pytz.utc) I get the tz_info error. How can I datetime a tz_info attribute? USE_TZ = True in settings.py 回答1: It looks as though day.trade_date is actually a datetime.date object rather than a datetime.datetime so trying to