Skip to content

Commit

Permalink
Added 'code' property to Listing model + a few pep8 corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
wm3ndez committed Sep 14, 2014
1 parent 5264950 commit 5eba5c3
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions realestate/listing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
(LOCATION_STATE, _('State/Province')),
)

OFFERS = (('buy', _('For Sale')), ('rent', _('For Rent')), ('buy-rent', _('For Sale/For Rent')))
OFFERS = (
('buy', _('For Sale')),
('rent', _('For Rent')),
('buy-rent', _('For Sale/For Rent'))
)

VALIDATIONS = [
('realestate.listing.utils.validation_simple', _('One or more characters')),
Expand All @@ -64,9 +68,12 @@ def streets(self, **kwargs):


class Location(models.Model):
parent = models.ForeignKey('self', verbose_name=_('Location'), null=True, blank=True)
parent = models.ForeignKey('self', verbose_name=_('Location'), null=True,
blank=True)
name = models.CharField(_('Name'), max_length=60)
location_type = models.CharField(_('Location Type'), choices=LOCATION_TYPES, default=LOCATION_SECTOR, max_length=20)
location_type = models.CharField(_('Location Type'),
choices=LOCATION_TYPES,
default=LOCATION_SECTOR, max_length=20)

objects = LocationManager()

Expand Down Expand Up @@ -269,6 +276,16 @@ def should_have_baths(self):
def on_sale(self):
return Deal.objects.on_sale(listing__in=(self,)).exists()

@property
def code(self):
if self.agent is not None:
agent = self.agent
prefix = '{0}{1}'.format(agent.first_name[0], agent.last_name[0])
return '{0}{1:04}'.format(prefix, self.id).upper()

rent_or_sale = 'v' if self.offer in ('buy-rent', 'buy') else 'r'
return '{0}{1:04x}'.format(rent_or_sale, self.id).upper()


class Attribute(models.Model):
name = models.CharField(_('Attribute'), max_length=100)
Expand Down

0 comments on commit 5eba5c3

Please sign in to comment.