class Location(models.Model): site_description = models.TextField(blank=True, null=True, default='') reservation = models.ForeignKey(Reservation, on_delete=models.SET_NULL, blank=True, null=True) watershed = models.ForeignKey(Watershed, on_delete=models.SET_NULL, blank=True, null=True) directions = models.TextField(blank=True, null=True, default='') polygon = PolygonField(null=True) class Meta: abstract = True
class Location(models.Model): site_description = models.TextField(blank=True, null=True, default='') reservation = JSONField(blank=True, null=True) watershed = JSONField(blank=True, null=True) directions = models.TextField(blank=True, null=True, default='') polygon = PolygonField(null=True) class Meta: abstract = True def __str__(self): reservation = ", ".join(self.reservation) if self.reservation else None watershed = ", ".join(self.watershed) if self.watershed else None return "Reservation: {} - Watershed: {}".format(reservation, watershed)
class Migration(migrations.Migration): initial = True dependencies = [("people", "0001_creer_modeles")] operations = [ migrations.CreateModel( name="Segment", fields=[ ( "id", models.AutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ("name", models.CharField(max_length=255, verbose_name="Nom")), ( "support_group_status", models.CharField( blank=True, choices=[ ("m", "Membres de GA"), ("M", "Animateurices et gestionnaires de GA"), ("R", "Animateurices de GA"), ], max_length=1, verbose_name="Statut GA", ), ), ( "area", PolygonField(blank=True, null=True, srid=4326, verbose_name="Territoire"), ), ("tags", models.ManyToManyField(blank=True, to="people.PersonTag")), ], bases=(nuntius.models.BaseSegment, models.Model), ) ]
class AreaModel(TimeStampedModel): polygon = PolygonField() objects = GeoManager() class Meta(TimeStampedModel.Meta): abstract = True def get_center(self): return self.polygon.centroid def center(): #@NoSelf doc = """The center latitude and longitude of the area. This is only accurate for very small geographic areas.""" #@UnusedVariable def fget(self): return self.get_center() return locals() center = property(**center())
class Location(models.Model): event = models.OneToOneField( Event, on_delete=models.CASCADE, ) # NOTE: Coorindates are stored as (lng, lat) # This is done to match DeckGL's convention point = PointField(blank=True, null=True) polygon = PolygonField(blank=True, null=True) @property def lng_lat(self): return [self.point.coords[0], self.point.coords[1] ] if self.point else None class Meta: constraints = [ models.CheckConstraint( name="value_either_point_or_polygon", check=(models.Q(point__isnull=False, polygon__isnull=True) | models.Q(point__isnull=True, polygon__isnull=False))) ]