-
Notifications
You must be signed in to change notification settings - Fork 4
[11229] Add relationship methods on Provider #571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11229] Add relationship methods on Provider #571
Conversation
3119145 to
bb18d9e
Compare
| def __str__(self): | ||
| return self.name | ||
|
|
||
| @property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go with this approach we might also want to consider customising related_name for some of our foreign keys, so that the naming is more consistent when accessing related objects https://docs.djangoproject.com/en/5.2/ref/models/fields/#django.db.models.ForeignKey.related_name
Otherwise we will have a mix of the pluralised form and "foo_set"
bb18d9e to
3c171ff
Compare
This methods define the relationship traversals for a provider's appointments and clinics. They allow view code to retrieve these records correctly scoped to provider.
We can use strings instead of actual models when defining our foreign keys to make sure we don't trigger circular dependency issues on model import.
We want to write a linter to discourage the use of direct record retrieval from Appointment, Clinic, and Participants models. The linter will look for 'ModelName.objects'. With this in mind, it would be useful to discourage use of get_object_or_404, which simply accepts the bare ModelName as an argument. We'll also likely replace get_object_or_404 at some point with some custom behaviour. Replace use of this method with a slightly more verbose alternative.
Allows simpler querying of associated appointments in the participant show view.
Allows for: - Retrieval of appointments scoped to a clinic record - Refactoring of `Appointment.objects.for_clinic_and_filter` to `for_filter`.
This linter checks for two things: - If Model.objects is being used in views, where Model is one of Appointment, Clinic or Participant. - Use of get_object_or_404 We check for the latter because: - We're going to replace it eventually anyway, probably with some kind of flash message usage - It accepts a model as an arg, with no call to objects. Not using it makes it easier to lint for unscoped queries.
3c171ff to
cee05b0
Compare
Description
With the goal of ensuring we have a set of conventions for scoping certain queries by provider, this is an alternative to the approach taken in #558 .
Here we:
appointments,clinicsandparticipantsmethods onProvider, each defining how to traverse the relationship.request.current_provider.appointments(for example) in views instead of direct access to the Appointment model.There are also these related changes:
appointmentsmethods to Clinic and Participants models as well.Jira link
https://nhsd-jira.digital.nhs.uk/browse/DTOSS-11229
Review notes
has_many,has_many: :through, etc). Does it make sense to do something like this in Django?