class Car(BaseDateAuditModel): STATUS_PENDING = 'pending' STATUS_PUBLISHED = 'published' STATUS_SOLD = 'sold' STATUS_ARCHIVED = 'archived' STATUS_CHOICES = ( (STATUS_PENDING, "Pending"), (STATUS_PUBLISHED, "Published"), (STATUS_SOLD, "Sold"), (STATUS_ARCHIVED, "Archived"), ) objects = CarManager.from_queryset(CarQuerySet)() views = models.PositiveIntegerField(default=0, editable=False) slug = models.SlugField(max_length=75) number = models.CharField(max_length=16, unique=True) status = models.CharField(max_length=15, choices=STATUS_CHOICES, default=STATUS_PENDING, blank=True) dealer = models.ForeignKey('dealers.Dealer', on_delete=models.CASCADE, related_name='cars', null=True, blank=False) color = models.ForeignKey(to='Color', on_delete=models.SET_NULL, null=True, blank=False) model = models.ForeignKey(to='CarModel', on_delete=models.SET_NULL, null=True, blank=False) extra_title = models.CharField(max_length=255, null=True, blank=True, verbose_name=_('Title second part')) engine_type = models.ForeignKey(to='CarEngine', on_delete=models.SET_NULL, null=True, blank=False) fuel_type = models.ForeignKey(to='FuelType', on_delete=models.SET_NULL, null=True, blank=False) engine_power = models.DecimalField(max_digits=6, decimal_places=2, null=True, blank=False) price = models.DecimalField(max_digits=6, decimal_places=2, null=True, blank=False) doors = models.PositiveSmallIntegerField(default=4) sitting_places = models.PositiveSmallIntegerField(default=4) first_registration_date = models.DateField(auto_now_add=False, null=True, blank=False) # dealer = models.ForeignKey('Dealer', on_delete=models.CASCADE, related_name='cars') model = models.ForeignKey(to='CarModel', on_delete=models.SET_NULL, null=True, blank=False) extra_title = models.CharField(max_length=255, null=True, blank=True, verbose_name=_('Title second part')) def save(self, *args, **kwargs): order_number_start = 7600000 if not self.pk: super().save(*args, **kwargs) self.number = f"LK{order_number_start + self.pk}" self.save() else: super().save(*args, **kwargs) def delete(self, using=None, keep_parents=False): self.status = self.STATUS_ARCHIVED self.save() @property def title(self): return f'{self.model.brand} {self.extra_title or ""}' # do not show None def __str__(self): return self.title class Meta: verbose_name = _('Car') verbose_name_plural = _('Cars') indexes = [ Index(fields=['status', ]) ]
class Car(BaseDateAuditModel): STATUS_PENDING = "pending" STATUS_PUBLISHED = "published" STATUS_SOLD = "sold" STATUS_ARCHIVED = "archived" STATUS_CHOICES = ( (STATUS_PENDING, "Pending"), (STATUS_PUBLISHED, "Published"), (STATUS_SOLD, "Sold"), (STATUS_ARCHIVED, "Archived"), ) car_id = models.AutoField(primary_key=True) color_id = models.ForeignKey(to='Color', on_delete=models.SET_NULL, null=True, blank=False, related_name='colour') dealer = models.ForeignKey(to='dealers.Dealer', on_delete=models.SET_NULL, null=True, blank=False, related_name='dealer') model_id = models.ForeignKey(to='CarModel', on_delete=models.SET_NULL, null=True, blank=False, related_name='model') engine_type = models.CharField(max_length=20) population_type = models.CharField(max_length=20) price = models.FloatField(blank=True, null=False) fuel_type = models.CharField(max_length=20) status = models.CharField(max_length=15, choices=STATUS_CHOICES, default=STATUS_PENDING, blank=True) doors = models.ImageField(blank=True, null=False) capacity = models.FloatField(blank=True, null=False) gear_case = models.CharField(max_length=20, blank=True, null=False) number = models.FloatField(blank=True, null=False) slug = models.SlugField(max_length=75) sitting_place = models.ImageField(blank=True, null=False) first_registration_date = models.DateTimeField(auto_now=True) engine_power = models.FloatField(blank=True, null=False) ONE_DOOR = 1 TWO_DOORS = 2 THREE_DOORS = 3 FOUR_DOORS = 4 FIVE_DOORS = 5 SIX_DOORS = 6 DOORS_CHOICES = ( (ONE_DOOR, 1), (TWO_DOORS, 2), (THREE_DOORS, 3), (FOUR_DOORS, 4), (FIVE_DOORS, 5), (SIX_DOORS, 6), ) CHOICE_MANUAL_TRANSMISSION = "manual transmission" CHOICE_AUTOMATIC_MANUAL_TRANSMISSION = "automatic-manual transmission" CHOICE_AUTOMATIC_TRANSMISSION = "automatic transmission" GEAR_CASE_CHOICES = ( (CHOICE_MANUAL_TRANSMISSION, "manual transmission"), (CHOICE_AUTOMATIC_MANUAL_TRANSMISSION, "automatic-manual transmission"), (CHOICE_AUTOMATIC_TRANSMISSION, "automatic transmission"), ) color = models.ForeignKey("Color", on_delete=models.SET_NULL, blank=False, null=True, related_name='colour') dealer = models.ForeignKey("dealers.Dealer", on_delete=models.SET_NULL, null=True, related_name="dealer") model = models.ForeignKey("CarModel", on_delete=models.SET_NULL, blank=False, null=True, related_name='model') engine_type = models.CharField(max_length=25, blank=True, null=False) population_type = models.CharField(max_length=55, blank=False, null=True) price = models.FloatField(max_length=20, blank=True, null=False) fuel_type = models.CharField(max_length=40, blank=False, null=True) status = models.CharField(max_length=15, choices=STATUS_CHOICES, default=STATUS_PENDING, blank=True) doors = models.IntegerField(choices=DOORS_CHOICES, default=FOUR_DOORS, blank=True, null=True) capacity = models.IntegerField(blank=True, null=True) gear_case = models.CharField(max_length=30, choices=GEAR_CASE_CHOICES, blank=False, null=True) number = models.CharField(max_length=20, unique=True) slug = models.SlugField(max_length=75) sitting_place = models.IntegerField(null=True) first_registration_date = models.DateField( auto_now_add=False, default=date.today, verbose_name="First registration date", null=False) engine_power = models.FloatField(null=True) objects = CarManager.from_queryset(CarQuerySet)() views = models.PositiveIntegerField(default=0, editable=False) extra_title = models.CharField(max_length=255, null=True, blank=True, verbose_name=_("Title second part")) def save(self, *args, **kwargs): order_number_start = 7600000 if not self.pk: super().save(*args, **kwargs) self.number = f"LK{order_number_start + self.pk}" self.save() else: super().save(*args, **kwargs) def delete(self, using=None, keep_parents=False): self.status = self.STATUS_ARCHIVED self.save() @property def title(self): return f'{self.model.brand} {self.extra_title or ""}' # do not show None def __str__(self): return self.title class Meta: verbose_name = _("Car") verbose_name_plural = _("Cars") indexes = [Index(fields=[ 'status', ])]
class Car(BaseDateAuditModel): STATUS_PENDING = "pending" STATUS_PUBLISHED = "published" STATUS_SOLD = "sold" STATUS_ARCHIVED = "archived" STATUS_CHOICES = ( (STATUS_PENDING, "Pending"), (STATUS_PUBLISHED, "Published"), (STATUS_SOLD, "Sold"), (STATUS_ARCHIVED, "Archived"), ) AUTOMATIC_TRANSMISSION = "automatic transmission" SEMI_AUTOMATIC_TRANSMISSION = "semi-automatic transmission" MANUAL_TRANSMISSION = "manual transmission" GEAR_BOX_CHOICES = ( (AUTOMATIC_TRANSMISSION, "automatic transmission"), (SEMI_AUTOMATIC_TRANSMISSION, "semi-automatic transmission"), (MANUAL_TRANSMISSION, "manual transmission"), ) WHEEL_DRIVE_CHOICE_YES = "Yes" WHEEL_DRIVE_CHOICE_NO = "No" ALL_WHEEL_DRIVE_CHOICES = ( (WHEEL_DRIVE_CHOICE_YES, "Yes"), (WHEEL_DRIVE_CHOICE_NO, "No"), ) objects = CarManager.from_queryset(CarQuerySet)() views = models.PositiveIntegerField(default=0, editable=False) slug = models.SlugField(max_length=75) number = models.CharField(max_length=16, unique=True) status = models.CharField(max_length=15, choices=STATUS_CHOICES, default=STATUS_PENDING, blank=True) dealer = models.ForeignKey("dealers.Dealer", on_delete=models.CASCADE, related_name="cars") model = models.ForeignKey("CarModel", on_delete=models.SET_NULL, null=True, blank=False) color = models.ForeignKey("Color", on_delete=models.SET_NULL, null=True, blank=False) extra_title = models.CharField(max_length=255, null=True, blank=True, verbose_name=_("Title second part")) first_registration_date = models.DateField( auto_now_add=False, default=date.today, verbose_name="First registration date") engine_type = models.CharField(max_length=25, blank=True) engine_power = models.IntegerField(null=True) fuel_type = models.CharField(max_length=25, null=True, blank=False) fuel_capacity = models.IntegerField(null=True) gear_box = models.CharField(max_length=27, choices=GEAR_BOX_CHOICES, null=True, blank=False) all_wheel_drive = models.CharField(max_length=3, choices=ALL_WHEEL_DRIVE_CHOICES, null=True, blank=False) doors = models.IntegerField(null=True) sitting_place = models.IntegerField(null=True) trunk_capacity = models.IntegerField(null=True) population_type = models.CharField(max_length=55, null=True, blank=False) price = MoneyField(max_digits=9, decimal_places=2, default_currency="USD", null=True) class Meta: verbose_name = _("Car") verbose_name_plural = _("Cars") indexes = [Index(fields=[ "status", ])] def save(self, *args, **kwargs): order_number_start = 7600000 if not self.pk: super().save(*args, **kwargs) self.number = f"LK{order_number_start + self.pk}" self.save() else: super().save(*args, **kwargs) def delete(self, using=None, keep_parents=False): self.status = self.STATUS_ARCHIVED self.save() @property def title(self): return f'{self.model.brand} {self.extra_title or ""}' # do not show None def __str__(self): return self.title
class Car(BaseDateAuditModel): STATUS_PENDING = 'pending' STATUS_PUBLISHED = 'published' STATUS_SOLD = 'sold' STATUS_ARCHIVED = 'archived' STATUS_CHOICES = ( (STATUS_PENDING, "Pending"), (STATUS_PUBLISHED, "Published"), (STATUS_SOLD, "Sold"), (STATUS_ARCHIVED, "Archived"), ) objects = CarManager.from_queryset(CarQuerySet)() views = models.PositiveIntegerField(default=0, editable=False) slug = models.SlugField(max_length=75) number = models.CharField(max_length=16, unique=True) status = models.CharField(max_length=15, choices=STATUS_CHOICES, default=STATUS_PENDING, blank=True) dealer = models.ForeignKey(Dealer, on_delete=models.CASCADE, null=True, blank=False) model = models.ForeignKey(to='CarModel', on_delete=models.SET_NULL, null=True, blank=False) extra_title = models.CharField(max_length=255, null=True, blank=True, verbose_name=_('Title second part')) # other fields ... # def save(self, *args, **kwargs): order_number_start = 7600000 if not self.pk: super().save(*args, **kwargs) self.number = f"LK{order_number_start + self.pk}" self.save() else: super().save(*args, **kwargs) def delete(self, using=None, keep_parents=False): self.status = self.STATUS_ARCHIVED self.save() @property def title(self): return f'{self.model.brand} {self.extra_title or ""}' # do not show None def __str__(self): return self.title class Meta: verbose_name = _('Car') verbose_name_plural = _('Cars') indexes = [Index(fields=[ 'status', ])]