I am using Django REST framework and have been trying to create a view that returns a small bit of information, as well as register it on my router.
I have four models which store information, and all of them have a created_time
field. I am trying to make a view that returns the most recent objects (based on the created_time
) in a single view, where only the four creation times are returned.
So, a possible JSON output from the view would look like
{
"publish_updatetime": "2015.05.20 11:53",
"meeting_updatetime": "2015.05.20 11:32",
"training_updatetime": "2015.05.20 15:25",
"exhibiting_updatetime": "2015.05.19 16:23"
}
I am also hoping to register this view on my router, so it appears with the rest of my endpoints when the API root is loaded.
router.register(r'updatetime', views.UpdateTimeView)
Here are the four models that I am trying to work with
class Publish(models.Model):
user = models.ForeignKey(MyUser)
name = models.CharField(max_length=50)
created_time = models.DateTimeField( default=datetime.now)
class Meeting(models.Model):
user = models.ForeignKey(MyUser)
name = models.CharField(max_length=50)
file_addr = models.FileField(upload_to=get_file_path)
created_time = models.DateTimeField(default=datetime.now)
class Training(models.Model):
user = models.ForeignKey(MyUser)
name = models.CharField(max_length=50)
image = models.ImageField(upload_to=get_file_path, max_length=255)
created_time = models.DateTimeField(default=datetime.now)
class Exhibiting(models.Model):
user = models.ForeignKey(MyUser)
name = models.CharField(max_length=50)
file_addr = models.FileField(upload_to=get_file_path)
created_time = models.DateTimeField(default=datetime.now)
Is it possible to do this? And how would it be done?
created_time
(that would result in them all being the same). How are these four models supposed to be retrieved? How would it normally be done in a view?