Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Earth(models.Model):
- owner = models.ForeignKey(Owner, on_delete=models.CASCADE)
- year = models.IntegerField(')
- cadastral_number = models.CharField(max_length=100)
- area = models.FloatField()
- total = models.FloatField()
- price = models.FloatField()
- notes = models.CharField(max_length=100)
- image = models.ImageField(upload_to='earth_img/')
- active = models.BooleanField(default=True)
- created = models.DateTimeField(auto_now_add=True)
- updated = models.DateTimeField(auto_now=True)
- PROPERTY_CHOISES = (
- 'a': 'A1',
- 'b': 'B1',
- )
- CITY_CHOISES = (
- 'k': 'Kiev',
- 'p': 'Poltava'
- )
- PRIVILEGE_CHOISES = (
- 'a': 'A',
- 'b': 'B',
- )
- privilege = models.CharField(max_length=19, choices=PRIVILEGE_CHOISES)
- city = models.CharField(max_length=10, choices=CITY_CHOISES)
- property = models.CharField(max_length=21, choices=PROPERTY_CHOISES)
- def __str__(self):
- return self.owner.name
- def get_absolute_url(self):
- return reverse('earth_detail_url', args=[self.id])
- def get_image_url(self):
- if not self.image:
- return '/static/img/no-image.jpg'
- else:
- return f'/media/{self.image}'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement