conversion of datetime Field to string in django queryset.values_list()

https://docs.djangoproject.com/en/2.2/ref/models/fields/#datetimefield A date and time, represented in Python by a datetime.datetime instance. You can get a string representation of a DateTimeField casting it directly: str(obj) # obj = qs[0][0] ? or qs[0][1] ? You’ll get result like this (in this example I use datetime.datetime.now() since a DateTimeField is represented by datetime.datetime is the same behavior): … Read more

Django Migrations Add Field with Default as Function of Model

I just learned how to do this with a single migration! When running makemigrations django should ask you to set a one-off default. Define whatever you can here to keep it happy, and you’ll end up with the migration AddField you mentioned. migrations.AddField( model_name=”series”, name=”updated_as”, field=models.DateTimeField(default=????, auto_now=True), preserve_default=False, ), Change this one operation into 3 … Read more

How to store a dictionary on a Django Model?

If it’s really dictionary like arbitrary data you’re looking for you can probably use a two-level setup with one model that’s a container and another model that’s key-value pairs. You’d create an instance of the container, create each of the key-value instances, and associate the set of key-value instances with the container instance. Something like: … Read more

Django: dynamic database file

The django.db.connections is a simple wrapper around DATABASES defined in your settings. The wrapper class is here: django.db.utils#L137-L227 from django.db import connections # Add connection information dynamically.. connections.databases[‘new-alias’] = { … } # Ensure the remaining default connection information is defined. # EDIT: this is actually performed for you in the wrapper class __getitem__ # … Read more