Exemplo n.º 1
0
    def save(self, *args, **kwargs):
        now = timezone.now()

        # set Point
        [
            self.set_lat_lng(name, getattr(self, name))
            for name in self.get_all_field_names()
            if isinstance(self._meta.get_field(name), geo.PointField)
        ]

        # create first time record
        if self.created_at is None:
            self.site = Site.objects.get_current()
            self.created_at = now
            self.created_at_timestamp = to_timestamp(self.created_at)
            if self.created_by:
                self.owned_by = self.created_by
                self.owned_at = self.created_at
                self.owned_at_timestamp = self.created_at_timestamp

        # always update
        self.updated_at = now
        self.updated_at_timestamp = to_timestamp(self.updated_at)

        # save the first time record
        instance = super(_BaseAbstract, self).save(*args, **kwargs)

        # generate id62
        if self.id and not self.id62:
            self.id62 = base62_encode(self.id)
            kwargs['force_insert'] = False
            instance = super(_BaseAbstract, self).save(*args, **kwargs)

        return instance
Exemplo n.º 2
0
 def save(self, *args, **kwargs):
     instance = super(AbstractUser, self).save(*args, **kwargs)
     if self.id and not self.id62:
         self.id62 = base62_encode(self.id)
         kwargs['force_insert'] = False
         instance = super(AbstractUser, self).save(*args, **kwargs)
     return instance