#30758: DateTimeRangeField crashes in django admin (object has no attribute
'strip').
------------------------------------+--------------------------------------
Reporter: yeppus | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: DateTimeRangeField | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Changes (by yeppus):
* status: closed => new
* resolution: needsinfo =>
Comment:
It seems to be connected to default function. After some digging and
testing I managed to make a minimal testcase.
**admin.py**
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
from django.contrib import admin
from . import models
@admin.register(models.DateRangeWithDefaultFunction)
class PriceAdmin(admin.ModelAdmin):
fields = (
'valid_period',
)
list_display = (
'__str__',
)
@admin.register(models.DateRangeWithoutDefaultFunction)
class PriceAdmin(admin.ModelAdmin):
fields = (
'valid_period',
)
list_display = (
'__str__',
)
}}}
}}}
**models.py**
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
from django.db import models
from django.utils import timezone
from django.contrib.postgres import fields as pg_fields
from psycopg2._range import DateTimeTZRange
def default_period():
return DateTimeTZRange(
lower=timezone.now(),
upper=None,
)
#Can add new but not change objects in admin
class DateRangeWithDefaultFunction(models.Model):
valid_period = pg_fields.DateTimeRangeField(
'valid during',
blank=True,
default=default_period,
)
#Working as expected
class DateRangeWithoutDefaultFunction(models.Model):
valid_period = pg_fields.DateTimeRangeField(
'valid during',
blank=True,
)
}}}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30758#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.dbc8944a6c4484af513a909288ba98c5%40djangoproject.com.