django-1.9

How to calculate distance between two PointField?

徘徊边缘 提交于 2019-12-06 09:23:20
I use Postgis with Django to store geographic points. I have a model like the following: from django.contrib.gis.db import models class Event(models.Model) position = models.PointField() I have two events(ev1, ev2). Here is the position value of each: SRID=4326;POINT (-73.6335140000000052 45.5472019999999986) SRID=4326;POINT (-73.6267909999999972 45.5459189999999978) My goal is to get distance in meters between those two points. If i do: ev1.position.distance(ev2.position) I get 0.006844327432269004 How can I convert this value in meters? Thanks! Michael I was able to make it work, but only

Use signals in Django 1.9

血红的双手。 提交于 2019-12-05 21:45:00
In Django 1.8, I was able to do the following with my signals, and all was well: __init__.py: from .signals import * signals.py: @receiver(pre_save, sender=Comment) def process_hashtags(sender, instance, **kwargs): html = [] for word in instance.hashtag_field.value_to_string(instance).split(): if word.startswith('#'): word = render_to_string('hashtags/_link.html', {'hashtag': word.lower()[1:]}) html.append(word) instance.hashtag_enabled_text = ' '.join(html) In Django 1.9, I get this error: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. I know it's coming from the __init__

Django 1.9 can not find newapp

耗尽温柔 提交于 2019-12-04 06:48:49
问题 I have worked with django 1.7 and recently started new project with django 1.9. The major difference with starting a new app was that new app is created with apps.py file. I read on django docs that now you have to use INSTALLED_APPS = [ 'newapp.apps.NewAppConfig', ... ] (old was just 'newapp' ) In my new project i have all my apps in a new directory called 'myapps'. But if i use 'myapps.newapp.apps.NewAppConfig' than django gives error ImportError: No module named newapp But if i use the old

New url format in Django 1.9

心不动则不痛 提交于 2019-12-03 15:04:37
问题 I recently upgraded my Django project to version 1.9. When I try to run migrate , I am getting the following two errors: Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got app.views.about). Pass the callable instead. django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead. Could someone please show me the proper syntax of how to do this? A brief

Django 1.8 to 1.9 upgrade: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet

我的梦境 提交于 2019-12-03 14:46:23
问题 I have a project currently working on Django 1.8. Since 1.9 just released, I thought I would update via pip install django==1.9 . However, when running python manage.py test -v 3 , I get this error: Traceback (most recent call last): File "manage.py", line 11, in <module> execute_from_command_line(sys.argv) File "/home/user/Envs/intranet/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line utility.execute() File "/home/user/Envs/intranet/lib

Django 1.8 to 1.9 upgrade: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet

邮差的信 提交于 2019-12-03 03:46:46
I have a project currently working on Django 1.8. Since 1.9 just released, I thought I would update via pip install django==1.9 . However, when running python manage.py test -v 3 , I get this error: Traceback (most recent call last): File "manage.py", line 11, in <module> execute_from_command_line(sys.argv) File "/home/user/Envs/intranet/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line utility.execute() File "/home/user/Envs/intranet/lib/python2.7/site-packages/django/core/management/__init__.py", line 324, in execute django.setup() File "

Why did Django 1.9 replace tuples () with lists [] in settings and URLs?

我怕爱的太早我们不能终老 提交于 2019-12-03 01:02:35
I am bit curious to know why Django 1.9 replaced tuples () with lists [] in settings, URLs and other configuration files I just upgraded to Django 1.9 and noticed these changes. What is the logic behind them? INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles' ] AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME':

filter tags of django-taggit in Django's Queryset

匆匆过客 提交于 2019-12-02 12:45:50
Having the following models: class Post(models.Model): title = models.CharField(max_length=250) tags = TaggableManager() and the data are: **post.title** **post.tags** Django By Example python,django,web Who was Django Reinhardt python,django, Test-Driven Development with Python python,web Python for Data Analysis python,data Learning Python python Programming Python python Automate the Boring Stuff with Python python I try to code below >>> alist=Post.objects.filter(tags__name__in=["data","python"]) >>> for i in alist.annotate(sam_tags=Count('tags')): ... print("\n---",i) ... print("tags of

Django 1.9 can not find newapp

微笑、不失礼 提交于 2019-12-02 08:02:50
I have worked with django 1.7 and recently started new project with django 1.9. The major difference with starting a new app was that new app is created with apps.py file. I read on django docs that now you have to use INSTALLED_APPS = [ 'newapp.apps.NewAppConfig', ... ] (old was just 'newapp' ) In my new project i have all my apps in a new directory called 'myapps'. But if i use 'myapps.newapp.apps.NewAppConfig' than django gives error ImportError: No module named newapp But if i use the old way i.e. INSTALLED_APPS = [ 'myapps.newapp', ... ] Than it works perfectly without error but configs

Django 1.9 drop foreign key in migration

旧街凉风 提交于 2019-11-30 15:19:53
问题 I have a Django model that has a foreign key to another model: class Example(models.Model) something = models.ForeignKey(SomeModel, db_index=True) I want to keep the underlying DB column as a field, but to get rid of the foreign key constraint in the database. So the model will change to: class Example(models.Model): something_id = models.IntegerField() And, to be clear, something_id is the column that Django had created for the foreign key field. I do not want to drop the column and re