Let’s assume that you have the following Django database model:
from django.db import models class Post(models.Model): title = models.CharField(max_length=100, ) date = models.DateTimeField() slug = models.SlugField(unique=True, )
In your mom.yaml file, you can refer to this model like this:
mom: map: post: model: myapp.models.Post lookupField: slug
post key in which we have
lookupField keys is the
name prefix for files that MOM will load and use.
As an example, we will create a serialization file that will target the
field: title: My Awesome Title date: 2021-06-25 13:00
As you can see, we don’t have the
slug field here. This is because
lookupField sets what the root name is going to be used for. In that
first-post will be the value of the
Now, you can run the MOM command:
$ ./manage.py mom
This will create the database row or update the existing row after you change the any of the values in the file and run the MOM command like above.