2

I have data that looks like:
Store Count_Customers Count_Purchases BestBuy 2 2 Target 1 1 Target 4 3 Walmart 5 1 Target 9 1

I want to use a django model to produce a list of stores, and summaries by stores.

So I have models.py as:

class UniqueStore(models.Model):
    store = models.CharField(db_column='store', max_length=100, unique=True)


class Summarize(object):
    store = models.ForeignKey(UniqueStore,
                             on_delete=models.CASCADE, unique=True) 
    sum_customers = models.IntegerField(u"count_customers") 
    sum_purchases = models.IntegerField(u"count_purchases")

and my_summary.py as a management command as

class Command(BaseCommand):
    help = "Summary by store"

    def handle(self, *args, **options):
        print("Stores: {}".format(UniqueStore.objects.all().count()))
        print("Facts: {}".format(Summarize.objects.all().sum()))

but even before I run python manage.py my_summary, I get the error unresolved attribute reference: object

Could help me understand how to fix this error?

I dont see this resolved in the documentation: https://docs.djangoproject.com/en/3.0/topics/db/models/

If it has to do with metaclass (django model referencing object from other class), could someone provide additional resources/explanation?

2
  • What do you mean "but even before I run python manage.py my_summary"? What are you executing that results in the error message? Commented Dec 7, 2019 at 19:20
  • IDE Pycharm highlights the error, and then yes when I try to run that command I get AttributeError: type object 'Summarize' has no attribute 'objects' Commented Dec 7, 2019 at 19:26

1 Answer 1

1

Summarize is type object but it needs to be type Model instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.