-
Notifications
You must be signed in to change notification settings - Fork 69
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
Connect Tag model to TimeEntry model #99
Comments
Ufff yeah, this will be quiet a lot of work 😄 That is mainly the reason why I left out the implementation of Originally, I had in my mind read-only approach as the main use case for the project = api.Project.get(id=123)
project.time_entries # return all linked Time Entries to the Project But with the use-case of Tags, there will be the need also for being able to add/remove tags. Tags will be an especially special case because they are serialized as normal array/list for the time entries. As I am thinking about how to approach this, I believe that the main work will go into implementing a special container that will encapsulate the mapped entries. There should be a general implementation that could be used for the read-only/filter out use-case and then for specific use-cases there would be extended containers that would allow mutability. You could then specify for the mapping field with class FilterContainer(AbstractContainer)
...
class Project(api.TogglEntity):
time_entries = field.MappingField(TimeEntry, cardinality=field.MappingField.MANY, container=FilterContainer) Mapped ContainerIt is a question on its own, what capabilities of this container should be. I think that it could be quiet similar (at least from an interface point of view) to the Few things about the container:
The general filter should then have all the information to retrieve the filtered information, it could look something like: class FilterContainer:
def __init__(self, mapped_cls, reverse_field, instance):
self.entities = mapped_cls.objects.filter(**{reverse_field: instance.id}) MappingFieldMapping field then should mainly do work around constructing the Container, returning it to the user, handling serialization, parsing etc. Sorry for such a long reply, but hopefully this give you some direction on how to approach this. Let me know if you have any questions, suggestions anything 😄 |
Thanks for the reply! Initially I thought I was really going to need this many-many relationship for doing what I want with tags. But realizing how Tags are dealt with by Toggl itself, and that they are literally no more than an ID-Name pair means that that part can be pretty low on the list of priorities. At least getting the read-only version working for e.g. the Project-TimeEntries relationship would still be very nice though. Is probably a better starting point for me to start looking into anyway 😄 |
If a
TimeEntry
currently has tags associated to it, they are stored as a genericSetField
. To link the proper Tag model to the time entries thetags
field ofTimeEntry
should probably change to aMappingField
, but cardinality'many'
has not yet been implemented for those.I'd like to look into it, but I'm stuck with what has to be done to implement that. Any pointers would be very helpful.
The text was updated successfully, but these errors were encountered: