Last active
August 3, 2018 01:49
-
-
Save OHua/211b21531d9b26db84781e285616ca5b to your computer and use it in GitHub Desktop.
error code about content_object in Django Genericforeignkey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FieldError at /member/brand/productmanage/checkarrived/9 | |
Field 'content_object' does not generate an automatic reverse relation and therefore cannot be used for reverse querying. If it is a GenericForeignKey, consider adding a GenericRelation. | |
Request Method: GET | |
Request URL: http://localhost:8000/member/brand/productmanage/checkarrived/9?ptype=productitem | |
Django Version: 2.0.6 | |
Exception Type: FieldError | |
Exception Value: | |
Field 'content_object' does not generate an automatic reverse relation and therefore cannot be used for reverse querying. If it is a GenericForeignKey, consider adding a GenericRelation. | |
Exception Location: /home/ubuntu/ohua/testenv/lib/python3.5/site-packages/django/db/models/sql/query.py in names_to_path, line 1360 | |
Python Executable: /home/ubuntu/ohua/testenv/bin/python |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/home/ubuntu/ohua/gitrepo/pypro/member/views.py in checkarrived | |
TL.first = ProductPackageClass.objects.filter(package=tl).order_by('date','time').first() | |
TL.date = TL.first.start_date | |
TL.time = TL.first.start_time | |
else : | |
raise Http404 | |
product = TL.product | |
orderitems = OrderItem.objects.filter(product=product,content_object=TL) ... | |
context = { | |
'TL': TL, | |
'orderitems': orderitems, | |
} | |
return render(request, 'checkarrived.html', context) | |
▼ Local vars | |
Variable Value | |
TL | |
<ProductItem: 課程a 的課程時間> | |
id | |
9 | |
product | |
<Product: 課程[email protected]> | |
request | |
<WSGIRequest: GET '/member/brand/productmanage/checkarrived/9?ptype=productitem'> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@login_required | |
def checkarrived(request, id): | |
# if this product is not yours , you should get 404 | |
# TL = Time & Location , whatever productitem or productpackage | |
if request.GET.get('ptype', False) : | |
if request.GET.get('ptype') == 'productitem' : | |
TL = ProductItem.objects.get(id=id) | |
TL.date = TL.start_date | |
TL.time = TL.start_time | |
else : | |
TL = ProductPackage.objects.get(id=id) | |
TL.first = ProductPackageClass.objects.filter(package=tl).order_by('date','time').first() | |
TL.date = TL.first.start_date | |
TL.time = TL.first.start_time | |
else : | |
raise Http404 | |
product = TL.product | |
orderitems = OrderItem.objects.filter(product=product,content_object=TL) | |
context = { | |
'TL': TL, | |
'orderitems': orderitems, | |
} | |
return render(request, 'checkarrived.html', context) |
Author
OHua
commented
Aug 3, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment