0

I have a very simple model:

class challenge(models.Model):
    challenge = models.CharField(max_length=255)
    timestamp = models.DateTimeField('date published',null=True,blank=True)
    code = models.CharField(max_length=255)

And that model is linked via Tastypie.

By default the timestamp field is empty when you add an entry.

I would like to update the timestamp field with the time that the user first accessed the resource.

For example, if admin added data is:

Challenge: Do something
Timestamp: Null
Code: 123

Then after accessing /api/challenge/1/?format=json to have the output be:

{"challenge": "Do something", "code": "sasdasd", "id": 2, "resource_uri": "/api/challenge/2/", "timestamp": "2015-05-11T12:18:54"}

Is this possible using Tastypie and how?

3
  • When is 11/11/11 22:22:22? Is that the time a user accesses the resource? Can you show us your API code?
    – user764357
    May 11, 2015 at 0:03
  • Ok, I was typing that out off the top of my head, output is : {"challenge": "Do something", "code": "sasdasd", "id": 2, "resource_uri": "/api/challenge/2/", "timestamp": "2015-05-11T12:18:54"}
    – R0b0tn1k
    May 11, 2015 at 10:19
  • API code right now is just: class challengeResource(ModelResource): class Meta: queryset = challenge.objects.all() resource_name = 'challenge'
    – R0b0tn1k
    May 11, 2015 at 10:20

0

Your Answer

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

Browse other questions tagged or ask your own question.