Tuesday, October 30, 2018

I'm getting nothiong on template after filtering there so i'm looking for a solution to filter in a model thorugh foreign key

views.py
from django.shortcuts import render
from .models import inherit
# Create your views here.

def homepage(request):
ab = inherit.objects.filter(name__name__contains='karan')

return render(request, 'jobs/index.html', {'x':ab} )


Models.py

from django.db import models

# Create your models here.


class main(models.Model):
name = models.CharField(max_length=200)

def __str__(self):
return self.name

class inherit(models.Model):
namein = models.CharField(max_length=200)
name = models.ForeignKey(main, on_delete=models.CASCADE)
slug = models.SlugField(max_length=40)
pas = models.CharField(max_length=200)
index.html
{% for x in y.all %}
<h1>{{ y.namein }}</h1>
{% endfor %}


--
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/bda75925-ea05-4418-81b9-75151cd01945%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment