class Project(models.Model): id = models.UUIDField(auto_add=True, primary_key=True) name = models.TextField(db_index=True, unique=True) created_at = models.DateTimeField(auto_now_add=True) modified_at = models.DateTimeField(auto_now=True) def __str__(self): return self.name def get_absolute_url(self): return reverse('project-detail', kwargs={'name': self.name}) @cached_property def last_check(self): try: return self.checks.exclude(finished_at=None).latest('finished_at') except (Check.DoesNotExist, IndexError): return None def check(self, delay=True): from .tasks import run_check check = Check(project=self, public=False, requirements=[self.name], projects=[self.name]) check.full_clean() check.save() if delay: run_check.delay(check.pk) else: run_check(check.pk)
class Author(models.Model): name = models.CharField(max_length=75) uuid = models.UUIDField(null=True) books = models.ArrayField(of=BookField) data = models.JSONField(default=None) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True)
class Check(models.Model): id = models.UUIDField(auto_add=True, primary_key=True) unblocked = models.SmallIntegerField(default=0) created_at = models.DateTimeField(default=now) started_at = models.DateTimeField(null=True, blank=True) finished_at = models.DateTimeField(null=True, blank=True) requirements = models.ArrayField(models.TextField()) projects = models.ArrayField(models.CharField(max_length=255)) blockers = models.JSONField() public = models.BooleanField(default=True) runs = models.SmallIntegerField(default=0) project = models.ForeignKey(Project, related_name='checks', null=True, blank=True) class Meta: ordering = ('-finished_at',) def __str__(self): return str(self.id) def get_absolute_url(self): return reverse('check-detail', kwargs={'pk': str(self.pk)}) def clean(self): projects = OrderedDict() # using this since sets aren't ordered for requirement in self.requirements: url = urlparse(requirement) if url.scheme in ('http', 'https', 'file'): requirement = [sanitize_github_url(requirement, url)] try: for project in projects_from_requirements(requirement): projects[project] = None except: raise ValidationError("Couldn't check %s." % requirement) else: projects[requirement] = None self.projects = list(projects.keys()) for index, project_name in enumerate(self.projects): validators.RegexValidator(project_name_re, 'Project %s invalid' % project_name)(project_name)
class Movie(models.Model): id = models.UUIDField(auto_add=True, primary_key=True) title = models.CharField(max_length=50)
class Book(models.Model): title = models.CharField(max_length=50) uuid = models.UUIDField(null=True)
class Game(models.Model): title = models.CharField(max_length=50) uuid = models.UUIDField()
class Elf(models.Model): id = models.UUIDField(auto_add=True, primary_key=True) name = models.CharField(max_length=50) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True)
def test_uuid_field_auto_add_string(self): """Establish that creating a UUID field with the `auto_add` set to an appropriately-formatted string works as expected. """ field = models.UUIDField(auto_add='uuid:uuid1') self.assertEqual(field._auto_add, uuid.uuid1)
class Thing(models.Model): uuid = models.UUIDField(blank=True)