I Want to Build Your Website
Follow me here and let me show you what I can do!
Build T-Shirt Model
With the framework that I use to build sites ( django ), I start with my drawing, and then move to modeling my data. When I model my data, I usually get out my trusty blank piece of paper and start writing down the things that I think are needed for a particular piece of data. Since we are building a T-Shirt shop, I thought the best place to start would be with the T-Shirt data. That is essentially the bulk of the content for the site.
Here are the things that will be part of every T-Shirt.
- Title: all shirts need some kind of title to identify it
- Description: Something short that describes the shirt in a few more words
- Image: This is kinda a big deal, since people are going to want to buy something they can see
- Price: We don't intend to build something for free, so there needs to be a price.
- Colors: This is an interesting one. I think we need to create a separate class for all the colors, because each design could have different set of colors associated with it. I think this needs a name and a hex value associated with it.
- Category: To make searching easier and associating shirts with each other, this puts things into a more manageable classification.
- Slug: This basically creates the sexy url that we'll use for all shirt detail pages.
- Pub Date: We'll want to see how long a shirt has been available. Plus we may want to build some pages like the "Newest" or "Recently Changed". We might also want to create an archive of shirts. A date just gives us a lot more options for the future.
- Status: This is important when it comes to uploading new shirt designs. We may want to get the ball rolling, but not ready for a shirt to be live. So we'll need a way to separate those that are live from those that are in draft form, or even retired.
- Meta Tags: This will be for keywords and description. It's one of those things we need for SEO.
- Number of looks: We'll want to track our most popular viewed shirts. Along with that we'll want to track when the last time someone actually viewed a particular shirt.
- Designer: We will want to track the designer of the shirt. Right now it's simply a matter of having this field available. But in the future if we have more than one contributor, then this will be important.
from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
from markdown import markdown
from photologue.models import Gallery, Photo
import markdown
import datetime
LIVE_STATUS = 1
DRAFT_STATUS = 2
RETIRED_STATUS = 3
STATUS_CHOICES = (
(LIVE_STATUS, "Live"),
(DRAFT_STATUS, "Draft"),
(RETIRED_STATUS, "Retired"),
)
class Colors(models.Model):
name = models.CharField(max_length=25, help_text="The name of the color")
hex = models.CharField(max_length=6, help_text="Hexidecimal value of the color")
slug = models.SlugField(unique=True, help_text="Suggested value automatically generated from name. Must be Unique.")
def __unicode__(self):
return self.name
class Category(models.Model):
title = models.CharField(max_length=250, help_text="Maximum 250 characters")
slug = models.SlugField(unique=True, help_text="Suggested value automatically generated from title. Must be Unique.")
description = models.TextField(help_text="This is a full length description of the category")
class Meta:
verbose_name_plural = "Categories"
def __unicode__(self):
return self.title
def get_absolute_url(self):
return "/category/%s/" % self.slug
class Shirt(models.Model):
# Core Fields
title = models.CharField(max_length=250,help_text="Maximum 250 Characters", blank=False)
description= models.TextField(blank=False)
price = models.CharField(max_length=6, help_text="Price of the Shirt", blank=False)
colors = models.ManyToManyField(Colors)
image = models.ForeignKey(Photo, blank=True, null=True)
gallery = models.ForeignKey(Gallery, blank=True, null=True)
pub_date=models.DateTimeField(default=datetime.datetime.now)
# Metadata
slug=models.SlugField(unique_for_date='pub_date', help_text="Suggested value automatically generated from title")
designer = models.ForeignKey(User)
status = models.IntegerField(choices=STATUS_CHOICES, default=LIVE_STATUS, help_text="Only entries with 'Live' status will be publicly displayed")
categories = models.ManyToManyField(Category)
#SEO
keywords = models.CharField(max_length=160, blank=True, null=True, help_text="Use Keywords that are related to the title")
meta_description = models.TextField(blank=True)
# Who's Looking
last_accessed = models.DateTimeField(blank=True,null=True)
views = models.IntegerField(blank=True, null=True, default=0)
# Fields to store generated HTML
description_html = models.TextField(editable=False, blank=True)
def __unicode__(self):
return self.title
def get_absolute_url(self):
return "/shirt/%s/" % (self.slug)
def save(self):
self.description_html = markdown.markdown(self.description)
super(Shirt, self).save()
Current Projects
In Production
Recently on twitter
Categories
Archives
Content is licensed under a Creative Commons Public Domain License






Comments
No Response Yet
Why don't YOU kick it off by saying something ↓