Skip to content

Instantly share code, notes, and snippets.

@LucasMagnum
Created August 17, 2017 19:48
Show Gist options
  • Save LucasMagnum/6d4a247ba749735ed2984931893643f7 to your computer and use it in GitHub Desktop.
Save LucasMagnum/6d4a247ba749735ed2984931893643f7 to your computer and use it in GitHub Desktop.
Product Models #djangotip02
# 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