SHARE
TWEET

Untitled

a guest Jun 19th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.db import models
  2. from django.conf import settings
  3. from django.core.urlresolvers import reverse
  4. from django.utils.translation import ugettext_lazy as _
  5.  
  6. from smart_selects.db_fields import ChainedForeignKey
  7.  
  8.  
  9. class PropertyType(models.Model):
  10.     """Class that implements properties types, as House or Apartment."""
  11.  
  12.     name = models.CharField(_('Type of Property'), max_length=140)
  13.  
  14.     class Meta:
  15.         verbose_name = _("Type of Property")
  16.         verbose_name_plural = _('Type of Properties')
  17.  
  18.     def __str__(self):
  19.         return self.name
  20.  
  21.  
  22. class Category(models.Model):
  23.     """Model for category of properties."""
  24.  
  25.     title = models.CharField(_('Category'), max_length=140)
  26.     property_type = models.ForeignKey(PropertyType)
  27.  
  28.     class Meta:
  29.         verbose_name = _("Category")
  30.         verbose_name_plural = _('Categories')
  31.  
  32.     def __str__(self):
  33.         return self.title
  34.  
  35.  
  36. class Property(models.Model):
  37.     """Model for all properties."""
  38.  
  39.     owner = models.ForeignKey(settings.AUTH_USER_MODEL)
  40.     address = models.CharField(_('Address'), max_length=140)
  41.     state = models.CharField(_('State'), max_length=80)
  42.     property_type = models.ForeignKey(PropertyType)
  43.     category = ChainedForeignKey(
  44.         Category,
  45.         chained_field='property_type',
  46.         chained_model_field='property_type'
  47.     )
  48.     rooms = models.PositiveSmallIntegerField(_('Rooms'))
  49.     title = models.CharField(_('Title'), max_length=140)
  50.     image = models.ImageField(_('Image'), upload_to='img/property/')
  51.     rent_price = models.DecimalField(
  52.         _('Property Value'),
  53.         max_digits=19,
  54.         decimal_places=10
  55.     )
  56.     timestamp = models.DateTimeField(auto_now=True)
  57.  
  58.     class Meta:
  59.         verbose_name = _("Property")
  60.         verbose_name_plural = _('Properties')
  61.  
  62.     def __str__(self):
  63.         return self.title
  64.  
  65.     def get_absolute_url(self):
  66.         """Return the absolute url for the model instance."""
  67.         return reverse('properties:show_property', args=[self.id])
RAW Paste Data
Top