Advertisement
Guest User

Untitled

a guest
Jan 9th, 2021
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. class RowInfo(models.Model):
  2.     class Meta:
  3.         abstract = True
  4.     updated = models.DateTimeField(default=django.utils.timezone.now())
  5.     created = models.DateTimeField(default=None)
  6.     #updated = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
  7.     #created = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
  8.  
  9.     def save(self, *args, **kwargs):
  10.         print(self.id)
  11.         self.updated = django.utils.timezone.now()
  12.         operation = 'I' if self.id is None else 'U'
  13.         if(operation == 'I'):
  14.             print('Insert operation')
  15.             self.created = django.utils.timezone.now()
  16.         else:
  17.             print('Update operation')
  18.        
  19.         super().save(*args, **kwargs)        
  20.  
  21.     def delete(self):
  22.         print(self.id)
  23.         operation = 'D'
  24.         print('Delete operation')
  25.         super().delete()
  26.  
  27. class Dicti(RowInfo):
  28.     code = models.CharField(max_length=255,null=True,blank=True)
  29.     numcode = models.IntegerField(null=True,blank=True)
  30.     fullname = models.CharField(max_length=255)
  31.     shortname = models.CharField(max_length=255)
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement