Hello Todor,

I followed your directions and 
used https://docs.djangoproject.com/ja/1.9/ref/contrib/contenttypes/ for 
reference but I got stuck at error 'GenericForeignKey' object has not 
attribute 'get_lookup'. I tried 
Product.objects.aggregate(Count('hits'))[:6]. In my models.py I got 
following code:

hits = GenericRelation(HitCount, content_type_field='content_object', 
object_id_field='object_pk',)

    class Meta:
        ordering = ["-title"]
Removed the -hits from ordering section and rest of the code is same. I 
searched it on google but it showed some Django based bugs.
Any suggestions?
Thanks,



On Thursday, August 4, 2016 at 2:07:53 PM UTC-7, Todor Velichkov wrote:
>
> My field hits=models.ForeignKey(Hitcount) means that my Product model has 
>> a related  model with multiple fields and all the products in Product model 
>> will have one or more hit records. Instance of Product model will save a 
>> hit from end user by session/ip/user etc.
>
> Honestly, I don't understand that. 
>
> The HitCount class already has a GenericForeignKey, maybe you are looking 
> for a Reverse Generic Relation 
> <https://docs.djangoproject.com/ja/1.9/ref/contrib/contenttypes/#reverse-generic-relations>
>  
> class in order to get the Hits for a product.
>
> On Thursday, August 4, 2016 at 10:42:58 PM UTC+3, M Hashmi wrote:
>>
>> My field hits=models.ForeignKey(Hitcount) means that my Product model has 
>> a related  model with multiple fields and all the products in Product model 
>> will have one or more hit records. Instance of Product model will save a 
>> hit from end user by session/ip/user etc.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2a7be23a-c227-460d-89f2-d7ffd52d4123%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to