-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmodel_example.py
44 lines (33 loc) · 1.52 KB
/
model_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from django.db import models
from wagtail_airtable.mixins import AirtableMixin
class YourModel(AirtableMixin, models.Model):
name = models.CharField(max_length=200, blank=False)
slug = models.SlugField(max_length=200, unique=True, editable=True)
@classmethod
def map_import_fields(cls):
"""
Maps your Airtable columns to your Django Model Fields.
Always provide explicit field names as to not accidentally overwrite sensitive information
such as model pk's.
Return a dictionary such as: {'Airtable column name': 'model_field_name', ...}
"""
mappings = {
# "Name" is the column name in Airtable. "name" (lowercase) is the field name on line 8.
"Name": "name",
# "Slug" is the column name in Airtable. "slug" (lowercase) is the field name on line 8.
"Slug": "slug",
}
return mappings
def get_export_fields(self):
"""
Export fields are the fields you want to map when saving a model object.
Everytime a model is saved, it will take the Airtable Column Name and fill the appropriate cell
with the data you tell it. Most often this will be from self.your_field_name.
Always provide explicit field names as to not accidentally share sensitive information such as
hashed passwords.
Return a dictionary such as: {"Airtable Column Name": "update_value", ...}
"""
return {
"Name": self.name,
"Slug": self.slug,
}