xxxxxxxxxx
Model.save() does either INSERT or UPDATE of an object in a DB,
Model.objects.create() does only INSERT.
Model.save()
UPDATE If the object’s primary key attribute is set to a value that evaluates to True
INSERT If the object’s primary key attribute is not set
or if the UPDATE didn’t update anything
(e.g. if primary key is set to a value that doesn’t exist in the database).
xxxxxxxxxx
from django.db import models
# importing slugify from django
from django.utils.text import slugify
# Create your models here.
class GeeksModel(models.Model):
title = models.CharField(max_length = 200)
slug = models.SlugField()
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super(GeeksModel, self).save(*args, **kwargs)