How to filter choices in Django2’s autocomplete_fields?

If you are using autocomplete_fields for a ManyToManyField on ‘self’, this example will exclude the current object. Get the current object’s id by overriding get_form: field_for_autocomplete = None def get_form(self, request, obj=None, **kwargs): if obj: self.field_for_autocomplete = obj.pk return super(MyAdmin, self).get_form(request, obj, **kwargs) Next, override get_search_results. Modify the queryset only for your model’s autocomplete URI: … Read more

django.core.exceptions.AppRegistryNotReady: Apps aren’t loaded yet. (django 2.0.1)(Python 3.6)

Overcame similar situation just now. All you really need is this: import os os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “your_project.settings”) And then these lines: from django.core.wsgi import get_wsgi_application application = get_wsgi_application() After that you can easily import models without AppRegistryNotReady: Apps aren’t loaded yet. UPDATE: This is really exactly the 4 code lines from wsgi.py file in your project’s folder. … Read more

Getting TypeError: __init__() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries

You can change the property categorie of the class Article like this: categorie = models.ForeignKey( ‘Categorie’, on_delete=models.CASCADE, ) and the error should disappear. Eventually you might need another option for on_delete, check the documentation for more details: https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ForeignKey EDIT: As you stated in your comment, that you don’t have any special requirements for on_delete, you … Read more

ImportError: No module named ‘django.core.urlresolvers’

Django 2.0 removes the django.core.urlresolvers module, which was moved to django.urls in version 1.10. You should change any import to use django.urls instead, like this: from django.urls import reverse Note that Django 2.0 removes some features that previously were in django.core.urlresolvers, so you might have to make some more changes before your code works. See … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)