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?
python manage.py my_summary"? What are you executing that results in the error message?AttributeError: type object 'Summarize' has no attribute 'objects'