djongo icon indicating copy to clipboard operation
djongo copied to clipboard

auto_now_add and auto_now not working on EmbeddedField or ArrayField

Open giordy84 opened this issue 4 years ago • 0 comments

I have three models where the first has created_at = models.DateTimeField(auto_now_add=True)

the second one imports the first one with ArraField and has in turn updated_at = models.DateTimeField(auto_now=True)

The third imports the second.

Upon saving, the fields "created_at" and "updated_at" remain null. I need help. thanks


class Message(models.Model):
    message = models.TextField()
    user = models.ForeignKey(Login, on_delete=models.CASCADE, related_name='user')
    created_at = models.DateTimeField(auto_now_add=True)
    is_read = models.BooleanField(default=False)
    is_deleted = models.BooleanField(default=False)

    def __str__(self):
        return self.message
    
    class Meta:
        abstract = True


class Conversations(models.Model):
    messages = models.ArrayField(model_container=Message,)
    updated_at = models.DateTimeField(auto_now=True)

    objects = models.DjongoManager()

    def __str__(self):
        return f'{Groups.objects.get()}'

    class Meta:
        abstract = True


class Groups(models.Model):
    name = models.CharField(max_length=80)
    conversations = models.EmbeddedField(
        model_container=Conversations
    )

    objects = models.DjongoManager()

    def __str__(self):
       return self.name

```

giordy84 avatar May 20 '21 08:05 giordy84