0
Python inheritance question
Hello, pythoneers! ^^ A question about Python/Django: I have a parent class Page which has fields like: Title, etc. and have another child class Services(Page) . My view is: def serviceDetails(request, Slug): obj=Services.objects.filter(Slug=Slug) context = { 'obj' : obj, } return render(request, 'home/our-service-details.html',context) How can I access the fields of the parent class Page in my the template? {{obj.Title}} does not work
4 Respuestas
+ 1
Yes, Akshay, I solved the problem, and you're right! The mistake was to use filter instead of get().
Thank you!
0
Or should I add Foreign Key Field ?
0
Sorry for late reply. I don't know whether your problem is solved or not but I can see you are using `filter` method and this returns a queryset. So {{obj.Title}} will not work directly, firstly you have to access the inner elements of queryset and then use template tag.
{% for o in obj %}
{{o.Title}}
{% endfor %}