All I want to do is display related Subcats on the detail page under the Category detail.
Seems like the exact same thing as the Books/Publisher demo but I just can't get it to work. It keeps saying my field doesn't exist, or it pulls all the records from the entire table for every entry in the Category table. This seems like it should be so simple. I'm really starting to get discouraged here.
This is my VIEW. Below are my models.
class CatDetailView(DetailView):
model = Category
template_name = 'ohnet/category_detail.html'
def get_context_data(self, **kwargs):
context = super(CatDetailView, self).get_context_data(**kwargs)
context['subcats'] = SubCat.objects.filter(category_id=self.get_object())
return context
model = Category
template_name = 'ohnet/category_detail.html'
def get_context_data(self, **kwargs):
context = super(CatDetailView, self).get_context_data(**kwargs)
context['subcats'] = SubCat.objects.filter(category_id=self.get_object())
return context
MODEL
class Category(models.Model):
category_name = models.CharField(max_length=200, default=None)
date_entered = models.DateTimeField(auto_now_add=True)
customer_id = models.SmallIntegerField(default=0)
is_active = models.BooleanField(default=True)
scr_pending = models.BooleanField(default=False)
scr_pending_date = models.DateTimeField(default=None, null=True)
header_id = models.SmallIntegerField(default=0)
last_script_added = models.DateTimeField(default=None)
category_type = models.SmallIntegerField(default=0)
writer = models.SmallIntegerField(models.ForeignKey(Emp, related_name='+', on_delete=models.CASCADE), default=0)
nickname = models.CharField(max_length=50, default=None, null=True)
def __str__(self):
return self.category_name
def get_absolute_path(self):
return reverse('cat-det', args=[self.id])
class SubCat(models.Model):
category = models.ForeignKey(Category, related_name='+', on_delete=models.CASCADE)
subcat = models.CharField(max_length=200, default=None)
scope_users = models.CharField(max_length=200, default=None, null=True)
scope_loc_reg = models.CharField(max_length=200, default=None, null=True)
is_featured = models.BooleanField(default=False)
date_entered = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.subcat
-- category_name = models.CharField(max_length=200, default=None)
date_entered = models.DateTimeField(auto_now_add=True)
customer_id = models.SmallIntegerField(default=0)
is_active = models.BooleanField(default=True)
scr_pending = models.BooleanField(default=False)
scr_pending_date = models.DateTimeField(default=None, null=True)
header_id = models.SmallIntegerField(default=0)
last_script_added = models.DateTimeField(default=None)
category_type = models.SmallIntegerField(default=0)
writer = models.SmallIntegerField(models.ForeignKey(Emp, related_name='+', on_delete=models.CASCADE), default=0)
nickname = models.CharField(max_length=50, default=None, null=True)
def __str__(self):
return self.category_name
def get_absolute_path(self):
return reverse('cat-det', args=[self.id])
class SubCat(models.Model):
category = models.ForeignKey(Category, related_name='+', on_delete=models.CASCADE)
subcat = models.CharField(max_length=200, default=None)
scope_users = models.CharField(max_length=200, default=None, null=True)
scope_loc_reg = models.CharField(max_length=200, default=None, null=True)
is_featured = models.BooleanField(default=False)
date_entered = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.subcat
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4f0f1bad-1389-4a66-93fb-9f7a301dc936n%40googlegroups.com.
No comments:
Post a Comment