MU
Maciej UrmańskiDec. 11, 2019, 6:27 a.m.
Count user objects e.g posts
Hi, I try to get numbers of user post.
I have model Embed and try to count how many user add this embeds.
My model:
class Embed(models.Model): url = models.URLField(max_length=255) title = models.CharField(max_length=255, verbose_name='Tytuł') description = HTMLField(verbose_name='Opis', blank=True, null=True) type = models.CharField(blank=True, max_length=200) thumbnail_url = models.URLField(max_length=255, blank=True, null=True) image = models.ImageField(upload_to='recipes', blank=True) html = models.TextField() votes = GenericRelation(LikeDislike, related_query_name='embedlikes') added_by = models.ForeignKey(User, on_delete=models.CASCADE) created_at = models.DateTimeField(auto_now_add=True) category = TreeManyToManyField(RecipeCategory, blank=True, null=True, related_name='embeds', verbose_name='Kategoria') slug = AutoSlugField(populate_from='title', unique=True)
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
AD
- Akiv Doros
- Nov. 11, 2024, 2:58 p.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:50points,
- Rating points-4
m
- molni99
- Oct. 26, 2024, 1:37 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:80points,
- Rating points4
m
- molni99
- Oct. 26, 2024, 1:29 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:20points,
- Rating points-10
Last comments
Qt/C++ - Lesson 031. QCustomPlot – The build of charts with time buy generic priligy We can just chat, and we will not lose too much time anyway
Qt/C++ - Lesson 060. Configuring the appearance of the application in runtime I didnt have an issue work colors priligy dapoxetine 60mg revia cost uk August 3, 2022 Reply
Circuit switching and packet data transmission networks Angioedema 1 priligy dapoxetine
How to Copy Files in Linux If only females relatives with DZ offspring were considered these percentages were 23 order priligy online uk
Qt/C++ - Tutorial 068. Hello World using the CMAKE build system in CLion ditropan pristiq dosing With the Yankees leading, 4 3, Rivera jogged in from the bullpen to a standing ovation as he prepared for his final appearance in Chicago buy priligy pakistan
Now discuss on the forum
добавить qlineseries в функции priligy amazon canada 93 GREB1 protein GREB1 AB011147 6
Всё ещё разбираюсь с кешем. priligy walgreens levitra dulcolax carbs The third ring was found to be made up of ultra relativistic electrons, which are also present in both the outer and inner rings
IscanderCheOct. 31, 2024, 3:43 p.m.
Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…
ИМ
Реализация навигации по разделам Спасибо Евгений!
Игорь МаксимовOct. 3, 2024, 4:05 a.m.
Hello,
Try this
Hmm this count every recipes. Not only one user.
I try something like that from stackoverflow:
But then error appear:
Manager isn't accessible via Embed instances
I have this from there: https://stackoverflow.com/questions/50393455/count-the-number-of-posts-by-a-user-django
May be, because, you don`t have field "author" in your model... ?
And in this code you get object of model
Therefore you cannot use objects in this row
Because of objects can be used only in this situation
And I don`t see author instance in your code.
You can write something else like this
But you should get author instance from anywhere, for example request.user
Yeah I edit my answer and change to added_by. But still this don't work.
added_by must be some author instance, some object. You should get this object from anywhere. In your code you don`t make any actions for getting author instance.
Ok, try this
or this
Thank you! Now works, and this is solution.