开发者

how do I access model fields individually?

su开发者_C百科ppose I have this model:

id = models.AutoField(primary_key=True)  
datetime_from = models.DateTimeField('time')

model = MyModel
def read(self, request, id=0):
    if not id:
        id = 0        
 MyModel.object 
    mmodel = MyModel.objects.filter(id__gt=id)
    return mmodel

My question is, how do I possible get the model fields individually, because I need to validate the datetime_from before I have to output the data on json format


You don't need to create an id column yourself. The read method is not necessary, either. Just say

from django.db import models

class MyModel(models.Model):
    datetime_from = models.DateTimeField('time')

You can then query the table like so

>>> obj = MyModel.objects.get(id=<target id here>)
>>> date = obj.datetime_from
etc.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