Hello Todor,
On Thursday, August 4, 2016 at 2:07:53 PM UTC-7, Todor Velichkov wrote:
-- 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 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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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.
No comments:
Post a Comment