Pastebin
Paste #25067: No description
< previous paste - next paste>
Pasted by Anonymous Coward
class Project(models.Model):
"""Project entity representing a paid project for a customer."""
name = models.CharField(max_length=200, db_index=True)
customer = models.ForeignKey(Customer, on_delete=models.PROTECT)
active = models.BooleanField(default=True)
code = models.CharField(max_length=200, db_index=True, blank=True, null=False)
created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateTimeField(auto_now=True)
def get_code_default(self) -> str:
return f"{self.customer.id}-{self.id}"
# Override save function to populate self.code
def save(self, *args, **kwargs):
if not self.code:
self.code = self.get_code_default()
return super().save(*args, **kwargs)
def __str__(self):
return f"{self.customer.name} - {self.name} ({self.code})"
class ProjectCode(models.Model):
code = models.CharField(max_length=200, unique=True, db_index=True, blank=True, null=False)
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}"
# Override save function to populate self.code
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.