Django2.0中文(models)

1、python manage.py startup yourapp
2 from django.db import models
models.CharField max_length
models.URLField
models.EmailField
models.ForeignKey
models.DateField
3 python manage.py validate
obj.save()
Obj.objects.all()
Obj.objects.create(xx=,x)
4 def __unicode(self):
return self.name
from django.db import models

class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()

**def __unicode__(self):**
    **return self.name**

5 Obj.objects.filter(name='xxx')
name__contains="aa"
Obj.objects.get(name="xxx")
Obj.objects.order_by("name","")
Obj.objects.order_by("-name") 逆序
6
class Meta:
ordering=['name']


class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()

def __unicode__(self):
    return self.name

**class Meta:**
    **ordering = ['name']**

7 Publisher.objects.order_by('name')[0] 但是不支持负索引
8 update: Publisher.objects.filter(id=52).update(name='Apress Publishing')
9 delete: obj.delete()

你可能感兴趣的:(Django2.0中文(models))