Spaces:
Runtime error
Runtime error
Download dashboard/models.py from OLETECH/BUSINESSTRACKER: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/spaces/OLETECH/BUSINESSTRACKER/resolve/main/dashboard/models.py
- Command line
-
hf download hf://spaces/OLETECH/BUSINESSTRACKER/dashboard/models.py
-
curl -L -o models.py https://huggingface.co/spaces/OLETECH/BUSINESSTRACKER/resolve/main/dashboard/models.py
1.68 kB
| from django.db import models | |
| # Create your models here. | |
| from django.db import models | |
| from django.contrib.auth import get_user_model | |
| User = get_user_model() | |
| class Sale(models.Model): | |
| """Represents a single sale made by the business""" | |
| user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='sales') | |
| item_name = models.CharField(max_length=255) | |
| quantity = models.PositiveIntegerField(default=1) | |
| unit_price = models.DecimalField(max_digits=12, decimal_places=2) | |
| total = models.DecimalField(max_digits=12, decimal_places=2) | |
| date = models.DateField() | |
| created_at = models.DateTimeField(auto_now_add=True) | |
| def save(self, *args, **kwargs): | |
| # Auto calculate total before saving | |
| self.total = self.quantity * self.unit_price | |
| super().save(*args, **kwargs) | |
| def __str__(self): | |
| return f"{self.item_name} - {self.total}" | |
| class Expense(models.Model): | |
| """Represents a single expense made by the business""" | |
| CATEGORY_CHOICES = [ | |
| ('rent', 'Rent'), | |
| ('stock', 'Stock'), | |
| ('transport', 'Transport'), | |
| ('utilities', 'Utilities'), | |
| ('other', 'Other'), | |
| ] | |
| user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='expenses') | |
| description = models.CharField(max_length=255) | |
| amount = models.DecimalField(max_digits=12, decimal_places=2) | |
| category = models.CharField(max_length=50, choices=CATEGORY_CHOICES, default='other') | |
| date = models.DateField() | |
| created_at = models.DateTimeField(auto_now_add=True) | |
| def __str__(self): | |
| return f"{self.description} - {self.amount}" |