MU
Feb. 20, 2019, 9:11 a.m.

User attendance in app

django, python, Django

Hi, i try to create list of users attendance in goal app.

But i don't know how to filter user.

I have Goal model:

class Goal(models.Model, Activity):
    title = models.CharField(max_length=255, verbose_name='Tytuł')
    image = ImageField(blank=True, verbose_name='Tło')
    body = HTMLField(verbose_name='Treść')
    tags = TaggableManager()
    created_at = models.DateTimeField(auto_now_add=True)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    slug = AutoSlugField(populate_from='title')

and Joined model:

class Joined(models.Model, Activity):
    goal = models.ForeignKey(Goal, on_delete=models.CASCADE, related_name='joined')
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='joined_users')
    created_at = models.DateTimeField(auto_now_add=True)
    joined = models.BooleanField(default=False)

I try:

def goalusers(request, slug):
    goal = get_object_or_404(Goal, slug=slug)

    users = goal.joined_users.all()

    return render(request, 'goals/users.html',
                {'goal': goal,
                'users': users})

This makes error: 'Goal' object has no attribute 'joined_users'.

I try also:

users = User.objects.filter(joined_users__joined__in=goal)

but then error is:
'Goal' object is not iterable.

Virtual hosting with 10 percent discount
Virtual hosting with 10 percent discount
EVILEG offers reliable hosting with a 10% discount for virtual hosting and 5% for VPS
4

Hello,

For second solution try this

users = User.objects.filter(joined_users__joined__in=[goal])

For first solution I think need to use annotate or aggregate methods, but it may be slowly and strongly.

0
MU

Now error say: ["Value 'Test' must be True or False."]

0

For me it is unexpected error.

What is 'Test' value? Do you use some object, in which exists some Test variable or member?

Do you have applied migrations?

0
MU

Yes, ok I have solution!

Thank you for directing me about annotate.:)

Solution is:

users_in = User.objects.filter(joined_users__goal=goal, joined_users__joined=True)
1

Comments

Only authorized users can post comments.
Please, Log in or Sign up
July 22, 2019, 7:26 a.m.
Pavel K.

Qt - Test 001. Signals and slots

  • Result:68points,
  • Rating points-1
o
July 22, 2019, 6:26 a.m.
oksik193

C++ - Test 001. The first program and data types

  • Result:80points,
  • Rating points4
VD
July 21, 2019, 11:33 p.m.
Vlad Dolgov

C++ - Test 001. The first program and data types

  • Result:40points,
  • Rating points-8
Last comments
July 21, 2019, 6:03 a.m.
Evgenij Legotskoj

да, наверное, 32-х разрядную поддержку уже давно поа было выкинуть. К слову, у вас много проектов под Android? Часто много где вижу вопросы о том, пишет ли кто-то вообще на Qt под мобильные сист…
July 20, 2019, 2:41 p.m.
Andrej Jankovich

Очень полезная информация, увы уже выкинул поддержку 32 битных бедняг.
July 20, 2019, 9:31 a.m.
Mihailll

Вот так qDebug()<<"position:"<<event->scenePos();
July 20, 2019, 8:49 a.m.
Mihailll

Добрый день. Как можно узнать координату на графической сцене при отпускании клавиши мыши?
Now discuss on the forum
July 22, 2019, 8:41 a.m.
BlinCT

Вот только что нашел в инете, у человека такая же ошибка. Вроде бы таже самая проблема https://stackoverflow.com/questions/37633709/how-to-create-qtquick-window-outside-the-main-thread…
July 22, 2019, 3:58 a.m.
Evgenij Legotskoj

Добрый день! Нужен совет сообщества по разработке функционала проверки орфографии. Одна из идей - добавить проверку орфографии при наборе текста статей. Полагаю, что наиболее аде…
July 22, 2019, 3:01 a.m.
Evgenij Legotskoj

Возможно, если при сохранении файла установить права доступа на файл. Что-то такое должно быть у QFile
July 22, 2019, 3:01 a.m.
Evgenij Legotskoj

Я отрисовываю квадрат в его локальной системе координат от верхнего левого угла (-30,-30) до его правого нижнего угла (30,30). Поэтому мне нужно указать размеры объекта через boundingRect()…
July 20, 2019, 11:04 a.m.
Mihailll

Так и с ресурсами работает QImage image(":/Images/Images/1.png");
Looking for a Job?
5,000.00 руб. - 15,000.00 руб.
Дизайнер
Moskovskiy, Moscow, Russia
25,000.00 руб. - 30,000.00 руб.
Разработчик Qt/C++
Barnaul, Altai Krai, Russia

For registered users on the site there is a minimum amount of advertising

EVILEG
About
Services
Join us
© EVILEG 2015-2019
Recommend hosting TIMEWEB