Questions tagged [django-2.1]

1

votes
2

answer
31

Views

Combining more than one slug in the url

I'm trying to use two slug for generate the urls of a type of post. My site is divided in category and everyone of these have one or more post. views.py def singlePost(request, slug_post): blogpost = get_object_or_404(BlogPost, slug_post=slug_post) context = {'blogpost': blogpost} return render(requ...
0

votes
0

answer
4

Views

Use django-filters on multiple models

I'm trying to create a search capability in my Django project that will filter multiple models (currently 3). It worked great for one model, worked when I added a second, but when I tried to add a dropdown menu for the third model, I got an error saying they keyword was unavailable (because it wasn'...
Bird
0

votes
0

answer
3

Views

Retrieving An Entire Table from Database using Drop-Down Menu Django

I am trying to figure out how I can create a drop-down menu which can display an “entire table” from the Django database backend. Note, each item of the drop-down menu is simply a reference to the table from the database and so that when an item is selected from the menu it should display the t...
aBiologist
0

votes
0

answer
8

Views

Django app goes haywire when deployed. Race conditions?

I wrote a django app for quizzing, and it checks the user's answers and updates scores as soon as the user submits an answer. Here is the corresponding view to do this - def check_answer(request): current_user = request.user current_team = Team.objects.get(user = current_user) current_score = curre...
Dushyant Yadav
0

votes
0

answer
3

Views

Redirect old path to a new path on website based on Django

After the solution of my problem with double slug now I'm faced with one thing totally new for me. I've never worked with the redirection! In urls.py my old path was: path('/', views.singlePost, name='single_blog_post'), Now I've have this: path('//', views.singlePost, name='single_blog_post'), With...
0

votes
0

answer
4

Views

How to implement Depended Drop Down List in Django administrator?

I have multiple dropdown lists that depended on each other as below: Province-->City-->Bakhsh-->Dehestan-->Abadi my models are: from django.db import models # Create your models here. class Province(models.Model): id = models.CharField(primary_key=True, max_length=2) name = models.CharField(max_leng...
mehdi parastar
1

votes
1

answer
269

Views

How to pre-populate Django ModelForm fields

I have the following ModelForm: class IssueProcessForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(IssueProcessForm, self).__init__(*args, **kwargs) self.fields['number'].disabled = True self.fields['title'].disabled = True self.fields['body'].disabled = True self.fields['body'].wid...
Caspian
1

votes
1

answer
162

Views

Is it possible to add 2nd slug to URL path in Django?

I'm using Django version 2.1. I want to create this type of URL Path in my Project: www.example.com/bachelor/germany/university-of-frankfurt/corporate-finance Is it possible to do it in Django?
Ulvi Damirli
1

votes
1

answer
26

Views

Object_list does not show correct data in template

I've a strange problem in Django template. It is a template for show a list of the articles and for everyone of they I show a list of keyword that I've called key concepts. The stranger thing is that instead of a list of key concepts it is shown a list of articles that use that key concept. Below th...
Massimiliano Moraca
1

votes
2

answer
245

Views

Celery can not find tasks nor settings with Django 2.1.1

I am trying to do Asynchronous task using Celery and RabbitMQ server. I have installed Celery and RabbitMQ on my system. Now when I'm running celery worker -l info, the celery starts working using default configuration settings ignoring my settings and it shows no registered tasks. I am assuming the...
SK. Fazlee Rabby
1

votes
1

answer
25

Views

Multiple querystring parameters

I've created this simple search function: def search(request): if 'q' in request.GET: querystring = request.GET.get('q') print(querystring) if len(querystring) == 0: return redirect('/search/') posts = Blog.objects.filter(title__icontains=querystring | tagline__icontains=querystring | contents__icon...
Massimiliano Moraca
1

votes
1

answer
42

Views

View thumbnails of uploaded images in django admin

