django-2.0

How to filter choices in Django2's autocomplete_fields?

时间秒杀一切 提交于 2019-12-04 11:13:21
问题 In Django 2.0, autocomplete_fields was added, which is great. Without autocomplete_fields, I can change the queryset of a ForeignKeyField using formfield_for_foreignkey. But combining the two together doesn't work - it looks like the list of options for autocomplete is dynamic and coming from a different url, instead of from the current form. So the question is - How can I change the queryset in the autocomplete widget? 回答1: Override the ModelAdmin's get_search_results method to use the query

Getting 404 not found using path() in Django

ε祈祈猫儿з 提交于 2019-12-03 18:12:02
问题 I was just checking out django, and was trying a view to list the books by passing id as an argument to the URL books/urls.py . But getting 404 page not found error. I'm not getting whats wrong in the url when I typed this url in the browser: http://192.168.0.106:8000/books/list/21/ bookstore/urls.py urlpatterns = [ path('admin/', admin.site.urls), path('books/', include("books.urls")) ] settings.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes

Django 2.0: sqlite IntegrityError: FOREIGN KEY constraint failed

断了今生、忘了曾经 提交于 2019-12-03 15:51:04
I'm working on adding Django 2.0 support to the django-pagetree library. During automated testing, using an sqlite in-memory database, I'm getting a bunch of errors like this: File "/home/nnyby/src/django-pagetree/pagetree/tests/test_models.py", line 638, in setUp 'children': [], File "/home/nnyby/src/django-pagetree/pagetree/models.py", line 586, in add_child_section_from_dict ... File "/home/nnyby/src/django-pagetree/venv/lib/python3.5/site-packages/django/db/backends/base/base.py", line 239, in _commit return self.connection.commit() django.db.utils.IntegrityError: FOREIGN KEY constraint

How to filter choices in Django2's autocomplete_fields?

不羁的心 提交于 2019-12-03 06:11:40
In Django 2.0, autocomplete_fields was added, which is great. Without autocomplete_fields, I can change the queryset of a ForeignKeyField using formfield_for_foreignkey . But combining the two together doesn't work - it looks like the list of options for autocomplete is dynamic and coming from a different url, instead of from the current form. So the question is - How can I change the queryset in the autocomplete widget? Peter DeGlopper Override the ModelAdmin's get_search_results method to use the query you want. You can see in the get_queryset method for the view providing the data for

ImportError: No module named 'django.core.urlresolvers'

流过昼夜 提交于 2019-11-27 00:29:19
Hi I am working on Django project where I need to create a form for inputs. I tried to import reverse from django.core.urlresolvers . I got an error: line 2, in from django.core.urlresolvers import reverse ImportError: No module named 'django.core.urlresolvers' I am using Python 3.5.2, Django 2.0 and MySQL. knbk 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

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

纵然是瞬间 提交于 2019-11-27 00:16:31
I have two classes in my sqlite database, a parent table named Categorie and the child table called Article . I created first the child table class and addes entries. So first I had this: class Article(models.Model): titre=models.CharField(max_length=100) auteur=models.CharField(max_length=42) contenu=models.TextField(null=True) date=models.DateTimeField( auto_now_add=True, auto_now=False, verbose_name="Date de parution" ) def __str__(self): return self.titre And after I have added parent table, and now my models.py looks like this: from django.db import models # Create your models here. class

ImportError: No module named 'django.core.urlresolvers'

前提是你 提交于 2019-11-26 09:21:44
问题 Hi I am working on Django project where I need to create a form for inputs. I tried to import reverse from django.core.urlresolvers . I got an error: line 2, in from django.core.urlresolvers import reverse ImportError: No module named \'django.core.urlresolvers\' I am using Python 3.5.2, Django 2.0 and MySQL. 回答1: 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

NoReverseMatch with keyword argument uidb64 with Django 2.0

一个人想着一个人 提交于 2019-11-26 07:43:33
问题 I can\'t understand why my code doesn\'t work. Before it worked, but now, when I run the server and test, the code does not work. When the user is registering, I send him activation email, like this: def send_activation_email(serializer, request, user): current_site = get_current_site(request) message = render_to_string(\'acc_active_email.html\', { \'user\': user, \'domain\': current_site.domain, \'uid\': urlsafe_base64_encode(force_bytes(user.pk)), \'token\': account_activation_token.make