Models.py
class Listing(models.Model):
name = models.CharField(max_length=20)
description = models.TextField(max_length = 100)
website = models.URLField()
category = models.ForeignKey(Category)
class Category(models.Model):
category_code = models.CharField(max_length = 50, primary_key=True,
blank=False)
category_name = models.CharField(max_length = 50,)
def __unicode__(self):
return self.category_code
i have cat_list.html which list all the category with name only as
link if some one wants to know more details he/she may click on that
link.
urls.py
(r'^category/category_view/$','mysite.library.views.categories'),
(r'^category/category_view/(?P<category_code>\w+)/
$','mysite.library.views.category_info'),
views.py
def categories(request):
result_category = Category.objects.all()
return render_to_response("cat_list.html",
{'result_category':result_category})
def category_info(request, category_code):
result_category = get_object_or_404(Category, pk = category_code)
--------->result_listing = get_object_or_404(Listing, pk = id)
print result_category
return render_to_response("category_view.html",
{'result_category':result_category,'result_listing':result_listing})
see ------>result_listing in category_info function. i want to display
some info of Listing tables of corresponding category_code.
when i use
1--> result_listing = get_object_or_404(Listing, pk = id) then i get
an error
id() takes exactly one argument (0 given)
2--> result_listing = get_object_or_404(Listing, pk = category_id)
then i am not getting the exact result cause Category(category_code)
is checking with Listing(id). it should check with category_id of
Listing tables.
i do not know how may i access corresponding records from two tables.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---