Created
August 17, 2017 19:48
-
-
Save LucasMagnum/6d4a247ba749735ed2984931893643f7 to your computer and use it in GitHub Desktop.
Product Models #djangotip02
This file contains 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
# product/models.py | |
from django.db import models | |
class Category(models.Model): | |
name = models.CharField(max_length=120) | |
is_active = models.BooleanField(default=True) | |
subcategories = models.ManyToManyField('self', symmetrical=False) | |
def __str__(self): | |
return self.name | |
class Product(models.Model): | |
title = models.CharField(max_length=120) | |
category = models.ForeignKey(Category) | |
def __str__(self): | |
return self.title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment