I’m building a Django project and I have a Django app for the login, which I called members. The project is behind the login, so all the URLs redirect to the login page if the user is not logged. If the user inputs an existing user and password, the user can access to the site. This workd OK. If the
How do I solve django.db.utils.IntegrityError: UNIQUE constraint failed? error code is django.db.utils.IntegrityError: UNIQUE constraint failed: Movies_comment.user_id, Movies_comment.tv_or_movie_id. This error occurs Comment(comment=form.cleaned_data[“comment”],user=request.user,stars=form.cleaned_data[“stars”],tv_or_movie=tv_or_movie_object).save() views.py models.py helper_views.py Answer tv_or_movie before saving i.e.
models.py: This is my views.py file. I show error at: bestseller = Product.objects.filter(product__category__icontains=’BestSeller’) views.py: I want to Bestseller category product at index.html I use Django 4 and pyhton 3.9 Answer You can’t use CharField as a ForeignKey. It should be like this: Or like this (the same logic): This will output all Products in category with name BestSeller.
I am beginner and I am working on Django project – risk assessment application. I have a trouble to achieve saving on related objects for my application risk record. I am using MultiModelForm to achieve the following. I am successfully creating Whatif instance and connecting it with GuideWordi instance on save, however, I am not able to connect my RiskRecordi
I have a JSON array in my server in Django rest framework, but I want to filter them by category , for example some of them have ‘category’:1 and some of them have ‘category’:2 like this: How can I add the following JSON to a new URL based on its “category”: 2? views: urls: Answer Assuming that this thingy you
I am trying to plot fusion chart in django after adding fusioncharts,I am getting an error. Answer Normally when you get such an error it is because you forgot to install the module, did a bit of research and came to the conclusion that you can install using pip: open the command prompt use the command pip install twFusionCharts.If this
I want to let the user upload multiple images per post. Similarly to an e-commerce platform with multiple images per product. But till now the images are not sent to the database. That’s my code so far: models.py: forms.py: views.py: project_form.html: settings.py: project urls.py app urls.py Answer Issue: You have made ProjectForm which relates to Project model, but the image
So I’m trying to create a table of hosts, and as one of the fields of that table include a clickable link to an update page. Which will pass the host_id to the update page. I was hoping someone could tell me what I’m doing wrong with regards to passing the correct parameter to upate/<host_id>. As I’m not quite sure
I have a profile form that shows email, user name and first name. user only allowed to change first name field and the others are read only, if user change HTML value in email and username then submit it, it returns error but fill the fields with invalid value entered. I tried create a new instance of form and render
I have two models, Account model & Thread model: If I have already created a thread that is ForeignKey to the Account model, I am not able to change the username of the Account model, returning the error FOREIGN KEY constraint failed. I guess the existing Thread model require a username to point to. Is there way to create a