Django's operating table

1. The single-table queries must know will be 13

1.all, return all
2.filter, returns the object qualified
3.get, returns the object itself
4.first, returns the first
5.last, returns the last
6.exclude, returns do not meet the target condition
7.values, dictionaries list sets
8.values_list, listing set tuples
9.count, counting
10.distinct, deduplication
11.order_by, sorting
12.reverse, sorted inverted
13 .exists, returns a Boolean value

2. The magic double underline inquiry

__gt: greater than
__lt: less than
__gte: greater than or equal
__lte: less
__in = [a, b, c ]: a or b or C
__range = (a, b): In a, b intermediate (GU regardless of the end head)
__contains = '': comprising (case sensitive)
__icontains = '': comprising (ignore case)
__startswith = '': begin with what
__endswith = '': what end
__year / month / day = '': time is how many years / months / days

3. The method of many-to-four fields

add () to add information
set () amending,
remove () delete
clear () Clear

django test environment to build

​ import os
​ if name == "main":
​ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "one_search.settings")
​ import django
​ django.setup()

# You can test django py file in any of the following

If you see orm statement to internal real sql statement in two ways (second recommendation)

1. If an object is directly queryset query view point
2. profile disposed directly
the LOGGING = {
'Version':. 1,
'disable_existing_loggers': False,
'handlers': {
'Console': {
'Level': 'the DEBUG',
'class':' logging.StreamHandler ',
},
},
' Loggers': {
'django.db.backends': {
' handlers': [ 'Console '],
' Propagate ': True,
' Level ':' the DEBUG ',
},
}}

增:1.models.表名.objects.create(id="")

2.表名_obj = models.表名(id='')

    表名_obj.save()

改:1.models.表名.objects.filter(id="").update(name='')

2.表名_obj = models.表名.objects.filter(id='').first()

   表名_obj.name=''

   表名_obj.save()

删:models.表名.objects.filter(id="").delete(name='')

Charles:. 1.res = models table name .objects.all ()

for i in res:

    print(i.title)

2.res = models.表名.objects.filter()

    print(res)

Guess you like

Origin www.cnblogs.com/bjlxxbj/p/11735169.html