Skip to content

Instantly share code, notes, and snippets.

@srkama
Created May 29, 2014 10:52
Show Gist options
  • Save srkama/d81bef2a296c43305472 to your computer and use it in GitHub Desktop.
Save srkama/d81bef2a296c43305472 to your computer and use it in GitHub Desktop.
A simple Gist to for Address mixin, When we Address fields in your model include this mixin
__author__ = 'Kamal.S'
__version__ = '0.0.1'
from django.db import models
class AddressMixin(models.Model):
"""
AddressMixin
"""
contact_number_1 = models.CharField(max_length=20)
contact_number_2 = models.CharField(max_length=20, null=True)
address_1 = models.CharField(max_length=100, null=True)
address_2 = models.CharField(max_length=100, null=True)
city = models.CharField(max_length=100)
pincode = models.IntegerField(max_length=10)
class Meta:
abstract = True
@property
def get_address(self):
"""
Returns the Association Address
"""
address_list = [self.address_1, self.address_2, self.city, 'pin:' + str(self.pincode)]
return ", ".join([address for address in address_list if address])
@property
def get_contacts(self):
contacts = [self.contact_number_1, self.contact_number_2]
return ", ".join([str(contact) for contact in contacts if contact])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment