please ignore the manager it is just a naming convention ignore, it if for me to identify tables, if i have 50 table, I want to be able to know which model is holding which object information and for what I need it.
Please use below, I have removed the # information to reduce confusion.
models.py
class Project(models.Model):
name = models.CharField(max_length=100)
budget = IntegerField()
def save(self, *args, **kwargs):
self.name
super(Project, self).save(*args, **kwargs)
class Category(models.Model):
project = models.ForeignKey(
Project, on_delete=models.CASCADE)
name = models.CharField(max_length=150)
class Expense(models.Model):
project = models.ForeignKey(
Project, on_delete=models.CASCADE, related_name='expenses')
title = models.CharField(max_length=100)
amount = models.DecimalField(max_digits=8, decimal_places=2)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
On 6 Sep 2019, at 20:45, Bhoopesh sisoudiya <bhoop23sis@gmail.com> wrote:
Best wishes,
Kean
Ok No problem butwhy you want Manager?Please send me answerThanksBhoopesh sisoudiyaOn Sat, Sep 7, 2019, 1:06 AM Kean <keanld1@gmail.com> wrote:Hi BhoopeshThanks for this, please can you put it into the context of my specific model setup, so I get it right and understand.This will be easier for me as this approach is causing me some other errors, when i try to apply it.Best wishes,KeanOn 6 Sep 2019, at 20:19, Bhoopesh sisoudiya <bhoop23sis@gmail.com> wrote:Hi Kean,Write manager like this ,I give you referencefrom django.db import models# First, define the Manager subclass.class BhoopeshBookManager(models.Manager):def get_queryset(self):return super(BhoopeshBookManager, self).get_queryset().filter(author='Bhoopesh')# Then hook it into the Book model explicitly. class Book(models.Model):title = models.CharField(max_length=100)author = models.CharField(max_length=50)# ...objects = models.Manager()# The default manager.bhoopesh_objects = BhoopeshBookManager()# The Bhoopesh-specific manager.Book.bhoopesh_objects.all() # use managerThanksBhoopesh KumarOn Sat, Sep 7, 2019, 12:34 AM Bhoopesh sisoudiya <bhoop23sis@gmail.com> wrote:Hi kean,Please check Expenses Class is not ManagerPlease make Manager Class.ThanksBhoopesh sisoudiyaOn Sat, Sep 7, 2019, 12:20 AM Kean <keanld1@gmail.com> wrote:Hi,New to Django. when navigating to the reqired view, I get the error above.urls.pypath('businesslogin/businessadmin/busproject', views.projectdetail, name='projectdetail'),views.pydef projectdetail(request):project = Project.objects.all()return render(request, 'busprojectdetail.html', {'project': project, 'expense_list': project.expenses.all()})models.py# Project modelclass Project(models.Model):name = models.CharField(max_length=100)budget = IntegerField()def save(self, *args, **kwargs):super(Project, self).save(*args, **kwargs)# Category manager modelclass Category(models.Model):project = models.ForeignKey(Project, on_delete=models.CASCADE)name = models.CharField(max_length=150)# Expenses manager modelclass Expense(models.Model):project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name='expenses')title = models.CharField(max_length=100)amount = models.DecimalField(max_digits=8, decimal_places=2)category = models.ForeignKey(Category, on_delete=models.CASCADE)the error is as follows:
Exception Type: AttributeError Exception Value: 'QuerySet' object has no attribute 'expenses'Exception Location: /Users/ProductionEnv/Desktop/test/test1/dev/core/views.py in projectdetail, line 238
Please can anyone help?
Best
K--
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/024bc998-b683-41ae-90e2-d33f4527913a%40googlegroups.com.--
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/CAAk3c1NmgbP7cQtyX8uOAFX%3DXbyC6f2ug1FURabwxRgD44Mwpg%40mail.gmail.com.--
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/52D49AAA-5E17-4F6C-92DE-E1576F305927%40gmail.com.
--
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/CAAk3c1PtFX7oNie8qZKF%3Dm7jFrCEMwTZfn%2BcvWBFSqc9FT0h4A%40mail.gmail.com.
No comments:
Post a Comment