django-todo icon indicating copy to clipboard operation
django-todo copied to clipboard

Assign task to multiple people

Open james1293 opened this issue 5 years ago • 26 comments

Hello all, I just started using Django todo, and I love the simplicity of it. I recently hacked together a fork (locally, not on GitHub) that allows a task to be assigned to multiple users. It's not perfect yet, but would this be something worth sharing? If so, would it be the sort of thing that would stay as a fork, or could it be incorporated into the main project repo? (I haven't contributed much on GitHub, so that's why I'm asking for etiquette advice.) Thanks!

james1293 avatar Apr 05 '19 17:04 james1293

Hi James - this is a great idea. It should be as simple as converting the ForeignKey from Task to User to a ManyToMany field, and modifying the UI to allow multi-assignment. It would also have to ensure that emails are sent to all of the right parties.

The general process for contributing to open source on github is this:

  1. Fork the project (you already have)
  2. Make your changes in a branch and push the branch to your fork's repo
  3. Make a pull request for that branch, targeted at this repo
  4. We'll go through the review process - I'll suggest changes, you'll push additional commits
  5. I'll merge it and it will be in!

Thanks.

shacker avatar Apr 06 '19 06:04 shacker

I tried simply converting the ForeignKey from Task to User to a ManyToMany field, it worked almost correctly, except the task_detail view, where i couldn't update the "Assigned to:" column. However it worked fine when creating a new task, or editing the task from the admin panel. Any suggestion?

GoldenBookCover avatar May 10 '19 22:05 GoldenBookCover

Two things - You have to add form.save_m2m() For the list display, I did .join(", ")

james1293 avatar May 11 '19 01:05 james1293

@MonstreCharmant You would need to replace the Assigned To dropdown with some sort of multiple-choice selection widget. Or did you do that already and I'm misunderstanding the question?

shacker avatar May 11 '19 06:05 shacker

Thank you guys, I just added form.save_m2m(), it worked fine. The code looks like this now, I'm not sure if there is any impact to my data?

# from task_detail.py --> def task_detail() --> # Save task edits
if form.is_valid():
            item = form.save(commit=False)
            item.note = bleach.clean(form.cleaned_data["note"], strip=True)
            item.save()
            form.save_m2m()
            messages.success(request, "The task has been edited.")
            return redirect(
                "todo:list_detail",
                list_id=task.task_list.id,
                list_slug=task.task_list.slug,
            )

GoldenBookCover avatar May 11 '19 21:05 GoldenBookCover

@MonstreCharmant I added form.save_m2m() in the same place, and it seems to be working. Would you like to share your fork, or do you want me to share mine? Mine is messy (I commented tests that didn't work any more, and I disabled the email notifications) but I could share it as-is anyway...

james1293 avatar May 20 '19 20:05 james1293

Still hoping that one of you can share your changes back to the mother project here! Pull request please?

shacker avatar Sep 20 '19 06:09 shacker

Yes, will do that. Working on some jobs now, but I'll share my changes once I got some time.

GoldenBookCover avatar Sep 20 '19 09:09 GoldenBookCover

Yes, will do that. Working on some jobs now, but I'll share my changes once I got some time.

can you share your changes

f4i5i avatar Mar 05 '21 12:03 f4i5i

I'm sorry that I never did share mine. I'm no longer working at the job where I was working on this, so I don't think that I would be able to access the code easily. If you decide to reimplement it, I wish you the best of luck.

james1293 avatar Mar 05 '21 16:03 james1293

can you guide me how you done the task few tips

f4i5i avatar Mar 05 '21 17:03 f4i5i

It has been 2 years, so I don't remember a lot of the details. It was something like this:

  • Remove the assigned_to field here.
  • Add a field called assigned_users (or similar). It would look like this: assigned_users = models.ManyToManyField(...).
  • Run a database migration.
  • Search the code for occurrences of assigned_to. Change them appropriately.
    • In particular, when saving a task, you'll need to run form.save_m2m(), as described earlier in this thread.

Feel free to ask follow-up questions. :slightly_smiling_face:

james1293 avatar Mar 05 '21 17:03 james1293

okay what for selection of users from template

f4i5i avatar Mar 05 '21 17:03 f4i5i

I think I started by making sure it worked using the default multi-select interface. Then, once I was sure that that worked, I figured out how to use the pretty widget from the Django admin. There's some advice here (I recommend reading the comments on that answer).

Does that make sense?

james1293 avatar Mar 05 '21 18:03 james1293

todo

f4i5i avatar Mar 06 '21 06:03 f4i5i

it show something like this and the values not saving in db and i want to make check box to select multiple users

f4i5i avatar Mar 06 '21 06:03 f4i5i

one error is this that it show account.customuser.none task 2

f4i5i avatar Mar 06 '21 07:03 f4i5i

Did you add form.save_m2m() as discussed earlier in this thread? That may be the reason why it's not saving.

I've never tried doing the checkboxes.

james1293 avatar Mar 06 '21 15:03 james1293

yes i do

f4i5i avatar Mar 07 '21 17:03 f4i5i

I don't think there's much more I can do to help right now.

james1293 avatar Mar 07 '21 18:03 james1293

one error is this that it show account.customuser.none task 2

I had the same issue of m2m fields being rendered with this "none" thing in a table. Have you tried to add something like this in the template ? `

{% for customuser in accounts.customuser.all %} {{ customuser.name }} {% endfor %} `

This loop worked fine for me, I hope it will help you ! ps : first comment ever on GitHub - please let me know if I broke any etiquette ^^

diogne avatar Mar 28 '21 01:03 diogne

@diogne thank you, hopefully @f4i5i finds that helpful! :slightly_smiling_face:

If you want, you can submit a pull request to accomplish what I never succeeded in finishing :sweat_smile:

By the way, just so you know about the feature: if you want to put multiple lines of code, a way to do it is to indent them, like this:

these words have four spaces before them
which makes them render as monospace font

james1293 avatar Mar 28 '21 18:03 james1293

Many thanks for your kind reply and the tips ! I appreciate it !

diogne avatar Mar 28 '21 23:03 diogne

This is a great idea and it would rock if someone PRed it.

bernd-wechner avatar Sep 23 '21 15:09 bernd-wechner

@bernd-wechner what is the credentials to log

palrohitg avatar Oct 10 '21 13:10 palrohitg

@bernd-wechner what is the credentials to log

Sorry, but I'm not sure what you're asking. Can you clarify?

bernd-wechner avatar Oct 10 '21 21:10 bernd-wechner