product DB

This commit is contained in:
Sharad Ahlawat 2020-03-10 12:01:41 -07:00
parent d1ac07a066
commit bf7b9d2a9d
4 changed files with 54 additions and 4 deletions

View File

@ -1,3 +1 @@
from django.contrib import admin
# Register your models here.

View File

@ -1,3 +1,4 @@
from django.contrib import admin
from .models import Product
# Register your models here.
admin.site.register(Product)

View File

@ -0,0 +1,31 @@
# Generated by Django 3.0.3 on 2020-03-10 18:56
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Product',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=200)),
('url', models.CharField(max_length=200)),
('pubdate', models.DateTimeField()),
('votes_total', models.IntegerField(default=1)),
('image', models.ImageField(upload_to='images/')),
('icon', models.ImageField(upload_to='images/')),
('body', models.TextField(max_length=1000)),
('hunter', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

View File

@ -1,3 +1,23 @@
from django.db import models
from django.contrib.auth.models import User
class Product(models.Model):
title = models.CharField(max_length=200)
url = models.CharField(max_length=200)
pubdate = models.DateTimeField()
votes_total = models.IntegerField(default=1)
image = models.ImageField(upload_to='images/')
icon = models.ImageField(upload_to='images/')
body = models.TextField(max_length=1000)
hunter = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return self.title
def summary(self):
return self.body[:100]
def pubdate_pretty(self):
return self.pubdate.strftime('%b %e %Y')
# Create your models here.