Opened 5 years ago

Closed 4 years ago

#24305 closed New feature (fixed)

Allow overriding abstract model fields

Reported by: Marten Kenbeek Owned by: Aron Podrigal
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Marten Kenbeek, Aron Podrigal, ramezashraf@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Discussion on django-developers: https://groups.google.com/forum/#!topic/django-developers/6zUfnElOIks

I suggest we allow fields that are only defined on an abstract base class of a model, to be overridden by models directly inheriting the abstract class. As fields on an abstract class are python-only, and don't live in the database yet, they can easily be switched for another field. If you use abstract models from sources outside your control, or if you reuse an abstract model multiple times, this allows for some flexibility without the need to copy the complete abstract class.

Change History (18)

comment:2 Changed 5 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:3 Changed 5 years ago by Marten Kenbeek

Has patch: set

PR: https://github.com/django/django/pull/4184

Feedback welcome, especially on the documentation.

Last edited 4 years ago by Marten Kenbeek (previous) (diff)

comment:4 Changed 4 years ago by Tim Graham

Patch needs improvement: set

Chatted with Loic briefly and he indicated he didn't think the locking approach is an appropriate implementation. The approach also needs to integrate with the upcoming work on virtual fields, so it may take some time to sort that out.

comment:5 Changed 4 years ago by Aron Podrigal

Owner: changed from Marten Kenbeek to Aron Podrigal
Status: newassigned

comment:6 Changed 4 years ago by Tim Graham

Patch needs improvement: unset

There is a commit here with an alternate approach: https://github.com/knbk/django/commit/7ac5b58587ea2a153766d1601965734731609cdf (having difficulty finding what branch it's part of so I could create a pull request).

comment:8 Changed 4 years ago by Tim Graham

Patch needs improvement: set

Tests are not passing.

comment:9 Changed 4 years ago by Aron Podrigal

Patch needs improvement: unset

comment:10 Changed 4 years ago by Aron Podrigal

Cc: Aron Podrigal added

comment:11 Changed 4 years ago by Tim Graham

Patch needs improvement: set

The patch is missing some tests cases as noted in Loic's review.

comment:12 Changed 4 years ago by Aron Podrigal

Patch needs improvement: unset

comment:13 Changed 4 years ago by Aron Podrigal

Triage Stage: AcceptedReady for checkin

comment:14 Changed 4 years ago by Ramez Issac

Cc: ramezashraf@… added
Triage Stage: Ready for checkinAccepted

I believe that the correct ticket flow is a person other then who supplied the patch can mark Ready For Checkin.
Kindly review
https://docs.djangoproject.com/en/1.8/internals/contributing/new-contributors/#new-contributors-faq
and
https://docs.djangoproject.com/en/1.8/internals/contributing/triaging-tickets/

Thanks

comment:15 Changed 4 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

I reviewed the patch and asked Aron to mark the patch as such after updating for my comments. :-)

comment:16 Changed 4 years ago by Ramez Issac

I apologize for any inconvenience then :-)

comment:17 Changed 4 years ago by Tim Graham

Summary: Allow to override abstract model fieldsAllow overriding abstract model fields

comment:18 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 85ef98dc:

Fixed #24305 -- Allowed overriding fields on abstract models.

Fields inherited from abstract base classes may be overridden like
any other Python attribute. Inheriting from multiple models/classes
with the same attribute name will follow the MRO.

Note: See TracTickets for help on using tickets.
Back to Top