I was wondering what is the best way to get the current date in a django application. Currently I query the python datetime module – but since I need the date all over the place I thought maybe Django already has a buildin function for that. e.g. I want to filter objects created in the current year so I would
Tag: django-orm
Convert Django Model object to dict with all of the fields intact
How does one convert a django Model object to a dict with all of its fields? All ideally includes foreign keys and fields with editable=False. Let me elaborate. Let’s say I have a django model like the following: In the terminal, I have done the following: I want to convert this to the following dictionary: Questions with unsatisfactory answers: Django:
“except” statement with same exception class as parameter twice
In Python, how can I use except block with same exception name twice in try/except statements without need to wrap code into one more try/except block? Simple example (here each call of pages.get may raise the exception): For now, in my Django app I do handling like this (but I don’t want “extra” try block here): Any handling code better