Jesse
How can i declare a model field that increase with time
Jesse
?
William
What are you trying to achieve?
William
How-to get an age of a person, if you're given datefield (birthdate) in model.py def get_age(self): today = date.today() return ?
You can use something like this. Import datetime def get_age(self): return datetime.date.today().year - date_of_birth.year
Islom
You can use AJAX $(#next_profile).click(() =>{ # logic })
I'm not familiar with Ajax yet, any alternative way to do that?
William
try def str(self): return {self.birthdate.year}
William
check in admin age what is the value for the above function
Islom
Try using JavaScript EventListener
any referencial example to see how to do that?
William
any referencial example to see how to do that?
1. https://www.w3schools.com/js/js_htmldom_eventlistener.asp 2. https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events
Islom
try def str(self): return {self.birthdate.year}
I just tried to write the code in views.py, that you provided above, now it works. Great!
Islom
If I try to do something similar to that in models.py, it doesn't work tho, weird :\
Ankit
Can anyone tell what do you understand by usermanagement using django?
Ankit
Is it registration page,login page and logout?
William
Islom
https://stackoverflow.com/a/59131016/12540183 check this
Yea, I've searched a bit, before actually asking here. But this doesn't work either, so anyways, I found what works for me, thank you!
Sanjana
Exception in thread django-main-thread: Traceback (most recent call last): File "C:\Users\Sanjana Raghuwanshi\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner self.run()......
Anonymous
I want to add multi product in my cart at the same time but IDK how do it! this is my code! {% for product in products %} <tr class="{% cycle 'bg-gray-200 dark:bg-dark-1' '' %}"> <td class="border-b dark:border-dark-5">{{product.name}}</td> <td class="border-b dark:border-dark-5">{{product.price}}</td> <td class="border-b dark:border-dark-5"><input type="text" class="input w-24 border" placeholder="amount"></td> </tr> {% endfor %} how can I do it ? this will be show a list of products to users but when user click on the submit button I don't know how I most to handle it!
Anna Karolina
https://imgur.com/JREmgc9 I need to create data with this, how can I do it, a light at the end of the tunnel?
Almaz
Hello guys, where can you store several gigabytes of video, as cheaply as possible, and could be connected with Django?
autobot
Hello guys, I am looking for consultation with project defence and running itself. Of course, for payment.
akash
Hlo everyone Actually I'm new in django I need a help i have two models in second model i to use post request and need some elements in first one with their already fill data and then use that overall i have make many to one relationship but had that issue that how i get that fields in our model please help me Thanks 🙏
akash
Please help me
Vishnu
Hello guys, How can I accept formulas (in latex code) in input field .
akash
Can u explain it one more time
Yes sure Model 1- fields - name, email, address, postal code, family members , Model 2- site address, property type, section, name(from 1) , phone (from 1) , postal code (from1) Relationship between them is one to many
akash
I want stored value of that fields which comes from model 1 And other have to fill that time
akash
Share the two models code or Image
I still not get how to implement that that's why i didn't make any of them
Dev__master
Yes I understood, you want to update model 2 fields after giving values in 1st model right?
akash
And some fields also go with that in post request of second model
Dev__master
Then use update query for 2nd model while you updating that 1st model
Anonymous
Yes
Add insert query to 2 nd model while inserting datas to 1 st model
Dev__master
Exactly, Hazzi
akash
I have to fill only model second data and i need some data of first model with that then post that
Dev__master
Actually we are not getting what exactly you are trying to say..
Dev__master
Try to give exact info then we can help you...Thanks
akash
Ok
akash
I try
Zvs
Good day guys, the question is, how can I get the likes counter, that is, Json, which is written in the view, with JS so that the operations of the views themselves are not performed, but simply receive json, so I implemented a script that supposedly should pull out json, he does so, he just does the vshka operation, that is, he adds a like and then only takes json .... how can I fix this?
Dev__master
Try to use to model2.objects.create(name=variable of name)
akash
I already fill a person data with model 1 Model 1- fields - name, email, address, postal code, family members , Now i need to make a project of costomer with help some of my own data and second model data which has the project elements Model 2- site address, property type, section, And the data of my own which i stored earlier which is required to make project is this name(from 1) , phone (from 1) , postal code (from1) So i need to post that aal data to make a project Relationship between them is one to many. One person can make many projects
Dev__master
Try to give image of your code so that we can help you
akash
Actually i have to make only api json data
akash
Media is not allow in this group
William
One person can create many projects and other users can also see the projects created by every other users?
akash
Yes
William
In model2 instead of name rename it as user and use it like user = models.ForeignKey(MODEL_1, on_delete=models.CASCADE)
William
Then in request.POST use user=request.user
Stealth
Hi, has anyone did api testing in rest framework?
William
akash
Previous elements means?
Means model one elements
akash
Read only = true
akash
Something
akash
My name phone postal code
William
in user field in Model2 add related_name='model1_name_in_lowercase') data = Model2.objects.get(id=pk) data.relate_name(from model2 user related_name attribute)
William
Model1: name="Abcd" Phone=... Postal_code=... Model2: Site_address=some_value Property_type=category_choices user=every user will have a unique id. You don't have to include phone_number in model2 As you will have user info in model1 so you can retrieve from model1
akash
Yesss exactly
William
Do you want to do something like when the user enters the info and clicks submit thise info should be created and displayed in web page
akash
No
akash
Only they Store
Dev__master
Rule 5️⃣: To share code or error tracebacks, use an online pasting service like: - https://del.dog - https://dpaste.org - https://linkode.org - https://hastebin.com - https://bin.kv2.dev If you posted a wall of text, go back and delete it.
akash
Then after go to next step wher the other data will add on that
Dev__master
Paste your code
akash
Paste your code
I'm not using laptop at that time
William
related_name https://docs.djangoproject.com/en/3.2/ref/models/fields/#django.db.models.ForeignKey.related_name
akash
9557572716 that's my whatsapp number
Anonymous
Hi guys! I'm trying to handle a DoesNotExist error (is a part of a bigger process that handles muliple record sets) when I look for a object with an specific value Model.objects.get( column = value ) And as expected it's not found. I did code a try except (specifying the exception) and it enters, but Django still stops the execution. Is it possible not to stop the execution? I've tried "pass" statement and have same result.
Vishnu
Hello guys How can we display mathematical formula in webpages