Вопрос

This is part of my code.

My imports:

import jinja2
from jinja2 import evalcontextfilter, Markup, escape
import os
import hashlib
import logging
import json
import re
import webapp2
from string import *
import random
import hmac
import xlwt
from datetime import datetime, date, time, timedelta
import time as tiempo
from models import *

One of my models:

class Combustible(SqliteModel):
    cini = DateTimeField()
    cfin = DateTimeField()

And when I execute this line of code:

combus=Combustible.select().where(Combustible.cfin.year==3000).count()

I get this error:

AttributeError: 'DateTimeField' object has no attribute 'year'

I use peewee as orm.

What is driving me crazy is that it doesn't work in one computer but it works fine in another. The python and lib versions are the same.

Anybody can help me?

Это было полезно?

Решение

I would double and triple-check your peewee versions.

Другие советы

To quote from the datetime documentation:

class datetime.datetime(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])

The year, month and day arguments are required. tzinfo may be None, or an instance of a tzinfo subclass. The remaining arguments may be ints or longs, in the following ranges:

Your class sets cfin to DateTimeField(), which should be equivalent to datetime.datetime(), see here:

DateTimeField A date and time, represented in Python by a datetime.datetime instance.

So no year, month or day are provided by your code. This is vorbidden if you trust the datetime documentation

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top