I am using Django 1.7 and I have a problem with my lights.
I would like Django to use the default value or use the save() method to create undefined values.
Here are my current objects:
# File: uuidable.py import uuid from django.db import models from django.utils.translation import ugettext_lazy as _ class Uuidable(models.Model): uuid = models.CharField(_('uuid'), blank=True, null=False, unique=True, max_length=64, default=uuid.uuid4())
As you can see, when generating a new Post() , the created_at , updated_at and uuid values โโare automatically created on save() . But when I use appliances, I get the following error:
[...]initial_data.yaml': Could not load post.Post(pk=None): UNIQUE constraint failed: post_post.uuid
If I specify uuid in my fixture file, I get a created_at error message and then updated_at . Therefore, I must indicate the contents of each field, even if I want it to be โautomaticโ.
From the documentation (why is it in django admin docs ?!), I know that the save() method is not called so therefore everything that I entered in the save() method does not work. But should you not enable / use the default or auto_now* functions?
When the archive files are processed, the data is saved in the database as is. The simulated save () methods are not called, and any pre_save or post_save signals will be called with raw = True, since the instance contains only attributes that are local to the model. For example, you can disable handlers that access the associated fields that are present at boot time, and otherwise throw an exception.
Is there a way to โforceโ Django to automatically use the default or auto_now* functions for fixtures? I use manage.py syncdb to create all tables, etc.
I searched google and stack overflow, but could not find the right keywords to search.
UPDATE-1 . The next google group discussion says that objects are saved in raw mode, which means that auto_now* functions auto_now* not taken into account. I'm still trying to check if there is a way to bind some of the model's functions to saving a Django device.