Esempio n. 1
0
class ItemWithArea(models.Model):
    title = models.CharField('title', max_length=100)

    location = AddressField()

    area = ChainedAreaField(AddrObj,
                            address_field='location',
                            related_name='+')
Esempio n. 2
0
class FIASAddress(models.Model):
    class Meta:
        abstract = True

    address = AddressField(AddrObj, verbose_name=_('address'))

    full_address = models.CharField(_('full address'),
                                    max_length=255,
                                    blank=True,
                                    editable=False)
    short_address = models.CharField(_('short address'),
                                     max_length=255,
                                     blank=True,
                                     editable=False)

    def _update_address(self):
        full_addr = [force_unicode(self.address)]
        short_addr = []

        def make_addr(obj):
            if obj.aolevel > 3:
                short_addr.append(force_unicode(obj))

            #level = int(obj.aolevel)
            #attr = self._LEVELS[level]
            #if hasattr(self, attr):
            #    setattr(self, attr, obj)

            if obj.aolevel > 1:
                try:
                    parent = AddrObj.objects.get(aoguid=obj.parentguid)
                except AddrObj.DoesNotExist:
                    return
                else:
                    full_addr.append(force_unicode(parent))
                    make_addr(parent)

        make_addr(self.address)

        self.full_address = ', '.join(full_addr[::-1])
        self.short_address = ', '.join(short_addr[::-1])

    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):

        if self.pk:
            old_obj = self._meta.concrete_model.objects.get(pk=self.pk)

            if self.address != old_obj.address:
                self._update_address()
        else:
            self._update_address()

        super(FIASAddress, self).save(force_insert, force_update, using,
                                      update_fields)
Esempio n. 3
0
class FIASAddress(models.Model):
    class Meta:
        abstract = True

    address = AddressField(verbose_name=_('address'), related_name='+')

    full_address = models.CharField(_('full address'),
                                    max_length=255,
                                    blank=True,
                                    editable=False)
    short_address = models.CharField(_('street address'),
                                     max_length=255,
                                     blank=True,
                                     editable=False)

    def _update_address(self):
        full_addr = [force_text(self.address)]
        short_addr = []

        def make_addr(obj):
            if obj.aolevel > 3:
                short_addr.append(obj)

            if obj.aolevel > 1:
                try:
                    parent = AddrObj.objects.get(aoguid=obj.parentguid)
                except AddrObj.DoesNotExist:
                    return
                else:
                    full_addr.append(force_text(parent))
                    make_addr(parent)

        make_addr(self.address)

        self.full_address = ', '.join(full_addr[::-1])
        self.short_address = ', '.join(
            force_text(obj) for obj in short_addr[::-1] if obj.aolevel > 4)

    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):

        if self.pk:
            old_obj = self._meta.concrete_model.objects.get(pk=self.pk)

            if self.address_id is None:
                self.full_address = self.short_address = ''
            elif self.address_id != old_obj.address_id:
                self._update_address()
        else:
            self._update_address()

        super(FIASAddress, self).save(force_insert, force_update, using,
                                      update_fields)
Esempio n. 4
0
class Item(models.Model):

    title = models.CharField('title', max_length=100)

    location = AddressField()
Esempio n. 5
0
class Item(models.Model):
    title = models.CharField('title', max_length=100)
    location_id = AddressField(db_column='location_id')
Esempio n. 6
0
class NullableAddressItem(models.Model):
    title = models.CharField('title', max_length=100)

    location = AddressField(blank=True, null=True)