Created
May 29, 2014 10:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__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