Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. class Earth(models.Model):
  2.     owner = models.ForeignKey(Owner, on_delete=models.CASCADE)
  3.     year = models.IntegerField(')
  4.    cadastral_number = models.CharField(max_length=100)
  5.    area = models.FloatField()
  6.    total = models.FloatField()
  7.    price = models.FloatField()
  8.    notes = models.CharField(max_length=100)
  9.    image = models.ImageField(upload_to='earth_img/')
  10.    active = models.BooleanField(default=True)
  11.    created = models.DateTimeField(auto_now_add=True)
  12.    updated = models.DateTimeField(auto_now=True)
  13.  
  14.    PROPERTY_CHOISES = (
  15.         'a': 'A1',
  16.         'b': 'B1',
  17.    )
  18.  
  19.    CITY_CHOISES = (
  20.         'k': 'Kiev',
  21.         'p': 'Poltava'
  22.     )
  23.  
  24.    PRIVILEGE_CHOISES = (
  25.         'a': 'A',
  26.         'b': 'B',
  27.         )
  28.  
  29.    privilege = models.CharField(max_length=19, choices=PRIVILEGE_CHOISES)
  30.    city = models.CharField(max_length=10, choices=CITY_CHOISES)
  31.    property = models.CharField(max_length=21, choices=PROPERTY_CHOISES)
  32.  
  33.    def __str__(self):
  34.        return self.owner.name
  35.  
  36.    def get_absolute_url(self):
  37.        return reverse('earth_detail_url', args=[self.id])
  38.  
  39.    def get_image_url(self):
  40.        if not self.image:
  41.            return '/static/img/no-image.jpg'
  42.        else:
  43.            return f'/media/{self.image}'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement