Vishal
While filtering Do something like this Media_data = media.objects.filter(inventory_id=pk) #here pk is the id you'll get from the url
I got your point but, I need all those media instance merged with corresponding inventory instance
david john
https://gist.github.com/vashuteotia123/6ed32a541cb5392b57b99c86b905826c Please take a look at this. In views.py function call I need Media instance of every Inventory instance. A syntax help would be appreciated.
Try adding a kwarg related_name on your ForeignKey field on your Jewelry model. jewel_object = models.ForeignKey( Inventoryofjewellery, on_delete=models.CASCADE, related_name="jewelry_medias") Every instance of your inventory contains a property of jewelry_medias that contains the media instance. inventories = Inventory.objects.filter(<any filter kwarg>) for inventory in inventories: inventory.jewelry_medias.image1.url
Phill
What's happening in my app is that I have a view that fetches all data in the dB and I assume "hands it over" to the serializer. Then the serializer gets some detail from the url via a query, say x coordinate, and calculates a distance from that for each data row. Then I need to filter out the data rows to return only those that have a distance shorter than say 5. The problem is, it seems like I can't filter out the data received
Phill
Pass the instance of queryset that you filtered to your serializer. data = Model.objects.filter(name="something") serializer = CustomSerializer(data, many=True) return Response(serializer.data)
From your solution, I'm wondering if I'd be able to refilter the data based on a condition that only exists in the serializers context?
Phill
As in, how to refilter the query set without the query set's rows having the distance field in the database?
david john
As in, how to refilter the query set without the query set's rows having the distance field in the database?
From what I understand you need to filter the data based on the query and calculated column, am I right?
Hardik
Collectstatic
Okay, thank you. I will try
Badal Kumar
Django has clear documentation of how to manage static files
david john
From what I understand you need to filter the data based on the query and calculated column, am I right?
May I know the fields you need to calculate on something? I assumed that you will need to use annotate to base your filter on some calculated column. Lets assume that your data contains a column name x1 and x2. That 2 columns is needed to calculate the distance, and we need to filter the distance greater than 5. data = Model.objects.annotate(distance=F("x1") - F("x2")).filter(distance__gt=5)
Phill
Which I'm only getting at the point when I make the extra fields for the serializer
Proton
Hi good evening Please is there a way to disable video or file download in django
Phill
So maybe I need to get the url params before the serializer? so that maybe I factor it in the objects.filter()?
Proton
As in you won't allow files to be download on the website
Phill
As in you won't allow files to be download on the website
I don't think that's something generally doable on the backend if you provide the file to the browser, but I guess you can stream a video under some conditions rather than give it whole to the browser; but that again won't save you from advanced downloaders
Proton
Ow okay
Proton
Thanks alot
Phill
Maybe someone else has an opinion, I'm not that seasoned in developing web applications
Proton
Can any one recommend a tutorial on how to make a video purchasing website Where you the admin uploads videos and someone buys them
Proton
Any good material you can recommend
Proton
that's too specific, search for a ecomerce tutorial instead
With ecommerce, you can buy and still buy again But in this situation, when you buy the product, it should always show in your feed as bought
Charly
With ecommerce, you can buy and still buy again But in this situation, when you buy the product, it should always show in your feed as bought
well you may need to make this part but the basics fo selling things you can get from a tutorial
Proton
well you may need to make this part but the basics fo selling things you can get from a tutorial
Sure @Carlangueitor, I have created a number of ecommerce projects But this is something I'd like to try my hands on
Umarzoda
Hello everyone, is there a video related to cpanel? I cannot host my website on the Internet, I have a host and a domain
Phill
Something like what onlyfans or YouTube movies uses
Mark
How to make in url pattern off app link like - admin/some_app/some_model/add/custom_page?
Mark
It's not work urlpatterns = [ path(r'^admin/events/event/add/something', views.hello) ]
Mark
i can't go to link localhost/admin/events/event/add/something
Alireza
i can't go to link localhost/admin/events/event/add/something
Which port your project is on? You didn't mention it in your url, It will be okay only when you are using the port 80
Mark
stock server ip 127.0.0.1:8000
Doragonsureiyā
Looks like you need an offtopic group, please continue this conversation at @pythonofftopic as it's not related to Python
Max
Hey guys I have some struggle with an HTML canvas. I would like to build a simulation with round about 1000 entities. These entities should be represented in this Canvas (with pixijs) and controlled asynch over the django backend. Does anyone has a clue if this is possible to do? And how? Thanks a lot!
Pablo
Hi everyone. I am having problems understanding django rest framework token authentication
Saurabh
Anyone have experience with offline conversion Bing API
Saurabh
Can you please tell , how to command over python?
Adhil latheef
Which serializer field name can read hexadecimal in serializer field?
Syed
Anyone know how to connect database table to matplotlib in django?
Syed
Plz help
fn
Hi all! Need a little bit of help, thnx in advance! https://stackoverflow.com/questions/70602829/how-to-make-a-query-using-multiple-foreign-key-fields-of-django-models
Siddhartha
hey all, i wanna make a payment gateway but have zero clue of how to start anything regarding it, any helps or leads appreciated
Anshu
hey all, i wanna make a payment gateway but have zero clue of how to start anything regarding it, any helps or leads appreciated
Your own payment gateway like stripe, razorpay or you want to accept payments through these in your application??
tech-tycoon
Hello guys
tech-tycoon
Can anyone tell me how can i show my local videos in video tag
Anshu
Can anyone tell me how can i show my local videos in video tag
<video width="500" height="400" controls autoplay> <source src="{% static "video.mp4" %}" type="video/mp4"> </source> </video>
Anik8
You should use on_delete in foreign key
Anik8
Try to put the name of the model under ' ' (quotes)
Anik8
For example Company = models.ForeignKey('company', on_delete=models.CASCADE)
Maxim
go back to the basics of Python and find out what positional arguments are
david john
So maybe I need to get the url params before the serializer? so that maybe I factor it in the objects.filter()?
If the url parameter is needed to calculate the distance, yes you must need it firs, or make it optional. Lets assume the URL parameter is named value. if not request.get("value"): #display all the data if the value is None data = Model.objects.all() else: #Filter the data by distance of x1 and the value. data = Model.objects.annotate(distance=F("x1") - request.get("value")).filter(distance__gt=5) I may help you more if can provide a snapshot of your current code and some visual diagram on how you want your application behaves.
Python Guy
"detail": "JSON parse error - Expecting value: line 2 column 14 (char 15)" what exactly this error is? I treid sending data but got this
𝕯aniel
Delete ','
𝕯aniel
Or u are not send correct format
Anonymous
Hi good evening to all Tiger one doubt. I have return form request.POST I want to return value using the function. HttpResponse("your first name is "+output) How can I store form firstname value to output variable Thank you ?
Anonymous
I am using this function output = request.POST.get("fname") But I got this output Your name is None Is it correct or wrong
Ridha
Hii I need help, I am trying to create a simple todo application using django, There I have an option to edit and remove the tasks.. For that how to fetch the collumn I'd to edit? In my SQL I am using
Anik8
Hii I need help, I am trying to create a simple todo application using django, There I have an option to edit and remove the tasks.. For that how to fetch the collumn I'd to edit? In my SQL I am using
Get the id of the particular task from the frontend to your view And fetch that particular data from the database. Then provide the instance to your form . For example def updateTask(request, pk): obj = Todo.objects.get(id=pk) Form = todoform(request.Post,instance=obj)
Ridha
Thanks
Ridha
It's working now
Mysterious
Hi i need a help. How can i store two servers celery logs into a single file with a centralized server?
Gomathi
Hi, I designing online course portal using django, in registration form need to authenticate mobile number using otp. I used two library django-auth and twilio to authenticate. But getting error. Is there, any other library r way to proceed. Kindly advice