(⌐■-■)
Does anyone know how to get user details in forms? Other than passing them from views?
Create the user details into session variable at the time of login
Lokdai
Hey guys .. i am beginner and want to learn more .. i stuck here anyone can help me class Post(models.Model): title = models.CharField(max_length=255) body = RichTextField() slug = models.SlugField() category = models.ForeignKey('Category', on_delete=models.SET_NULL,blank=True, null=True) class Category(models.Model): title = models.CharField(max_length=255) category_id = models.UUIDField(default=uuid.uuid4, unique=True ,editable=False ,primary_key=True) slug = models.SlugField() views.py def categoryPage(request): categories = Category.objects.all() return render(request, 'categories.html',{'categories':categories}) def index(request): posts = Post.objects.all() context ={'posts':posts} return render(request, 'index.html',context) Now.. i want to display posts of each category in sperate link for example I have Class 1 - Class 2 - Class 3 as categories i want when i press Class 1 link it take me to posts that related to this category only and show me math1 physi 1 and so on,, what should i use in views.py get or filter method sorry i am beginner and want to learn more
tech-tycoon
You have to pass an extra parameter in index() method which is category of class Then do this Post.objects.filter(category=Category.objects.get(class_category_parameter)) It will give you the posts which is related to class_category_parameter
Charly
I can help you
Then help instead of saying it
Д
Then help instead of saying it
I'm not committing to anything before people respond
Д
my suggestion would be to move away from functions and to use ViewSets — and at the same time explain how to pass them parameters
Lokdai
M Latif
I have two table 1 category 2 product I am going to get all products in spacific category and count how many products are exist in spacific category Anyone can help me then write query pls help me
Hirbod;
I have two table 1 category 2 product I am going to get all products in spacific category and count how many products are exist in spacific category Anyone can help me then write query pls help me
P = product.objects.filter(category="catgoryName") P.count() Category in filter is the foreign key model field that you should write in product model class
Marlon
Hello a question: I have a context from .models import AdminBase def admin_data(request): data = AdminBase.objects.all()[:1] dic_data = dict(data=data) return dic_data and when I call in the view it works like this <a href="#" class="nav-link">{% for d in data %}{{d.name}} / {{d.street}} {% endfor %} </a> But I do not want to be doing a for because it is not optimal, what do you recommend me to do instead of passing a dictionary to be able to take the value {{d.name}} without the for, Thanks
Owolabi
Hello guys, I'm creating an endpoint to retrieve a list of user notifications, I'm to display read and unread notifications separately, should I return the read and unread notifications in a single endpoint grouped in different arrays ("unread":[], "read":[]) or should I create a dedicated endpoint for each notification type which one is the best practice? Thanks.
Д
so I would solve the problem for now with the assumption that it's going to change anyway :) or well, write tests and let the tests drive the design
Owolabi
You can do something like this: name_list = data.values_list("name", flat=True)
This will return a list of names extracted from the queryset
Marlon
Thank you , i done ``` def admin_data(request): dic_data = AdminBase.objects.all()[:1] context = { 'dic_data' : dic_data[0], } return context ``` ``` <a href="#" class="nav-link">{{ dic_data.name }} </a> ```
Owolabi
so I would solve the problem for now with the assumption that it's going to change anyway :) or well, write tests and let the tests drive the design
I think having a dedicated endpoint for each notification type is the best in the long run as it goes bigger so we can independently control each response and pagination wise
Д
I think having a dedicated endpoint for each notification type is the best in the long run as it goes bigger so we can independently control each response and pagination wise
yeah it makes sense. i've personally tried to aggregate data into one query so I don't have to make multiple queries for the same data but I don't think it's horribly wrong to have 2 separate endpoints.
Charly
Did you loaded the static tag?
Shabbir
I want to update multiple models from a single page.... For example: In Entry.html I have a form which updates Author, Book, and Details of the book (It's Content) I have different models for all of that... I don't know how to pass all models to Entry.html from view.py and update all the models from single file.
Saddam
Plz any body send Django validation form fields like Name Email Contact number Gender Password Confirm password Validations like name must be character, contact number must be 10 num, email must have @ , password and confirm password should match.... If this conditions satisfied the details should store in database.. If anybody have this plz share...
༆𖤍ཽ🇻 G⃖r༙e༙y༙h༙a༙t༙⚚×͡×
How to redirect to back page through back button
Saddam
After clicking submit it store data in database
Akshay
You have to use the logic and build the code
Hirbod;
Kamlesh
https://stackoverflow.com/questions/18368207/django-emailfield-accepts-invalid-values
Kamlesh
Check this link
༆𖤍ཽ🇻 G⃖r༙e༙y༙h༙a༙t༙⚚×͡×
Doragonsureiyā
Anyone
Maybe anyone is here, yes, but they are not obliged to read everyone's message here neither to reply to everyone's message, if someone wants to reply to your message, they will do that, just don't try to draw attention to your message writing "anyone?" every 5 minutes, that will lead you to be warned for SPAM/Flood, just be patient or use Google/DuckDuckGo to research about your question instead of wasting time here waiting for people to do your work. Have a nice day 😊
Doragonsureiyā
Plz any body send Django validation form fields like Name Email Contact number Gender Password Confirm password Validations like name must be character, contact number must be 10 num, email must have @ , password and confirm password should match.... If this conditions satisfied the details should store in database.. If anybody have this plz share...
We're not here to do your job for you. This group is to help you on specific issues you have in YOUR code, so you have to show the code you wrote by yourself and explain where and why you are stuck... as simple as that. 🤷🏻‍♂️
Ricardo
Hi guys. I have to make that when the user selects from a select, the form fields appear according to what he chose dynamically, does anyone know a library to do it, I'm new to this
TheDoc
Hello Devs Dash or Django ?? (for a data scientist)
Д
Why ?
django was designed to write full applications where you are responsible for everything
Д
And Dash ?
is specifically designed for dashboards - while they are applications too, they generally require interaction with the backend, and place high requirements on the graphical\interactive nature of the frontend
Tony
guys i need a help in something
Tony
iam a beginner at django
Tony
i made a new project then i run the server then i delete the project without stopping the server
Tony
now i made a new project then i start the server it worked but when i press ctrl+c ... it doesn't work
Tony
and when i refresh the server page ... it doesn't change anything in the cmd
Tony
my laptop is 0% now
Tony
i will try to make you understand me
Tony
just a sec
Hiku
How to style django's loginview? Maybe from forms.py?
Hiku
Use css
Yes i know but How do I enter it? Like name = forms.TextInput({'class': 'form-control'})
Na ji Naa
Please suggest me good django course
Tony
Ok
when i run (127.0.0.1) on my browser the page show "the installed worked successfully " but when i try to shut down the server with ctrl+c will not work and the server will still running
Hirbod;
How?
Make a python file in your project folder either in shop or home app doesn't matter Name it context_processors.py Then add a global model in that file like this : def GlobalModels(request): return { "pro":product } And in your project setting folder under the TEMPLATES you will see 'options': { 'context_processors': [] Add 'appname.context_processors.GlobalModels' in the list
Tony
I think you have issue with your interpreter but I'm not sure
can i shut down the server by another way ? not using ctrl+c
Hoper
can i shut down the server by another way ? not using ctrl+c
As I know your command is not working wait I will try to find out solution
Moshe
Please suggest me good django course
If you have good knowledge in python and you know litel about the Web, you can start with the official django tutorial. Otherwise I do recommend "Django for beginners" by William S. Vincent, this is a good, I own it myself. If you a more video 📹 person, Harverd University have a nice course for django, check it on Edx. Good luck,
Tony
As I know your command is not working wait I will try to find out solution
i made a new project then i run the server then i delete the project without stopping the server can the problem be from this?
Hoper
i made a new project then i run the server then i delete the project without stopping the server can the problem be from this?
May be because it's runing in your server side... Do one thing close all project file browser first than restart all program as run file you want too
Hoper
and run file you want too //
Enes
bro exit rhe command line ant refresh your browser
Tony
and run file you want too //
okay i will try .. thx
Tony
bro exit rhe command line ant refresh your browser
i tried this ... the server will still running