Changing 'DateField' to 'DateTimeField' for 'date' attribute in AbstractProductAttributeValue class

708 views
Skip to first unread message

Alexandre Lara

unread,
May 10, 2015, 7:15:56 PM5/10/15
to django...@googlegroups.com

I'm trying to change the attribute date of my Product Attributes because it is a DateField and I need a DateTimeField (I want to implement a countdown on my website). I found out that the app responsible for it is oscar.apps.catalogue and the attribute that I want to modify (date) is located inside abstract_models.py in the catalogue app folder (AbstractProductAttributeValue class).

I forked the project and created a ProductAttributeValue class inheriting from AbstractProductAttributeValue but Python doesn't allow to modify a parent class attribute so I can't just modify that attribute.

Is there a way to modify that attribute or will I have to modify the original Django-Oscar file (abstract_models.py)?

EDIT: I'm trying to modify the Django-oscar behaviour by inheriting a class. Using AbstractProductAttributeValue._meta.get_field('value_date').default = models.DateTimeField(_('Date and Time'), blank=True, null=True) to change the parent class attribute doesn't work and shows me an error when I try to use python manage.py migrate: "AttributeError: 'DateField' object has no attribute 'model'"

John P

unread,
May 11, 2015, 12:36:10 PM5/11/15
to django...@googlegroups.com
I imagine you're going to have a really rough time doing this.

Django abstract models do not allow for field name hiding. https://docs.djangoproject.com/en/1.8/topics/db/models/#field-name-hiding-is-not-permitted

This means that it's really difficult to over-ride an existing field.

Let me know if you have any questions.

John
Message has been deleted
Message has been deleted

Alexandre Lara

unread,
May 12, 2015, 3:00:11 AM5/12/15
to django...@googlegroups.com
So I believe that I have 2 options:
  1. Changing the original oscar file;
  2. Forking the project and creating a new field to represent the datetime field that I need;

John P

unread,
May 12, 2015, 3:44:17 PM5/12/15
to django...@googlegroups.com
What is the DateTimeField supposed to represent? When the product is released?

It'd probably be easier just to add a new field onto product.

Something like this:

class Product(AbstractProduct):
    countdown_end = models.DateTimeField()


John

On Sunday, May 10, 2015 at 6:15:56 PM UTC-5, Alexandre Lara wrote:
Reply all
Reply to author
Forward
0 new messages