Skip to content

Commit 607ab40

Browse files
committed
working on autofield and integerfield examples
1 parent 218ed56 commit 607ab40

File tree

3 files changed

+4339
-0
lines changed

3 files changed

+4339
-0
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
title: django.db.models AutoField Example Code
2+
category: page
3+
slug: django-db-models-autofield-examples
4+
sortorder: 50107
5+
toc: False
6+
sidebartitle: django.db.models AutoField
7+
meta: Python code examples for the AutoField class used in the Django ORM, found within the django.db.models module of the Django project.
8+
9+
10+
[AutoField](https://github.com/django/django/blob/master/django/db/models/fields/__init__.py)
11+
is a [Django ORM](/django-orm.html) mapping from your Python code to an
12+
integer-type column in your [relational database](/databases.html).
13+
14+
The [Django](/django.html) project has great documentation for
15+
[AutoField](https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.AutoField)
16+
as well as all of the other column fields.
17+
18+
Note that `AutoField` is defined within the
19+
[django.db.models.fields](https://github.com/django/django/blob/master/django/db/models/fields/__init__.py)
20+
module but is typically referenced from
21+
[django.db.models](https://github.com/django/django/tree/master/django/db/models)
22+
rather than including the `fields` module reference.
23+
24+
25+
## Example 1 from django-axes
26+
[django-axes](https://github.com/jazzband/django-axes/)
27+
([project documentation](https://django-axes.readthedocs.io/en/latest/)
28+
and
29+
[PyPI package information](https://pypi.org/project/django-axes/)
30+
is a code library for [Django](/django.html) projects to track failed
31+
login attempts against a web application. The goal of the project is
32+
to make it easier for you to stop people and scripts from hacking your
33+
Django-powered website.
34+
35+
The code for django-axes is
36+
[open source under the MIT license](https://github.com/jazzband/django-axes/blob/master/LICENSE)
37+
and maintained by the group of developers known as
38+
[Jazzband](https://jazzband.co/).
39+
40+
[**django-axes / axes / migrations / 0001_initial.py**](https://github.com/jazzband/django-axes/blob/master/axes/migrations/0001_initial.py)
41+
42+
```python
43+
~~from django.db import migrations, models
44+
45+
46+
class Migration(migrations.Migration):
47+
48+
dependencies = [
49+
]
50+
51+
operations = [
52+
migrations.CreateModel(
53+
name='AccessAttempt',
54+
fields=[
55+
('id',
56+
~~ models.AutoField(verbose_name='ID',
57+
~~ serialize=False,
58+
~~ auto_created=True,
59+
~~ primary_key=True)),
60+
('user_agent', models.CharField(max_length=255)),
61+
('ip_address',
62+
models.GenericIPAddressField(null=True,
63+
verbose_name='IP Address')),
64+
('username', models.CharField(max_length=255,
65+
null=True)),
66+
('trusted', models.BooleanField(default=False)),
67+
('http_accept',
68+
models.CharField(max_length=1025,
69+
verbose_name='HTTP Accept')),
70+
('path_info',
71+
models.CharField(max_length=255,
72+
verbose_name='Path')),
73+
('attempt_time',
74+
models.DateTimeField(auto_now_add=True)),
75+
('get_data',
76+
models.TextField(verbose_name='GET Data')),
77+
('post_data', models.TextField(verbose_name='POST Data')),
78+
('failures_since_start',
79+
models.PositiveIntegerField(verbose_name='Failed Logins')),
80+
],
81+
options={
82+
'ordering': ['-attempt_time'],
83+
'abstract': False,
84+
},
85+
),
86+
migrations.CreateModel(
87+
name='AccessLog',
88+
fields=[
89+
~~ ('id', models.AutoField(verbose_name='ID',
90+
~~ serialize=False,
91+
~~ auto_created=True,
92+
~~ primary_key=True)),
93+
('user_agent', models.CharField(max_length=255)),
94+
('ip_address',
95+
models.GenericIPAddressField(null=True,
96+
verbose_name='IP Address')),
97+
('username', models.CharField(max_length=255, null=True)),
98+
('trusted', models.BooleanField(default=False)),
99+
('http_accept',
100+
models.CharField(max_length=1025,
101+
verbose_name='HTTP Accept')),
102+
('path_info',
103+
models.CharField(max_length=255,
104+
verbose_name='Path')),
105+
('attempt_time',
106+
models.DateTimeField(auto_now_add=True)),
107+
('logout_time', models.DateTimeField(null=True,
108+
blank=True)),
109+
],
110+
options={
111+
'ordering': ['-attempt_time'],
112+
'abstract': False,
113+
},
114+
),
115+
]
116+
```
117+
118+
119+
## Example 2 from django-filer
120+
[django-filer](https://github.com/divio/django-filer)
121+
([project documentation](https://django-filer.readthedocs.io/en/latest/))
122+
is a file management library for uploading and organizing files and images
123+
in Django's admin interface. The project's code is available under the
124+
[BSD 3-Clause "New" or "Revised" open source license](https://github.com/divio/django-filer/blob/develop/LICENSE.txt).
125+
126+
[**django-filer / filer / migrations / 0003_thumbnailoption.py**](https://github.com/divio/django-filer/blob/develop/filer/migrations/0003_thumbnailoption.py)
127+
128+
```python
129+
# -*- coding: utf-8 -*-
130+
from __future__ import unicode_literals
131+
132+
~~from django.db import migrations, models
133+
134+
135+
class Migration(migrations.Migration):
136+
137+
dependencies = [
138+
('filer', '0002_auto_20150606_2003'),
139+
]
140+
141+
operations = [
142+
migrations.CreateModel(
143+
name='ThumbnailOption',
144+
fields=[
145+
~~ ('id', models.AutoField(verbose_name='ID',
146+
~~ serialize=False,
147+
~~ auto_created=True,
148+
~~ primary_key=True)),
149+
('name', models.CharField(max_length=100,
150+
verbose_name='name')),
151+
('width',
152+
models.IntegerField(help_text='width in pixel.',
153+
verbose_name='width')),
154+
('height',
155+
models.IntegerField(help_text='height in pixel.',
156+
verbose_name='height')),
157+
('crop',
158+
models.BooleanField(default=True,
159+
verbose_name='crop')),
160+
('upscale',
161+
models.BooleanField(default=True,
162+
verbose_name='upscale')),
163+
],
164+
options={
165+
'ordering': ('width', 'height'),
166+
'verbose_name': 'thumbnail option',
167+
'verbose_name_plural': 'thumbnail options',
168+
},
169+
),
170+
]
171+
```

0 commit comments

Comments
 (0)