class Booking(models.Model):
    room = models.ForeignKey(Room, on_delete=models.CASCADE)
    time = DateRangeField(null=False)

    # Perhaps a booking is not always valid?
    # Perhaps the booking should be associated with a peson?

    def __str__(self):
        return f"{self.room} booked from {self.time.lower} to {self.time.upper}"

    def get_absolute_url(self):
        return reverse("booking:booking", kwargs={'pk': self.pk})

    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        try:
            super().save(force_insert, force_update, using, update_fields)
        except IntegrityError as e:
            raise ValidationError(
                "There's already a booking on those days") from e

    class Meta:
        constraints = [
            ExclusionConstraint(
                name='hotel_room_excl_constraint',
                expressions=[
                    ("time", RangeOperators.OVERLAPS),
                    ("room", RangeOperators.EQUAL),
                ],
                index_type="GIST",
            )
        ]
Beispiel #2
0
class Book(models.Model):
    name = models.CharField(max_length=20)
    daterange = DateRangeField()
    book_type_choices = (('Daily', 'Daily'), ('Monthly', 'Monthly'),
                         ('Yearly', 'Yearly'))
    book_type = models.CharField(choices=book_type_choices, max_length=10)

    def __str__(self) -> str:
        return f"{self.daterange}"
Beispiel #3
0
class WorkoutPlan(models.Model):
    """Stores a single workout plan entry."""

    name = models.CharField(max_length=64, verbose_name='Name of the plan')
    description = models.TextField(null=True,
                                   verbose_name='Description',
                                   blank=True)
    date_range = DateRangeField(verbose_name='Time range')
    is_active = models.BooleanField(default=False,
                                    verbose_name='Set as current')
    owner = models.ForeignKey(User, on_delete=models.CASCADE)
Beispiel #4
0
class Person(models.Model):
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    #  Jards Macalé is an amazing brazilian musician! =]
    enjoy_jards_macale = models.BooleanField(default=True)
    like_metal_music = models.BooleanField(default=False)
    name = models.CharField(max_length=30)
    nickname = models.SlugField(max_length=36)
    age = models.IntegerField()
    bio = models.TextField()
    birthday = models.DateField()
    birth_time = models.TimeField()
    appointment = models.DateTimeField()
    blog = models.URLField()
    occupation = models.CharField(max_length=10, choices=OCCUPATION_CHOICES)
    uuid = models.UUIDField(primary_key=False)
    name_hash = models.BinaryField(max_length=16)
    days_since_last_login = models.BigIntegerField()
    duration_of_sleep = models.DurationField()
    email = models.EmailField()
    id_document = models.CharField(unique=True, max_length=10)

    try:
        from django.db.models import JSONField

        data = JSONField()
    except ImportError:
        # Skip JSONField-related fields
        pass

    try:
        from django.contrib.postgres.fields import ArrayField, HStoreField
        from django.contrib.postgres.fields import JSONField as PostgresJSONField
        from django.contrib.postgres.fields.citext import (
            CICharField,
            CIEmailField,
            CITextField,
        )
        from django.contrib.postgres.fields.ranges import (
            BigIntegerRangeField,
            DateRangeField,
            DateTimeRangeField,
            IntegerRangeField,
        )

        if settings.USING_POSTGRES:
            acquaintances = ArrayField(models.IntegerField())
            postgres_data = PostgresJSONField()
            hstore_data = HStoreField()
            ci_char = CICharField(max_length=30)
            ci_email = CIEmailField()
            ci_text = CITextField()
            int_range = IntegerRangeField()
            bigint_range = BigIntegerRangeField()
            date_range = DateRangeField()
            datetime_range = DateTimeRangeField()
    except ImportError:
        # Skip PostgreSQL-related fields
        pass

    try:
        from django.contrib.postgres.fields.ranges import FloatRangeField

        if settings.USING_POSTGRES:
            float_range = FloatRangeField()
    except ImportError:
        # Django version greater or equal than 3.1
        pass

    try:
        from django.contrib.postgres.fields.ranges import DecimalRangeField

        if settings.USING_POSTGRES:
            decimal_range = DecimalRangeField()
    except ImportError:
        # Django version lower than 2.2
        pass

    if BAKER_GIS:
        geom = models.GeometryField()
        point = models.PointField()
        line_string = models.LineStringField()
        polygon = models.PolygonField()
        multi_point = models.MultiPointField()
        multi_line_string = models.MultiLineStringField()
        multi_polygon = models.MultiPolygonField()
        geom_collection = models.GeometryCollectionField()
Beispiel #5
0
class Season(models.Model):
    duration = DateRangeField()

    def __str__(self):
        return '{str} {year}'.format(str=season_str(self.duration.lower),
                                     year=self.duration.lower.year)