I am trying to add thumbnails to list view in django admin. This is my admin.py for my app, i got this far: from django.contrib import admin from .models import Image from django import forms from django.db import models class ImageAdmin(admin.ModelAdmin): list_display = ('label','tag','order','Edit...
Adam
1

votes
2

answer
73

Views

How to redirect url from middleware in Django?

How to redirect url from middleware? Infinite loop problem. I intend to redirect the user to a client registration url if the registration has not yet been completed. def check_user_active(get_response): def middleware(request): response = get_response(request) try: print(Cliente.objects.get(usuario...
marcelo.delta
0

votes
0

answer
10

Views

Django test “django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')”

Django 2.1.5, with MySQL backend. My django app works. This issue is about test. Added query prints to django code, it's failing on this line: ALTER TABLE `documents` ADD CONSTRAINT`documents_assessment_perspecti_2890f0af_fk_assess_pe` FOREIGN KEY (`assessment_perspective`) REFERENCES `assess_pe...
Emily
0

votes
0

answer
2

Views

Django date filter - find a date in-between

I'm attempting to create a query that returns an event if it runs at any point in a given period of time between 2 dates. model: class MyModel(models.Model): start_date = models.DateField(auto_now=False, blank=True, null=True, verbose_name='Start date') hd_end_date = models.DateField(blank=True, def...
AppHandwerker
1

votes
1

answer
19

Views

Annotate but with non-Django supplied values

Is there any way to append a non-Django supplied value to a query? For instance, to find out if a store closed, I may run a function called get_closed_stores() which returns a list of closed stores. Stores Closed [00090, 00240, 00306, 00438, 03005, 05524] Great, now we have store numbers for stores...
CodeSpent
1

votes
2

answer
70

Views

Incorrect redirection for a single post category

I'm developing my personal blog; it has only two categories and I would like to have a specific list of posts for both categories. For this reason I've expand get_absolute_url as you can see below: from django.db import models from django.urls import reverse CATEGORY_CHOICES = ( ('G.I.S.', 'G.I.S.')...
Massimiliano Moraca
0

votes
0

answer
6

Views

How to change django-filter filtering key?

I've tried this way class ProductFilter(django_filters.FilterSet): section = django_filters.ModelChoiceFilter(widget=CustomLinkWidget, queryset=Category.objects.filter(parent=None), label='Раздел', field_name='subcategory__parent__parent__slug') Unfortunately filter keep doing this http://loca...
Nursultan Ergeshov
0

votes
0

answer
21

Views

Problem with ERR_TOO_MANY_REDIRECTS django 2.1

I started to create login module in django. Login module is ok but I have problem with logout. When i click Logout - we see 'error -ERR_TOO_MANY_REDIRECTS' Probably something in this file is incorect: account/urls.py from django.conf.urls import url from django.urls import path from django.contrib....
Martix
2

votes
1

answer
112

Views

Is it correct to modify old migration files in Django?

I'm trying to migrate my Django project from Python 2.7/Django 1.11 to Python 3.7/Django 2.1. And I'm a little bit confused with one issue. Django 2.1 marks as errors all models.ForeignKey(...) code strings in my project with: TypeError: __init__() missing 1 required positional argument: 'on_delete'...
kostr22
2

votes
1

answer
41

Views

How to include DRF 3.8 router url patterns in Django 2.1

from app_listing import views from django.urls import path, include from rest_framework import routers router = routers.DefaultRouter() router.register(r'category', views.CategoryViewSet) urlpatterns = [ path('api/', include('router.urls')) ] urlpatterns += router.urls Here is the error while trying...
Milan
4

votes
1

answer
2.8k

Views

django cannot import login from django.contrib.auth.views

I try to build a login function for my page. To edit the urls.py as followed, it keeps printing that 'cannot import name 'login' from 'django.contrib.auth.views' ' How could I deal with the problem? Thx! from django.contrib.auth.views import login from django.urls import path from . import views ap...
Thomas.Q
2

votes
1

answer
43

Views

Module 'django.db.models' has no attribute 'FileBrowseField'

I would like to have on my Django 2.1.1 site django-filebrowser-no-grappelli. I've followed this indications but at the end of the procedure, when I restart my server, I've this error: header_image = models.FileBrowseField('Image', max_length=200, directory='images/', extensions=['.jpg'], blank=True...
Massimiliano Moraca
2

votes
0

answer
144

Views

Connecting Vertica as Django backend

I want to connect Vertica as the database backend for my Django application. Officially no support is provided by Django to it. I googled this problem and found this: https://github.com/rutube/django_vertica_backend The code which is written in this git hub returning following error: Traceback (most...
2

votes
2

answer
130

Views

template_name in LogoutView not working on django2.1 python3.7

Below is default setting in django.contrib.auth.views.LogoutViews, template_name = 'registration/logged_out.html' i configurate my app's urls.py like this: from django.urls import path from . import views from django.conf import settings from django.contrib.auth.views import LoginView, LogoutView a...
Leon Li
1

votes
2

answer
20

Views

Order post by date

I've created a list of post and now I want order this list by date of publishing. If I use order_by(-post_publishing_date) in the view the shell show me this error: NameError: name 'post_publishing_date' is not defined models.py class PostModel(models.Model): post_title = models.CharField(max_lengt...
Massimiliano Moraca
1

votes
2

answer
49

Views

Highlighted post in Django templates

I've created this model: class PostModel(models.Model): post_title = models.CharField(max_length=70) post_short_description = models.TextField(max_length=200) post_contents = models.TextField() post_publishing_date = models.DateTimeField(auto_now=False, auto_now_add=True) post_author = models.Foreig...
0

votes
0

answer
28

Views

Python Django 2 template blocks overriding is not working

I'm working on a Python(3.6) and django(2.0) project in which I need to implement multiple templates with inheritance. Here are my templates: The first template is: dashboard-base.html: {% block header %} // Header content like loading css and js files along with title {% endblock %} {% block body...
Abdul Rehman
0

votes
0

answer
4

Views

Site matching query problem with redirects app

I would like to use 'redirects app' for redirect all paths from an old site to a new site. On my site I've already 'sitemap framework' and 'syndication feed framework'. Without 'redirects app' I don't have problems to see feeds page and sitemap page. I've followed the indications of the official gui...
Massimiliano Moraca
0

votes
1

answer
10

Views

regular expression not recognized by django

I'm new to Django and I'm trying to create a simple path to later link it to the database, for now: I created this URL path in my music app: urlpatterns = [ # /music/ path('', views.index, name='index'), # /music/*****/ path(r'^(?P[0-9]+)/$', views.detail, name='detail'), ] And I added this to the v...
Tessnim