myii
In django Rest Api model how can I calculate the age from the date of birth field i.e in backend it should work like today's date-birthdate =age but how to showcase this logic and how to do
I wrote a little util function I use for displaying any date intervals in years and months. You can adjust it for your own needs. To calculate the age from the DOB, you only need to supply the date_earlier: def display_date_interval(date_earlier='', date_later=''): # Set default values if blank if not date_earlier: date_earlier = datetime.date.today() if not date_later: date_later = datetime.date.today() # Work out which date really is earlier if date_earlier > date_later: date_a = date_earlier date_b = date_later sign = '-' else: date_a = date_later date_b = date_earlier sign = '' # Calculate the years and months avg_days_in_month = config.AVG_DAYS_IN_YEAR / config.MONTHS_IN_YEAR years = date_a.year - date_b.year - ( (date_a.month, date_a.day) < (date_b.month, date_b.day) ) months = int( ( (date_a - date_b).days - years * config.AVG_DAYS_IN_YEAR ) / avg_days_in_month, ) return f'{sign}{years}y {months}m'
myii
The config is coming in from constance but you can use literal values there if you prefer.
William
Looking for Wagtail or Django CMS developer/agency, preferably in China, project is to migrate WordPress site to Wagtail/Django CMS
William
I hope my question is specific enough (not meta)
LORD
See my first blog Django website
LORD
gkv8192.pythonanywhere.com
Justin
I don't understand what are you trying to do... any way, you can use template tags to evaluate some conditions and handle the "text" displayed to user. https://docs.djangoproject.com/en/2.2/ref/templates/builtins/#if
its a web app used to register for events happening in our college and if a user has already registered for an event the text should be "You have already registered" else the button should have the text "register" I am using a model having the user and the event as the foreign key attributes
Luis
its a web app used to register for events happening in our college and if a user has already registered for an event the text should be "You have already registered" else the button should have the text "register" I am using a model having the user and the event as the foreign key attributes
Ok, do you have this relationship data in the context you are using to render the template? If yes, then use template tag as I said. Else, add the relationship to the context (ex: overwriting the get_context_data method) and use template tag.
Luis
Remember django has reverse lookup for foreign keys. It might make this work easier... And sorry for my English grammar. I'm working to improve it. https://stackoverflow.com/questions/15306897/django-reverse-lookup-of-foreign-keys/15307225#15307225
areeb
Can anyone tell me how to generate a qrcode after form submission, I need some guidance on how to do this.
blank_
How to create login session? Please help
pino@mastrobirraio ~$
How to create login session? Please help
if u search "Login" in this group you will find al lot of solutions that can be help you :)
Anil Kumar G
Is it is possible to delete a data in website but it should still present in database?
pino@mastrobirraio ~$
mmh you can add a boolean field called is_archived, and when you perform the delete route you can set the value to True. Obv you need to filter the ListView using the is_archived field
Krunal
I have used modelform and need to use md5 encryption on one of the field before save into database. How can I do that?
Dhruva
I modified my models but not updating it when doing python manage.py migrate
Dhruva
I tried deleting migration file and then again ran makemigration still not working
Dhruva
Yaa
Dhruva
Before I updated it was working
Dhruva
I just added one field to the model class
Dhruva
And it's not registering
Abhi
Dhruva
U mean blank=false
Dhruva
Still not working
Abhi
Blank= true
Abhi
Blank= true
Or null=true
Dhruva
No...
Dhruva
Not working
Abhi
Give default as " "
Abhi
Give default as " "
A field which you just added in model
Dhruva
Hey it worked thanks bro
Anonymous
Hello, I am dba, in a client system that uses the ORM of Django 1.2 and SQL Server, there is a query that testing performance is possible to improve a lot by adding a SQL Server Option, but I know how to suggest this code change. I need to add "OPTION (FORCE ORDER)" to the query. Ex: Before: select col1, col2, col3 from table1 t1 join table2 t2 on (t1.id = t2.id) join table3 t3 on (t1.id = t3.id) order by col1, col2, col3; After: select col1, col2, col3 from table1 t1 join table2 t2 on (t1.id = t2.id) join table3 t3 on (t1.id = t3.id) order by col1, col2, col3 OPTION (FORCE ORDER);
Anonymous
Use raw query
Thank you, I will talk to the developers.👍
Lizeth
LOCALTIMESTAMP (3), LOCALTIMESTAMP (0)
José
Hi, i need help to migración of my models
José
I want to change name of table in db, but db_name un class Meta don't work
Dextroleav
I don't think so?
Abhi
Dynamic data?
Dextroleav
Dynamic data?
The data that changes
Abhi
The data that changes
I think you have to find some API which provide data every second and you can render it on front end
inchidi
https://forum.djangoproject.com/t/welcome-to-the-django-forum/
Anonymous
hi im searching about this error but i cant found good answer. (in stackoverflow say change version sqlite but i dont how change version sqlite) error: The above exception (no such table: main.auth_user__old) was the direct cause of the following exception
inchidi
yes
provide more information then
Anonymous
provide more information then
version: django = 2.1.5 python = 3.8.0 sqlite = 3.28.0
Dextroleav
Dextroleav
I think u used another table which DNE
Dextroleav
How can I run my django project in my phone and other devices during development time
cj
use a computer 🤷🏻‍♂️
Abhi
How can I run my django project in my phone and other devices during development time
Connect on same network and use computer's IP address in your mobile's browser
Abhi
I mean same like runserver, is it ?
Same network means same WiFi may be
inchidi
Ok
using ngrok is better option if thats what you want to do btw
Dextroleav
I used ngrok, but it only load home page, other links doesn't work due to change in url
Anonymous
How can I run my django project in my phone and other devices during development time
with editor online django https://repl.it/languages/django but is not very good
inchidi
Ok
technically you'll get the same issue using that approach btw
Dextroleav
other links? any example?
Lets say home page is loaded, then when i click on or try to go to other pages it through a error of url not found
Dextroleav
termux
No not like this
inchidi
Please help me
what you're trying to do? why you need to encrypt user input?
inchidi
How to create login session? Please help
django provide these views btw https://docs.djangoproject.com/en/3.0/topics/auth/default/#module-django.contrib.auth.views all of them session based
inchidi
Can anyone tell me how to generate a qrcode after form submission, I need some guidance on how to do this.
usually qrcode generated on client side and backend only store the data of that qrcode btw
Krunal
what you're trying to do? why you need to encrypt user input?
we have vendor management system. Every vendor has their own URL and password to login. I want to store url, username and password in database. so I want to encrypt password with MD5 method before store into database.
Dextroleav
404 from django or ngrok? give me example of the path you try to access
Django,because in the url file there is no url according ti ngork