Coverage for /home/tribaal/workspace/django-shop/shop/addressmodel/models: 91.18%

# Coverage for /home/tribaal/workspace/django-shop/shop/addressmodel/models : 91.18%

## 34 statements 31 run 3 missing 0 excluded 0 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | # -*- coding: utf-8 -*- """ Holds all the information relevant to the client (addresses for instance) """ from django.contrib.auth.models import User from django.db import models from django.utils.translation import ugettext_lazy as _ from django.conf import settings BASE_ADDRESS_TEMPLATE = \ _(""" Name: %(name)s, Address: %(address)s, Zip-Code: %(zipcode)s, City: %(city)s, State: %(state)s, Country: %(country)s """) ADDRESS_TEMPLATE = getattr(settings, 'SHOP_ADDRESS_TEMPLATE', BASE_ADDRESS_TEMPLATE) class Country(models.Model): name = models.CharField(max_length=255) def __unicode__(self): return u'%s' % self.name class Meta(object): verbose_name = _('Country') verbose_name_plural = _('Countries') class Address(models.Model): user_shipping = models.OneToOneField(User, related_name='shipping_address', blank=True, null=True) user_billing = models.OneToOneField(User, related_name='billing_address', blank=True, null=True) name = models.CharField(_('Name'), max_length=255) address = models.CharField(_('Address'), max_length=255) address2 = models.CharField(_('Address2'), max_length=255, blank=True) zip_code = models.CharField(_('Zip Code'), max_length=20) city = models.CharField(_('City'), max_length=20) state = models.CharField(_('State'), max_length=255) country = models.ForeignKey(Country, verbose_name=_('Country'), blank=True, null=True) class Meta(object): verbose_name = _('Address') verbose_name_plural = _("Addresses") def __unicode__(self): return '%s (%s, %s)' % (self.name, self.zip_code, self.city) def clone(self): new_kwargs = dict([(fld.name, getattr(self, fld.name)) for fld in self._meta.fields if fld.name != 'id']) return self.__class__.objects.create(**new_kwargs) def as_text(self): return ADDRESS_TEMPLATE % { 'name': self.name, 'address': '%s\n%s' % (self.address, self.address2), 'zipcode': self.zip_code, 'city': self.city, 'state': self.state, 'country': self.country, }