django-1.8

How can i get all models in django 1.8

不打扰是莪最后的温柔 提交于 2019-11-28 19:26:05
I am using this code in my admin.py from django.db.models import get_models, get_app for model in get_models(get_app('myapp')): admin.site.register(model) But i get warning that get_models is deprecated How can i do that in django 1.8 This should work, from django.apps import apps apps.get_models() The get_models method returns a list of all installed models. You can also pass three keyword arguments include_auto_created , include_deferred and include_swapped . If you want to get the models for a specific app, you can do something like this. from django.apps import apps myapp = apps.get_app

How to redo a migration on django 1.8 after using --fake

有些话、适合烂在心里 提交于 2019-11-28 17:25:47
Something went wrong on my migrations, I added a new datetimefield to a model then I used makemigrations and migrate. python manage.py makemigrations python manage.py migrate But after this the migrate got an "table already exists error". I supposed I could fake the migrations and start over, so I did python manage.py makemigrations --fake core Operations to perform: Apply all migrations: core Running migrations: Rendering model states... DONE Applying core.0001_initial... FAKED Applying core.0002_auto_20150525_1331... FAKED Applying core.0003_auto_20150525_1348... FAKED Applying core.0004

ImportError: cannot import name update_all_contenttypes

送分小仙女□ 提交于 2019-11-28 13:29:28
I upgraded recently to Django 1.8. In previous versions of Django, the following import was fine: from django.contrib.contenttypes.management import update_all_contenttypes But update_all_contenttypes appears to have been silently removed in Django 1.8 (it was there in 1.7.7). I'm not seeing anything in the 1.8 release notes about its removal... Does anyone know what the modern replacement is for that function? It's unclear why that function was removed in 1.8, but it appears that the modern replacement is to just re-invent that wheel: from django.apps import apps from django.contrib

Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 08:02:37
I am trying to migrate from Django 1.6 to Django 1.8 . I was using South for managing migrations in Django 1.6. I have successfully created new migration files by python manage.py makemigrations . while running python manage.py migrate --fake-initial , I am getting this error Traceback (most recent call last): File "manage.py", line 39, in <module> execute_from_command_line(sys.argv) File "/home/jonty/.virtualenvs/squadrun/local/lib/python2.7/site- packages/django/core/management/__init__.py", line 338, in execute_from_command_line utility.execute() File "/home/jonty/.virtualenvs/squadrun

“Models aren't loaded yet” error while populating in Django 1.8 or later

て烟熏妆下的殇ゞ 提交于 2019-11-28 06:45:13
I am using this code to populate my database: import os def populate(): python_cat = add_cat('Python') add_page(cat=python_cat, title="Official Python Tutorial", url="http://docs.python.org/2/tutorial/") add_page(cat=python_cat, title="How to Think like a Computer Scientist", url="http://www.greenteapress.com/thinkpython/") add_page(cat=python_cat, title="Learn Python in 10 minutes", url="http://www.korokithakis.net/tutorials/python/") django_cat = add_cat(name="Django") add_page(cat=django_cat, title="Official Django Tutorial", url="http://djangoproject.com/en/1.5/intro/tutorial01/") add_page

Annotate with value of latest related in Django 1.8 using conditional annotation

Deadly 提交于 2019-11-27 21:53:54
I have the following models: class City(models.Model): ... class Census(models.Model): city = models.ForeignKey(City) date = models.DateTimeField() value = models.BigIntegerField() Now I'd like to annotate a City-queryset with the value of the latest Census. How do I achieve that? I have tried: City.objects.annotate(population=Max('census__date')) # --> annotates date and not value City.objects.annotate(population=Max('census__value')) # --> annotates highest value, not latest City.objects.annotate(population= Case( When( census__date=Max('census__date'), then='census__value') ) ) # -->

How can i get all models in django 1.8

元气小坏坏 提交于 2019-11-27 12:18:57
问题 I am using this code in my admin.py from django.db.models import get_models, get_app for model in get_models(get_app('myapp')): admin.site.register(model) But i get warning that get_models is deprecated How can i do that in django 1.8 回答1: This should work, from django.apps import apps apps.get_models() The get_models method returns a list of all installed models. You can also pass three keyword arguments include_auto_created , include_deferred and include_swapped . If you want to get the

ImportError: cannot import name update_all_contenttypes

雨燕双飞 提交于 2019-11-27 07:44:16
问题 I upgraded recently to Django 1.8. In previous versions of Django, the following import was fine: from django.contrib.contenttypes.management import update_all_contenttypes But update_all_contenttypes appears to have been silently removed in Django 1.8 (it was there in 1.7.7). I'm not seeing anything in the 1.8 release notes about its removal... Does anyone know what the modern replacement is for that function? 回答1: It's unclear why that function was removed in 1.8, but it appears that the

What should I use instead of syncdb in Django 1.9?

只谈情不闲聊 提交于 2019-11-27 06:47:18
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 ? syncdb is deprecated because of the migration system , introduced with django 1.7 . Now you can track your changes using makemigrations . This transforms your model changes into python code to

“Models aren't loaded yet” error while populating in Django 1.8 or later

此生再无相见时 提交于 2019-11-27 05:43:18
问题 I am using this code to populate my database: import os def populate(): python_cat = add_cat('Python') add_page(cat=python_cat, title="Official Python Tutorial", url="http://docs.python.org/2/tutorial/") add_page(cat=python_cat, title="How to Think like a Computer Scientist", url="http://www.greenteapress.com/thinkpython/") add_page(cat=python_cat, title="Learn Python in 10 minutes", url="http://www.korokithakis.net/tutorials/python/") django_cat = add_cat(name="Django") add_page(cat=django