Questions tagged [django-views]
Django views are MVC views; they control rendering (typically through templates), and the data displayed.
21,381
questions
0
votes
0
answers
27
views
Why am I getting a type error between two integers
I am trying to make the shopping cart of an e-commerce store and I've modelled the database and everything but I keep on getting a type error.
Storefront/Models.py/Product
from django.db import models
...
0
votes
1
answer
24
views
Django: Redirect from FormView to DetailsView upon submitting the form
Relevant FormView:
class addrecipe(FormView):
form_class = AddRecipeForm
model = Recipe
template_name = 'recipebook/addrecipe.html'
fields = '__all__'
extra_context = {
'recipe_list': Recipe....
0
votes
1
answer
11
views
Saving a file from FileResponse in Django
How to save file in FileField from FileResponse in Django.
I have the simplest PDF function to create PDF file in Django (according to the documentation).
import io
from django.http import ...
0
votes
0
answers
16
views
django edit and update multiple object of one form
I have one form for add information to table and in craete view I can copy the form as much I want and insert it to the table like this:
my form and can copy them
but when I want to edit and update ...
0
votes
1
answer
14
views
Showing many to many field as checkbox in template with createview
View:
class addrecipe(CreateView):
model = Recipe
template_name = 'recipebook/addrecipe.html'
fields = '__all__'
Model:
class Recipe(models.Model):
name = models.CharField(max_length=50)
...
0
votes
1
answer
13
views
Django and django rest framework saving profile information
How is possible to save profile information as I am using django rest api to login a user and the response which I am getting is with the help of requests library .what I want is to save the response ...
-2
votes
0
answers
19
views
how to make a view where user can select text, highlight and save as input for a readonly text field in django?
I am new to web programming and testing out a simple blog.
What I am trying to make is a Django view where non editable text field can get input only as highlight and maybe able to accept some ...
0
votes
0
answers
9
views
Django POST getlist for dynamic content
I a database I have a list of products. If they are need to be found = True they will appear in the screen :
<h2>Shopping list</h2>
<section>
{% for market in markets %}
<button ...
0
votes
1
answer
22
views
How can i call class function thats insert row into db properly from my django template?
Hellow, I am noob and I make instagram followers scraper on Django.
I make a function that should add 1 (only 1 cos it works really slow) new follower in to db which takes from already working ...
0
votes
0
answers
13
views
Need to perform update method on writable Nested serializers in django
models.py
class Product(models.Model):
product_id = models.CharField(max_length=50,default=uuid.uuid4, editable=False, unique=True, primary_key=True)
product_name = models.CharField(unique=...
0
votes
0
answers
19
views
Save many-to-many relationship after use the add() method on the field to add a record
I have models Book and I want to save new record this book after every update information about this book (duplicate information). It works good, but I don't know how to store many-to-many ...
0
votes
1
answer
22
views
How to validate foreign key with APIView
I'm learning django rest framework at school and now I'm on a internship project, I have some doubts using API base View.
I want to do a POST in a endpoint and validate if the foreign key exists or ...
0
votes
2
answers
35
views
Django: Update a value in html page without refreshing the page
I have a Rest API which I receive data every 10 seconds. I receive the data with time information that when the data sent. So, user should see the soonest data on the page.
That code would work but ...
0
votes
1
answer
14
views
The data/content isn't getting displayed. Can anyone please let me know any necessary changes to render the data?
Models.py
class Question(models.Model):
# id = models.AutoField(primary_key=True)
question=models.CharField(max_length=600)
option1=models.CharField(max_length=200, default=None)
...
0
votes
0
answers
17
views
Handling one template with multiple Django function
I have a template which contains feature to "fetch" the details and "edit" using Bootstrap Modal, from a API.
I created 2 functions, one to display data and one to edit
views.py
...
1
vote
1
answer
13
views
how do i icrement a filed on a model name:''order count' when an another model object is created in django
I have two models Customer and Order and I want to make 3 fields that are updating when an Order object is created. the fields are Order_Count:--, First_Order:order_date, Last_Order: order_date
how do ...
0
votes
0
answers
17
views
I am trying to retreive specific user information from django to react but I keep getting 404 error Not found
I keep I keep getting 404 error Not found when trying to retreive specific user information. Below is the django code for get request.
class ClientInformationView(APIView):
def get(self,request, *...
0
votes
1
answer
32
views
DRF : How to sum value from nested object and order by sum value
I've created serializing nested be using serializers as document
models.py
class Category(models.Model):
name = models.CharField("Name", "name", max_length=255)
iconname = ...
0
votes
1
answer
38
views
DRF How to display only not blank value of serializing nested object
I've created serializing nested be using serializers as document
models.py
class Category(models.Model):
name = models.CharField("Name", "name", max_length=255)
iconname = ...
0
votes
0
answers
12
views
Mass Upload Json data into Django Models using Views
I've been working on getting to learn Django and React to broaden my knowledge in Programming. I'm trying to create an API endpoint to Mass upload data from the front end (React) into Django models. ...
1
vote
1
answer
16
views
What is name and value attributes on a form Django
I am trying to find out what is name and value attributes in a form? On the example below what is the {{ current_name }} taken from in the form?
<form action="/your-name/" method="...
0
votes
1
answer
28
views
Why am I only getting default values when adding something to my database? (Django)
I'm trying to add tasks to my todo list. All of my added tasks are listed on the homepage (home.html) but whenever I try to add something it always sets my input to default (I added a picture at the ...
2
votes
1
answer
16
views
It is good practice to get all object in RetrieveUpdateDestroy Method?
Why we need to get all object in RetrieveUpdateDestroy Method?
In real project can I do it just like this Without fear even if there is large data?
0
votes
1
answer
17
views
Django - ModuleNotFoundError: No module named 'bootstrap5'
I am trying to run a django app which is made by some other developer. First I got *ModuleNotFoundError: No module named 'django_heroku'*That was solved by pip install django-heroku. Now I am getting ...
1
vote
1
answer
36
views
Is there a drawback to adding multiple indexes to a model in Django?
I'm working on a django dashboard to display data in a series of charts, and thusly need to set up different dataframes from my models.
When I load the dashboard up in production, it takes about 15 ...
0
votes
0
answers
12
views
DRF lost request.session on GET (but works when using DRF web interface)
I have a strange problem with the lost of request.session on DRF endpoint.
Here the code.
view.py
class DefaultPlant(APIView):
permission_classes = [permissions.IsAuthenticated]
def post(self,...
0
votes
0
answers
19
views
Django-celery can't work in another environment but work in localhost
I try to learn and pratice celery with Django and it works only in a localhost environment. The problem that I have is when I build it on another environment it returns an error like this
web_1 ...
0
votes
0
answers
15
views
How do you list blog posts from a specific category?
So the site is built similarly to a blog. Basically update=post and timeline=catagory
I'm trying to make a page where the categories are listed and you can click on them and it will list all the posts
...
0
votes
0
answers
24
views
Django .save() method not saving
I'm trying to save a text imput from an HTML page, and then display it on a redirect. It seems that the .save() method isn't working. I'm quite new to Django and HTML in general. I've followed the ...
0
votes
0
answers
16
views
Add a many-to-many relation to a Django many-to-many relation
I am making an offer creation module in Django, I have a product and a variant object, the product variant is connected with a many-to-many relationship. What I want to do is to save the products by ...
0
votes
1
answer
20
views
Django Views filter objects by user from custom model
I've created custom user model, and i'm trying to filter data in views.py by that user.
The error i get is:
'SomeClassView' object has no attribute 'user'
My goal is to 'encapsulate' data for each ...
0
votes
1
answer
16
views
How to query User model by 'custom' fields? (django.db.models.fields.related_descriptors.ReverseOneToOneDescriptor)
I extended the User model using my account app.
Model Account app:
from django.db import models
from django.contrib.auth.models import User
from departments.models import Department
class Account(...
0
votes
1
answer
17
views
How to force insert custom value in datetimefield(auto_now_add=True) while object creation in Django?
I have a model Test in service A
class Test(models.Model):
some_field = models.IntegerField()
created_at = models.DateTimeField(auto_now_add=True)
I am migrating data from a different ...
0
votes
0
answers
16
views
Django server not starting after importing python project as package
I have a deep learning python project named 'predict'. I want to use it in my django views so I use from predict.Prediction import Prediction where predict = root directory of python project, ...
-4
votes
0
answers
90
views
How to notify user when something happens in the models using post_save
I created an app where user's can post a question and get answers from others users.
Now I want to implement a notification system, so that when a user answer a question, the author of that question ...
0
votes
1
answer
20
views
DJANGO FORM - how to change save location file uploaded
i don't use models form but only form. How to change location file when i uploaded? i want the file just go to /mp3 folder. And now it not move to anything (the file didn't got upload).
and this my ...
0
votes
2
answers
30
views
How to fill 'initial value' in Django forms with current user data?
I went ahead and created a Form to update the user database entry.
class UserUpdateForm(forms.ModelForm):
class Meta:
model = User
fields = ("username", "first_name&...
0
votes
0
answers
12
views
Session information is not stored in the database(django-session table)-I have used a custom model and backend
I use multiple backend and models for user authentication
Default Django's model and a customized one . Default django authentication for admin-users and customized model and backend for customer-...
0
votes
0
answers
14
views
Filter Django ForeignKey Dropdown based on Current User
I am using django ClassBasedViews where I have a Project and Task Models. Each task is assigned to a project and both models register who created a recording in the created_by field.
class Project(...
0
votes
0
answers
13
views
With Django, should we be writing functions inside views, or importing them from another python file? [duplicate]
When writing functions for views, should they be placed within the specific views, outside of the views within views.py or inside a separate script such as viewsfunctions.py?
Is there any advantage/...
0
votes
0
answers
16
views
Display (4.0) Django models.JSONFields as form in webpage
I am working on a Django based website.
I have defined a JSONFields in my backend DB table , let's called it "CampaignTable"
The JSONFields is used to store Campaign parameters which might ...
1
vote
0
answers
18
views
getting problem with working nested json in django framework
Hi Everyone I am trying to writing a code to get nested response based on driver_id.
I am not able to solve this issue, kindly help me out.
views.py
def retrieve(self, request, *args, **kwargs):
...
0
votes
0
answers
11
views
Django Template View received post of other url and not display data
Okay, my problem is about context data that is not displayed in the template. First of all, I am pretty new in Django and js programing.
I have a first page with data sending, using ajax success (I ...
0
votes
0
answers
25
views
How can I order a table in Django without refreshing the whole page?
There is a feature in a Django application I'm working on that allows users to search the database by things like customer name, invoice number etc. The search result is rendered as a Django table ...
1
vote
2
answers
32
views
Django Many to Many 'QuerySet' object has no attribute 'members'
First, here is my Location model. It has one ManyToManyField called members.
Model:
class Location(models.Model):
name = models.CharField(max_length=200)
# ...
members = models....
0
votes
0
answers
12
views
How to render context when we open template from S3buckets?
I'm trying to render context in template. But I'm unable to do that. I'm opening my template from bucket and reading. Now how to render context.
render_param.update({'name': email.split("@&...
1
vote
1
answer
24
views
Cannot use None as a query value error when i try to view page without search query
I have a working search form in my base.html but when itry to access the listing page without passing a search query i get a "Cannot use None as a query value" error.
views.py
def listing(...
0
votes
0
answers
24
views
How to cache QuerySet in Django
I am starting with my web application in Django.
I tried to do some optimilization and look at queries and loading time. I did some refactor with select_related or prefetch_related, but I get stacked.
...
0
votes
3
answers
43
views
Django html display from model
I need on my html page to display data from Profesor and Ucenik model: ime, prezime, jmbg.
{{profesor.ime}}
{{profesor.prezime}}
{{ucenik.ime}}
{{ucenik.prezime}}
{{ucenik.jmbg}}
my profile page id ...
0
votes
1
answer
44
views
IntegrityError at /answer/ NOT NULL constraint failed: answer_answer.post_id
I have 2 models one for Question and one for Answer when i submitted answer form its throws me an error like this: IntegrityError at /answer/
NOT NULL constraint failed: answer_answer.post_id I'm ...