Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
TemplateDoesNotExist: polls/question_detail.html Django tutorial
Studied the tutorial up to the seventh part. Everything was fine until I decided to launch my application. After launch, I added a multiple choice question. The error occurs after I click on a question to answer it. Long searches for an answer did not bring any results. Please help. I get this error: TemplateDoesNotExist at /polls/1/ polls/question_detail.html Request Method: GET Request URL: http://127.0.0.1:8000/polls/1/ Django Version: 4.0.dev20210118085850 Exception Type: TemplateDoesNotExist Exception Value: polls/question_detail.html Exception Location: c:\users\mrand\django\django\template\loader.py, line 47, in select_template Python Executable: C:\Users\mrand\Anaconda3\envs\mysite\python.exe Python Version: 3.8.6 Python Path: ['C:\\Users\\mrand\\mysite', 'C:\\Users\\mrand\\Anaconda3\\envs\\mysite\\python38.zip', 'C:\\Users\\mrand\\Anaconda3\\envs\\mysite\\DLLs', 'C:\\Users\\mrand\\Anaconda3\\envs\\mysite\\lib', 'C:\\Users\\mrand\\Anaconda3\\envs\\mysite', 'C:\\Users\\mrand\\Anaconda3\\envs\\mysite\\lib\\site-packages', 'c:\\users\\mrand\\django', 'C:\\Users\\mrand\\Anaconda3\\envs\\mysite\\lib\\site-packages\\win32', 'C:\\Users\\mrand\\Anaconda3\\envs\\mysite\\lib\\site-packages\\win32\\lib', 'C:\\Users\\mrand\\Anaconda3\\envs\\mysite\\lib\\site-packages\\Pythonwin'] Server time: Wed, 27 Jan 2021 01:15:15 +0300 Traceback: Environment: Request Method: GET Request URL: http://127.0.0.1:8000/polls/1/ Django Version: 4.0.dev20210118085850 Python Version: 3.8.6 Installed Applications: ['polls.apps.PollsConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware'] Template loader postmortem Django tried loading these templates, in this order: Using engine django: * django.template.loaders.filesystem.Loader: C:\Users\mrand\mysite\templates\polls\question_detail.html (Source does not exist) * django.template.loaders.app_directories.Loader: C:\Users\mrand\mysite\polls\templates\polls\question_detail.html (Source does not exist) * django.template.loaders.app_directories.Loader: c:\users\mrand\django\django\contrib\admin\templates\polls\question_detail.html (Source does not exist) * django.template.loaders.app_directories.Loader: c:\users\mrand\django\django\contrib\auth\templates\polls\question_detail.html (Source does not exist) Traceback (most recent call last): File "c:\users\mrand\django\django\core\handlers\exception.py", line 47, in inner response = get_response(request) File "c:\users\mrand\django\django\core\handlers\base.py", line 204, in _get_response … -
Store JSON data in Django model
I am trying to send data from sensor to Django server using ESP8266. I sent the data in JSON format and used this code to convert it to python Dict but I can't store the sensors' values in the database, so any idea how to do that ? @csrf_exempt def index(request): print("\n") data = json.loads(request.body) type = data.get("SensorType", None) reading = data.get("Reading", None) print(type) print(reading) return HttpResponse("Hello") I made a sensortype row with charfield input and reading with integarfield input -
Django template cannot see model object
models.py from django.db import models from django.urls import reverse # Create your models here. class Post(models.Model): title = models.CharField(max_length=256) author = models.CharField(max_length=256) coverphoto_link = models.CharField(max_length=1000, blank=True) text = models.TextField() photo_link = models.CharField(max_length=1000,blank=True) date = models.DateTimeField(auto_now_add=True) def get_absolute_url(self): return reverse("basic_app:article", kwargs = {'pk':self.pk}) class Comment(models.Model): post = models.ForeignKey(Post,related_name='comments', on_delete = models.CASCADE) name = models.CharField(max_length=300) body = models.TextField() date_added = models.DateTimeField(auto_now_add=True) def __str__(self): return self.name article.html {% include 'base1.html' %} {% load static %} <br> <div class="container" id='container_article'> <div class="container2"> <h1>{{ article_detail.title }}</h1> <p class="author_detail" style="color: rgb(0, 4, 255);">{{ article_detail.author }} | {{article_detail.date }}</p> <br> <img id="photo" src="{{ article_detail.photo_link }}"> </div> <p id="articletext">{{ article_detail.text }}</p> <br> <br> <hr> <!--- HERE ---> <h2>Comments...</h2> {% if not post.comments.all %} No comments yet...<a href="#">Add one</a> {% else %} {% for comment in post.comments.all %} <strong> {{ comment.name }} - {{ comment.date_added }}</strong> <br> {{ comment.body }} <br> {% endfor %} <hr> {% endif %} </div> {% include 'footer.html' %} THe main problem is that I created comments at the admin secction, all good, but the page is still displaying "No comments yet...".See the <!--- HERE ---> part, there is the problem.I also registered the app and the model at admin.py. -
How to get Postgres (.sql) file generated by Django>
I am developing a website with Django and I connected Django to Postgres. Now I want to view the Postgres SQL generated by Django but I don't seem to find it. I know an SQL developer who wants to have a look at how the database is and I replied that I can absolutely get him the SQL file and I don't know how to, I've searched a lot and ended up asking here. -
Unable to register in a self hosted taiga.io docker instance; redis ConnectionError 99
I'm trying to spin up a taiga.io instance from https://github.com/taigaio/docker-taiga-5 but whenever I try to register, I have this error on my server: server_1 | File "/usr/local/lib/python3.7/site-packages/celery/app/task.py", line 570, in apply_async server_1 | **options server_1 | File "/usr/local/lib/python3.7/site-packages/celery/app/base.py", line 755, in send_task server_1 | self.backend.on_task_call(P, task_id) server_1 | File "/usr/local/lib/python3.7/site-packages/celery/backends/redis.py", line 294, in on_task_call server_1 | self.result_consumer.consume_from(task_id) server_1 | File "/usr/local/lib/python3.7/site-packages/celery/backends/redis.py", line 135, in consume_from server_1 | return self.start(task_id) server_1 | File "/usr/local/lib/python3.7/site-packages/celery/backends/redis.py", line 114, in start server_1 | self._consume_from(initial_task_id) server_1 | File "/usr/local/lib/python3.7/site-packages/celery/backends/redis.py", line 142, in _consume_from server_1 | self._pubsub.subscribe(key) server_1 | File "/usr/local/lib/python3.7/site-packages/redis/client.py", line 2229, in subscribe server_1 | ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels)) server_1 | File "/usr/local/lib/python3.7/site-packages/redis/client.py", line 2161, in execute_command server_1 | self._execute(connection, connection.send_command, *args) server_1 | File "/usr/local/lib/python3.7/site-packages/redis/client.py", line 2172, in _execute server_1 | connection.connect() server_1 | File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 442, in connect server_1 | raise ConnectionError(self._error_message(e)) server_1 | redis.exceptions.ConnectionError: Error 99 connecting to localhost:6379. Address not available. There is only this line regarding celery in the settings.py file: CELERY_ENABLED = True And there is strangely no redis service in the compose file. I don't really know in what direction to search... the README regarding a Docker setup doesn't seem to fully match the docker setup … -
Django OSError dont know how to resolve this error
File "C:\Users\Newto\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 141, in iter_modules_and_files resolved_path = path.resolve(strict=True).absolute() File "C:\Users\Newto\AppData\Local\Programs\Python\Python39\lib\pathlib.py", line 1204, in resolve s = self._flavour.resolve(self, strict=strict) File "C:\Users\Newto\AppData\Local\Programs\Python\Python39\lib\pathlib.py", line 200, in resolve return self._ext_to_normal(_getfinalpathname(s)) OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '<frozen importlib._bootstrap>' -
Django-summernote How can I make it work based on model form?
If you want to fix your relationship this is what you should be views What I did is based on this : https://github.com/summernote/django-summernote But it doesn't work. from django.shortcuts import render from django.views.generic import ListView, CreateView, UpdateView, DeleteView from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin from django.shortcuts import get_object_or_404 from django.contrib.auth.models import User from blog.models import Category, Comment, Post from .forms import PostForm # Create your views here. class PostCreateView(LoginRequiredMixin, CreateView): model = Post form_class = PostForm fields = ['category','title', 'content','image','status','excerpt','slug'] template_name = 'crud/new_post.html' # form_class = PostCreateForm def form_valid(self, form): form.instance.author = self.request.user return super().form_valid(form) crud/new_post.html <form method="post" enctype="multipart/form-data"> {% csrf_token %} {% bootstrap_form form layout="horizontal" size="small" label_class="form-label col-md-3" %} <div class="row"> <div class="col-12 text-center"> {% buttons %} <button type="submit" class="form-button btn btn-success"> Submit </button> {% endbuttons %} </div> </div> </form> -
How to create a model with a field that contains the unique values from a field in another model?
Using django 3.1.3 I have a model (Item) that holds all items submitted by users. All of these items are grouped into user-defined categories. Each record contains the item name and the category name. What I want to do is create a second model (Category) that will have two fields: category: populated with the unique values from the category field in (Item include: A boolean that indicates if 'category' should be included So lets say that model (Item) has the following unique categories: 'Clothes', 'Groceries', 'Chairs'. I want (Category) > category to contain one record for each of those unique values. How can I structure model (Category) to accomplish this? Here's the relevant portion of model (Item): class Item(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) created = models.DateTimeField(auto_now_add=True) include = models.BooleanField(default=False) quantity = models.PositiveIntegerField(default=0) category = models.CharField(max_length=20) item = models.CharField(max_length=50) And here's what I have for (Category): class Category(models.Model): include = models.BooleanField(default=True) category = ???? -
How to pass form_class data into model objects create in Django?
I want to create article form in Django. The code below getting Error FileModel.post" must be a "Article" instance. because i want to create multiple file related article instances which is coming from forgnekey. i need to pass example post=form.instances when i submit form data but i don't understand how can i pass FileModel.objects.create(post=self.form_class, file=f)? I would be grateful for any help. views.py class CreateView(CreateView): form_class = FileForm template_name = 'create.html' success_url = '/' success_message = "New story has been created successfully" def form_valid(self, form): form.instance.author = self.request.user for f in self.request.FILES.getlist('file'): FileModel.objects.create(post=self.form_class, file=f) # Error is here! return super().form_valid(form) -
Is it possible to fetch data and plot it to graph from REST API using only Django?
Because I have a chart on my django app. I also have django-filter on my rest_framework. where I can filter dates. start_date=$start_date&end_date=$end_date from a typical get data. def view_info(request): objs = test.objects.all() return render(request, 'test.html', {'objs': test}) I want to fetch the data directly to the REST API URL localhost:8000/api/test/?start_date=$start&end_date=$end Is it possible? this is how I fetch data from my chart. <script> $(document).ready(function(){ var ctx = document.getElementById('myChart').getContext('2d'); var myChart = new Chart(ctx, { type: 'bar', data: { labels: [{% for i in objs %}'{{i.timestamp}}',{% endfor %}], datasets: [{ label: 'Rainfall Graph', data: [{% for i in objs %}'{{i.amount}}',{% endfor %}], backgroundColor: [ 'rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(255, 206, 86, 0.2)', 'rgba(75, 192, 192, 0.2)', 'rgba(153, 102, 255, 0.2)', 'rgba(255, 159, 64, 0.2)' ], borderColor: [ 'rgba(255, 99, 132, 1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)', 'rgba(75, 192, 192, 1)', 'rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)' ], borderWidth: 1 }] }, options: { scales: { yAxes: [{ ticks: { beginAtZero: true } }] } } }); }); </script> -
Displaying Foreign Key Options in django restframework view
I'm having trouble displaying all the jobs as options in the apply url view see image below. I am getting the error which says Lists are not currently supported in HTML input The main function I am looking for is for a list of jobs that were posted to be available for selection when applying for the job. models.py class Job(models.Model): """A Job used to create a job posting""" user = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, ) description = models.TextField() job_type = models.CharField(max_length=12, choices=JOB_TYPE_CHOICES, default='Full-Time') city = models.CharField(max_length=255) def __str__(self): return self.description[:50] class Applicant(models.Model): """A applicant that can apply to a job""" job = models.ForeignKey(Job, related_name='applicants', on_delete=models.CASCADE) first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) email = models.EmailField(max_length=254) phone_number = PhoneNumberField() resume = models.FileField(upload_to=resume_file_path, validators=[validate_file_extension]) def __str__(self): return self.first_name I've removed some of the attributes in Job so that the code is not so long. serializers.py from rest_framework import serializers from django.utils.translation import ugettext_lazy as _ from core.models import Job, Applicant class JobSerializer(serializers.ModelSerializer): """Serializer for tag objects""" applicants = serializers.StringRelatedField(many=True) class Meta: model = Job fields = ('id', 'description', 'job_type', 'city', 'state', 'salary', 'position', 'employer', 'created_date', 'is_active', 'applicants') read_only_fields = ('id',) def create(self, validated_data): """Create a job posting with user and return it""" return … -
How to fix manytomany field in django
How to make a one to many relationship in Django/Mysql? I have an identical situation to this post, yet, my django returns errors on the admin page: get() returned more than one order2pizza-- it returned 5! order2pizza with that pizza already exists. My mysql database have composite keys on a tertiary table to order and pizza to link multiple pizzas to an order. models.py: class Orders(models.Model): order_id = models.AutoField(primary_key=True) order_name = models.CharField(max_length=100, blank=True, null=True) class Pizza(models.Model): Pizza= models.AutoField(primary_key=True) Pizza_name= models.CharField(max_length=50, blank=True, null=True) class order2pizza(models.Model): order = models.ManyToManyField(Orders, models.DO_NOTHING, ) pizza_id= models.IntegerField() class Meta: unique_together = (('order ', 'pizza_id'),) -
Error in hosting Django app with AWS Elastic Beanstalk
I was trying to host my Django app with AWS Elastic Beanstalk. I took help from their very own documentation here Upon doing whatever written there, I faced an error saying: "Internal Server Error" I tried finding out the solution. I found an answer in StackOverflow itself that removing the following part from my settings.py does the job. DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } } Well, it did for the very basic trial. I tried to host my eCommerce website on AWS using the same thing I learned. It showed the same internal server error. So I removed the DATABASE part from my settings.py. Now it shows the very obvious error: ImproperlyConfigured at / settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. .ebextensions/django.config option_settings: aws:elasticbeanstalk:container:python: WSGIPath: ebdjango/wsgi.py settings.py import os from pathlib import Path BASE_DIR = Path(__file__).resolve().parent.parent SECRET_KEY = 'my-secret-key' DEBUG = True ALLOWED_HOSTS = ['*'] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', # installed apps 'ckeditor', 'ckeditor_uploader', 'eshop', 'product', 'order', 'user', 'mptt', 'paywix', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'ebdjango.urls' TEMPLATES = [ … -
Why doesn't href from HTML to CSS work correctly with Django?
I have the next problem: Im ceating a basic django webpage using HTML and CSS. The issue is that when I try to make the href from the HTML file to the CSS one: <link rel="stylesheet" type="text/css" href="modelado.css"> It doesn't work correctly. my HTML file called "inicio.html" and "modelado.css" are in the same folder, but once I make the href, the console says this: Not Found: /inicio/modelado.css I think that the console is trying to find a folder called "inicio", but that's impossible since inicio is the HTML file from where I am running the program. What I want to know is if there is another way to write the direction, because that directory doesn't exist. I also think that this is a django related problem, because when I only use HTML, that line of code actually works when the files are in the same folder. Thanks! -
Do i need to manipulate DRF if only im using the built-in template django system?
I have some troubles understanding Django and DRF, if for instance I want to integrate a frontend framework along with Django, do I really need to use Django itself or will I touch DRF; and in the other hand, if I use the built in template django system, do I need to use DRF? please someone help me since I don't know the answer yet since I want to integrate a frontend framework such as Angular to developer my web page but I think I don't need Django, instead I need to use DRF! -
Issue with passing a file object as an argument of Django command
I'm trying to test a Django command by passing a file object as an argument: a_file = open('Sample.xml', 'rb') call_command("process_xml", a_file, self.valdate) and parse the xml file in the command: from lxml import etree, objectify from django.core.management.base import BaseCommand, CommandError from django.core.management import call_command class Command(BaseCommand): def add_arguments(self, parser): super(Command, self).add_arguments(parser) parser.add_argument( 'a_file', ) def __init__(self, **kwargs): super(BaseCommand, self).__init__(**kwargs) def handle(self, *args, **options): xml_file = options["a_file"] print(str(xml_file)) result = objectify.parse(xml_file) I got the error: File "/mnt/ccl/management/commands/process_xml.py", line 20, in handle result = objectify.parse(xml_file) File "src/lxml/objectify.pyx", line 1842, in lxml.objectify.parse File "src/lxml/etree.pyx", line 3521, in lxml.etree.parse File "src/lxml/parser.pxi", line 1859, in lxml.etree._parseDocument File "src/lxml/parser.pxi", line 1885, in lxml.etree._parseDocumentFromURL File "src/lxml/parser.pxi", line 1789, in lxml.etree._parseDocFromFile File "src/lxml/parser.pxi", line 1177, in lxml.etree._BaseParser._parseDocFromFile File "src/lxml/parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc File "src/lxml/parser.pxi", line 725, in lxml.etree._handleParseResult File "src/lxml/parser.pxi", line 652, in lxml.etree._raiseParseError OSError: Error reading file '<_io.BufferedReader name='/mnt/ccl/Sample.xml'>': failed to load external entity "<_io.BufferedReader name='/mnt/ccl/Sample.xml'>" However, if I open the file within the command module, with open('/mnt/ccl/Sample.xml', 'rb') as xml_file: result = objectify.parse(xml_file) There was no issue. Would appreciate if anyone can shed some light on this. -
What's the best way to run R script and use the results given in the output(csv file) using ReactJs
I have a React code that as an input 2 groupes of textes go then to the database to search for result and gives back 2 csv files. Then i should run an R script which uses these 2 csv files, make analysis then gives back a third csv file which i am going to render its content using react Js. Does anyone knows how to do such thing? Is it possible to launch all this cycle using a button? For now the button make first part only (outputes 2 csv files) but i didn't know how to launch the R script automatically when pressing the same button. Also i want to delete the 3 csv files because it will creates other files when doing the process again. I am using ReactJs and Django for the backend. If anyone can help would be appreciated -
Django Get content from FK of FK
I'm facing troubles with my django project. I have a three layer model: model.py class PLC(models.Model): name = models.CharField(max_length=50) class Measure(models.Model): class Meta: unique_together = ('PLC', 'address', 'is_bit') PLC = models.ForeignKey(PLC, on_delete=models.CASCADE) address = models.IntegerField() is_bit = models.BooleanField() class MeasureValue(models.Model): measure = models.ForeignKey(Measure, on_delete=models.CASCADE) value = models.TextField() In my view.py, I want to be able to get measures values out of the plc class PLCViewSet(viewsets.ModelViewSet): queryset = PLC.objects.all() serializer_class = PLCSerializer def measures(request, id): plc = PLC.objects.get(id=id) measures = Measure.objects.filter(PLC=id) values = MeasureValue.objects.filter(measure__PLC=id) context = { 'PLC': plc, 'MEASURES': measures, 'VALUES': values } return render(request, 'measures.html', context) Unfortunately, i cannot make a correct filter() (data are stored in sqlite base). -
How to automatically create new Profile once a new User is created in Django?
Currently running into this issue with my Django app that I am working on. I have a model class Profile that I want to be automatically created and assigned to a new user. Was wondering how I can do this? I do have a custom user model that I have set up as well. class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) -
How do I open a terminal in a Spyder project?
I am trying to publish my Django project to localhost but I cant' seem to open a terminal to do python manage.py runserver after that, my localhost is not working. Can someone help with that too? Thanks -
How can i use button to execute a view in Django?
Im using django to display some data of a database in a table, in that table a have a horizontal partition which separate data by date(old data and new data.) On top of the table ive created 2 button, "partition 1" and "partition 2" so when i click "partition 1" it displays me the data of the old partition. I would like to know how can when i click the button "old" to change the data in the main table(contains both new and old data) to the datas of old partition. Note: I have all views created for 3 of them. -
How to pass get object pk_ to inside of form valid function
I want to update an Article. i also get the Article(pk) data inside of Article(pk) form. when i try to submit the form data i'm getting this error FileModel.post" must be a "Article" instance because i need to pass the article(primary key) with FileModel (post=pk_) when i create new files which is related with Article, but i don't understand how can i pass the primary key from get_object function? I would be grateful for any help. VIEWS class UpdateViews(UpdateView): form_class = FileForm template_name = 'update.html' success_url = '/' def get_object(self): pk_ = self.kwargs.get('pk') FileModel.objects.filter(post=pk_).delete() return get_object_or_404(Article, pk=pk_) def form_valid(self, form): form.instance.author = self.request.user for f in self.request.FILES.getlist('file'): FileModel.objects.create(post=self.get_object.pk_, file=f) # here is the error return super().form_valid(form) -
Django Dependent Dropdown from API Response
I'm new to Django and developing an app for internal use. I've been following this scenario for getting a dependent dropdown to work, but not everything is relevant to what I'm trying to accomplish. I've got the first dropdown populated from my postgreSQL database. When a user selects the item (server), I want an API call to pull the latest information from that selected server to populate the second dropdown. So far I have been able to create the API session, but the GET request is sending the object ID rather than the object Name. I appreciate any ideas on how to get this to work. Below is what I have so far: forms.py class CreateForm(forms.ModelForm): class Meta: model = Argument fields = ('server', 'serv_cluster', 'number') labels = {'server':'Choose Server'} def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if 'server' in self.data: try: server_id = int(self.data.get('server')) except (ValueError, TypeError): pass views.py def load_clusters(request): server = request.GET.get('server') # getting obj ID but I want the obj Name session = create_session(server) # creates API session clusters = mgr(session).serv_cluster_list() # returns cluster names as a list return render(request, 'cluster_dropdown_list_options.html', {'cluster': cluster}) cluster_dropdown_list_options.html <option value="">---------</option> {% for cluster in clusters %} <option value="{{ cluster }}">{{ cluster … -
Redirect PasswordResetConfirm to Login on success
For a password reset, I'd like to redirect the user directly to the login screen, and skip the final "complete" screen. I've setup a view to use instead of the Django one: class CustomPasswordResetConfirmView(SuccessMessageMixin, PasswordResetConfirmView): success_url = reverse_lazy("login") success_message = "Your new password has been set. You may log in now." In urls.py path( "reset/<uidb64>/<token>/", CustomPasswordResetConfirmView.as_view(), name="password_reset_confirm", ), The same approach has worked just fine for the password change, when I link to a differnet "front" screen, and display a message, but here I am always linked to the standard "admin site" password_reset_complete view, with it's link back to login. How can I skip this and implement what I hope my custom view makes it obvious I'd like to do? -
How to connect tables that don't have direct link, using foreign key of other table in Django?
current connection of the tables Hello guys, Let sey I have three tables, Table1, Table2 and Table3. Table1 has foreign key of Table2 and Table3 has foreign key of Table2, but Table1 and Table3 aren't directly connected (as it seems redundant) - how can I access table3 from table1, using connection between Table1 and Table2, and then Table2 to Table3? More specifically, I want to add one column from Table3 to Table1 view in Django Admin and I am not sure how can I do it. Usually I would just add it as Table 3 foreign key in Table1 class, but that connection seems redundant, as they can connect through Table2. So my code looks something like that now: class Table2(models.Model): ... class Table3(models.Model) column_foreign_key2 = models.ForeignKey(table2) ... class Table1(models.Model): column_foreign_key = models.ForeignKey(table2) ... I want to achieve result as I would add class table1(models.Model) column_foreign_key3 = models.ForeignKey(table3) but without adding it, but going through table2 Sorry if that seems confusing