from django.contrib.auth.models import User from django.db import models class Candidate(models.Model): name = models.CharField('Candidate name', max_length=50) slug = models.SlugField(max_length=50, unique=True) vendor = models.CharField('Vendor name', max_length=50) device = models.CharField('Device name', max_length=50) release_date = models.DateField() description = models.TextField() source_url = models.URLField() binary_url = models.URLField(blank=True) ordering = models.SmallIntegerField(default=0) class Meta: ordering = ['ordering', 'name'] def __str__(self): return self.name class Comment(models.Model): candidate = models.ForeignKey(Candidate, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.PROTECT) time = models.DateTimeField(auto_now_add=True) message = models.TextField() def __str__(self): return f'{self.candidate.name}, {self.user}, {self.time}' class Meta: ordering = ['id']