Anonymous
Abrar
return render (request, self.template_name,context={'data':data}
R.U.S.H.A.B.H
Hs anyone made Django project for student and teacher?? I want tl build that app but not getting how to handle many users with 2 administration!?
R.U.S.H.A.B.H
I saw similar django app on GitHub, long time ago.
Can you share in personal message?? Please
Beka
Can you share in personal message?? Please
I don't know. You should look on GitHub.
Beka
Class ListTaskView(ListView): model = task Field = "__all__"
or you can simple add another field called context_object_name and use it for your template.
Anonymous
You don't have to pass the context
Actually I want to return count of category ( another model in my app) to that view
Beka
Actually I want to return count of category ( another model in my app) to that view
You definitely need get_context_data if you want another data to your another template.
Anonymous
def get_queryset(self): return *whatever you want to*
Beka
define a get_queryset fuction
How he shows in template?
Anonymous
How he shows in template?
context_object_name
Beka
context_object_name
he wants to show data from another model. You got it?
The
I tried twice for training manager. Their interview process is worst.
Anonymous
he wants to show data from another model. You got it?
See I have two model Task and category I am rendering list of task...it is working fine. Now I want to show count of category available.
Anonymous
Both in the same template?
Yes...just a count of category
Beka
I have no idea, how your model connected. If two model isn't conntedted then you need to work with get_context_data. If somehow connected then you need to focus on getting categories with related_name.
Anonymous
Class ListTaskView(ListView): model = task catCount = Category.objects.all().count() Field = "__all__" And I want to pass catCount to my template
Anonymous
What will be the correct approach?
Beka
Use get_context_data
Anonymous
Use get_context_data
Ok buddy...can you give me a example Otherwise will get through google Thanks
Beka
also, you shouldn't pass field, too.
You passed field model, which is already known what fields have task model
Beka
Welcome!
Beka
I just want to show how you can use django generics. You are doing it little bit wrong way. class ProductCategoryView(ListView): model = Product template_name = 'product/product_category.html' context_object_name = 'products' paginate_by = 6 paginate_orphans = 1 page_kwarg = 'category' Focus on first three fields. This is the correct approach of using generics.
Anonymous
Ok thanks....buddy😊
Lone
Hey,I know the basics of python,oops concepts, HTML and CSS is it possible for me to learn and understand Django framework
Beka
Possible!
Lone
Hey thx man that motivated me
dilip
Hi,I am hosting django on IIS webserver.for load balancing I have 2 servers. The problem comes up with media files. If user 1 logs in, it might take to server1 or server 2 randomly. So if user stores a file in server and sometime in future he wants to view it, but server is logged to server 2.it throws a error saying no file exist. So I created a shared path and assigned that path to media files in settings. Now the problem is path says permission denies on hosting site, but runs fine on url. Any thoughts how to fix it??
dilip
Basically any idea how to set up a common storage server??
Chandraprakash
How to save extra fields along with username,password while registering a new user in Django rest framework
Chandraprakash
Please help if anybody knows about this
Chandraprakash
I m creating a api which takes users details and I have register that user in the system along with all the information he gave
Chandraprakash
How to do that
Chandraprakash
Do you have any video or something
Chandraprakash
I can refer to
Beka
Serializers.serializermethodfield()
serializermethodfield only for read only man.
Mehmet
How to do that
https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html This post shows how to handle extending the User model.
Mehmet
I personally use a secondary OneToOne related Profile and implement custom authentication and authorization over User and Profile via DRF
dilip
Can we serialize multiple models in a single serializer in REST framework
Mehmet
Can we serialize multiple models in a single serializer in REST framework
Yes definitely. https://www.django-rest-framework.org/api-guide/relations/ Be sure you created querysets with select_related or prefetch_related workarounds to handle N+1 errors
Mehmet
If there is not a relationship between models to be serialized, you can use serializermethodfield. In order to handle N+1 errors again cache your subquery per object with a single query by overriding outer serializers init function.
Mehmet
I answered supposing your need is nested multiple serializer, if you wish to create single depth multiple serializer then you can use SerializerMethodField, or JsonField if your base field is JsonObject. SerializerMethodField is always insecure because it may leak memory if you use global variables, and it is very high probability that you create N+1 situation, always try to log your queries in development.
dilip
Reason?
Needed for my project. Have 4 models where 3 models are foreign keyed to parent model.
Anonymous
But u should write 3 serializers for child models..and inherite them in the parent serializer
Rishabh
Hi friends, I want to create a website , Using django in which pdfs is uploaded n there is one search bar . Function of search bar is to list out pdfs which contains particular searching word
Rishabh
Any 1 please. Help
Rishabh
How much this took the time to create this website
Beka
Just do it, man. Just do it.
Anonymous
Anybody here Contributing to Django open source?
محمد دلشاد
how can i use mobile number otp verification in django??
i hate milk
hello all. how can i check that the request was made on the frontend?
i hate milk
maybe i need jwt-tokens? or not?
Sai
Hi guys i am designing a app and i need to render google maps by passing.dynamic maps url every time. How do i pass to iframes from django
Doragonsureiyā
Hi guys i am designing a app and i need to render google maps by passing.dynamic maps url every time. How do i pass to iframes from django
Step 1: Open a browser Step 2: Write down https://google.com or https://duck.com and press Enter Step 3: In the search box write down the same words you asked here Step 4: Read the firsts results
محمد دلشاد
We can use foriegn key relation to get all datas in a select dropdown How can i only get the data which are have a specific value in its one field
محمد دلشاد
https://hastebin.com/suciluzuxo.coffeescript