1

I am writing/learning my first Django REST API. The database I am working on has all times are stored as an integers representing the seconds since Jan 01 1970 - aka Unix/Epoch time.

Right now I simply have two function that convert between this integer and a normal timestamp. So user input through parameters is converted to integers, and JSON responses are converted to timestamps.

I was wondering if there was a way to simply have Django "know" this conversion. So in my model:

class User(models.Model):
    createDate = models.IntegerField(blank=True, null=True, db_column='createdate')

I could change to models.DateTimeField and createDate would be a time stamp. Correspondingly if I call:

data = Subgroup.objects.filter(createDate_gt='2016-30-04')

In my view Django knows to convert this to an integer and filter by that, rather than the string interpretation.

I know it's a pretty pedantic request but I've been impressed with Django so far and was curious :)

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.