Pastebin
Paste #25066: No description
< previous paste - next paste>
Pasted by Anonymous Coward
class ProjectCode(models.Model):
code = models.CharField(max_length=200, unique=True, db_index=True)
project = models.ForeignKey(Project, on_delete=models.PROTECT)
active = models.BooleanField(default=True)
rate = models.DecimalField(blank=True, null=True, max_digits=10, decimal_places=2)
max_hours = models.IntegerField(blank=True, null=True)
date_start = models.DateField(blank=True, null=True)
date_end = models.DateField(blank=True, null=True)
created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateTimeField(auto_now=True)
def get_code_default(self) -> str:
return f"{self.project.customer.id}-{self.project.id}-{self.id}"
def save(self, *args, **kwargs):
if not self.code:
self.code = self.get_code_default():
return super().save(*args, **kwargs)
New Paste
Go to most recent paste.