Created
January 11, 2018 12:19
-
-
Save bencleary/f8bac22ae3ccf3fa072e75f32455ac49 to your computer and use it in GitHub Desktop.
Setup initial App for HTML to PDF tutorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from .models import * | |
admin.site.register(Sales) | |
admin.site.register(Products) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.auth.models import User | |
class Products(models.Model): | |
title = models.CharField(max_length=255) | |
price = models.DecimalField(default=0.00, max_digits=18, decimal_places=2) | |
def __str__(self): | |
return self.title | |
class Meta: | |
db_table = "tutorial_products" | |
verbose_name = "Product" | |
verbose_name_plural = "Products" | |
class Sales(models.Model): | |
product = models.ForeignKey(Products, on_delete=None) | |
quantity = models.IntegerField(default=0) | |
price = models.DecimalField(default=0.00, max_digits=18, decimal_places=2) | |
customer = models.ForeignKey(User, on_delete=None) | |
created_at = models.DateTimeField(auto_now_add=True) | |
def __str__(self): | |
return self.product | |
def save(self, *args, **kwargs): | |
self.price = self.product.price * self.quantity | |
super(Sales, self).save(*args, **kwargs) | |
class Meta: | |
db_table = "tutorial_product_sales" | |
verbose_name = "Sale" | |
verbose_name_plural = "Sales" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment