Esempio n. 1
0
class Hood(models.Model):
    name = models.CharField(max_length=150)
    location = GeoLocationField(blank=True)
    address = AddressField(max_length=100)

    def __str__(self):
        return self.name
Esempio n. 2
0
class Rental(models.Model):
    address = AddressField(max_length=100)

    geolocation = GeoLocationField(blank=True)

    def __str__(self):
        return self.address
Esempio n. 3
0
class Activo(models.Model):
    address = AddressField(max_length=100, verbose_name="Dirección")
    geolocation = GeoLocationField(blank=True, verbose_name="Coordenadas")
    tipoactivo = models.ForeignKey('Tipoactivo',
                                   models.DO_NOTHING,
                                   verbose_name="Tipo de activo")
    createddate = models.DateTimeField(default=timezone.now,
                                       verbose_name="Fecha de creación")

    class Meta:
        managed = True

    def __str__(self):
        return self.address
Esempio n. 4
0
class Location(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    organization = models.ForeignKey('openwisp_users.Organization',
                                     verbose_name=_('organization'),
                                     on_delete=models.CASCADE)
    name = models.CharField(max_length=100, blank=True, null=True)
    type = models.CharField(
        choices=[
            ('outdoor',
             'Outdoor environment (eg: street, square, garden, land)'),
            ('indoor',
             'Indoor environment (eg: building, roofs, subway, large vehicles)'
             )
        ],
        help_text='indoor locations can have floorplans associated to them',
        max_length=8,
        blank=True,
        null=True)
    is_mobile = models.BooleanField(
        help_text='is this location a moving object?',
        verbose_name='is mobile?')
    created = AutoCreatedField(_('created'), editable=False)
    modified = AutoLastModifiedField(_('modified'), editable=False)
    address = AddressField(max_length=100, blank=True, null=True)
    geolocation = GeoLocationField(blank=True, null=True)

    def __str__(self):
        return self.name

    def clean(self):
        self._validate_outdoor_floorplans()

    def _validate_outdoor_floorplans(self):
        """
        if a location type is changed from indoor to outdoor
        but the location has still floorplan associated to it,
        a ValidationError will be raised
        """
        if self.type == 'indoor' or self._state.adding:
            return
        if self.floorplan_set.count() > 0:
            msg = 'this location has floorplans associated to it, ' \
                  'please delete them before changing its type'
            raise ValidationError({'type': msg})

    @property
    def short_type(self):
        return _(self.type.capitalize())
Esempio n. 5
0
class PointOfInterest(models.Model):
    name = models.CharField(max_length=100, verbose_name=u'Nom')
    category = models.ForeignKey(Category, verbose_name=u'Catégorie')
    description = HTMLField(blank=True, verbose_name=u'Description')
    address = AddressField(max_length=100, verbose_name=u'Adresse')
    geolocation = GeoLocationField(verbose_name=u'Géolocalisation')
    image = models.ImageField(upload_to='cartography_pointOfInterest',
                              blank=True,
                              verbose_name=u'Image')
    phone = models.CharField(max_length=10,
                             blank=True,
                             verbose_name=u'Téléphone')
    website = models.URLField(blank=True, verbose_name=u'Site internet')
    opening_hours = models.CharField(max_length=254,
                                     blank=True,
                                     verbose_name=u'Heures d\'ouverture')

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = u'Point d\'intérêt'
        verbose_name_plural = u'Points d\'intérêt'
Esempio n. 6
0
class ProfileHost(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL,
                                on_delete=models.CASCADE)
    name = models.CharField(max_length=200, blank=False, null=False)
    type = models.CharField(choices=ORG_TYPE_CHOICE,
                            max_length=30,
                            null=True,
                            blank=True)
    description = models.TextField(null=True, blank=True)
    phone = PhoneNumberField(null=True, blank=True)
    address = AddressField(max_length=200)
    geolocation = GeoLocationField(blank=True)
    photo = models.ImageField(default='default.jpg', upload_to='profile_host')
    interests = models.ManyToManyField(Topic)
    interest_details = models.TextField(blank=True)
    languages = models.ManyToManyField(Language)

    objects = ProfileHostManager()

    def __str__(self):
        return self.user.username

    def save(self, *args, **kwargs):
        '''resize fotos'''
        super().save(*args, **kwargs)
        try:
            img = Image.open(self.photo.name)
            if img.height > 300 or img.width > 300:
                output_size = (300, 300)
                img.thumbnail(output_size)
                img.save(self.photo.name)
        except FileNotFoundError as e:
            pass

    def get_absolute_url(self):
        return reverse('profile_host', kwargs={'userid': self.user.id})
class SampleModel(models.Model):
    address = AddressField(max_length=100)
    geolocation = GeoLocationField(blank=True)