product DB
This commit is contained in:
parent
d1ac07a066
commit
bf7b9d2a9d
@ -1,3 +1 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
|
@ -1,3 +1,4 @@
|
||||
from django.contrib import admin
|
||||
from .models import Product
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(Product)
|
||||
|
31
products/migrations/0001_initial.py
Normal file
31
products/migrations/0001_initial.py
Normal 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)),
|
||||
],
|
||||
),
|
||||
]
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user