假设我有这个模型:
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
我的问题是,如何才能单独获取模型字段,因为我需要在json格式输出数据之前验证datetime_from
答案 0 :(得分:1)
您无需自行创建id
列。也不需要read
方法。只是说
from django.db import models
class MyModel(models.Model):
datetime_from = models.DateTimeField('time')
然后您可以像这样查询表格
>>> obj = MyModel.objects.get(id=<target id here>)
>>> date = obj.datetime_from
etc.