-2

我对 Django 很陌生,但这可能吗?如果可以,究​​竟需要什么?我检查了文档,找不到我要找的东西。

#models.py
class Car (models.Model):
    make = models.CharField(max_length=100)
    year = models.IntegerField(max_length=4)


car = Car(make = "Toyota", year = 2011)

*Code in question, will this result in true?*
if (car):
    //do stuff

谢谢你的帮助。

4

1 回答 1

0

你可以做这样的事情:

car = Car.objects.create(make = "Toyota", year = 2011)

if car:
    # do some thing
    # here you have access to car object like this car.make , car.year
于 2013-09-29T07:01:00.543 回答