I am new to Django and wanted to know how to retrieve a record from django database. Since I am learning, I don't know if model created by me is correct or not.
model.py
class ProductCategory(models.Model):
prodname = models.CharField(_("Product Name"), max_length=128, primary_key=True)
prodowner = models.CharField(_("Product Owner Name"), max_length=100)
email_message_id = models.CharField(_("e-mail message ID"), max_length=255, blank=True, null=True)
dependency = models.ManyToManyField(ThirdpartyProduct, related_name='tplibcategories')
def __unicode__(self):
return u'%s' % ( self.prodname )
This is my product table which has many to many field pointing to thirdpartyProduct table, The requirement is each product has multiple dependency on thirdparty library so a product can dependent on multiple component and it might possible that component can also become Product.
ThirdparyproductTable
class ThirdpartyProduct(models.Model):
tplib_name = models.CharField(_("Library Name"), max_length=128)
tplib_type = models.CharField(_("Library Type"), max_length=10 choices=LIBTYPE, default='LIB')
def __unicode__(self):
return u'%s' % ( self.tplib_name )
My views.py
When I try display dependency it only shows my thirdparty components, I dont know how to formulate queryset so that I can get Product name and its all thirdparty component details.
class MyThirdpartyView(ListView):
model = ThirdpartyProduct
template_name = 'thirdpartyproduct_list.html'
Base.html
<h1>ThirdParty</h1>
<ul>
{% for tp in object_list %}
<li class="thirdparty">{{ tp }}</li>
{% endfor %}
</ul>
I know some issue is there, but I need your valuable comments and some workable solution.