Permalink
Browse files

New models: TweetAuthor & Tweet

  • Loading branch information...
FrancoisConstant committed Jul 8, 2018
1 parent 27d431a commit 6ba208b4abfffab3e96fa31143a510e0b8544a89
Showing with 75 additions and 0 deletions.
  1. +45 −0 ede/migrations/0001_initial.py
  2. 0 ede/migrations/__init__.py
  3. +12 −0 ede/mixins.py
  4. +18 −0 ede/models.py
@@ -0,0 +1,45 @@
# Generated by Django 2.0.1 on 2018-07-08 06:54
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Tweet',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('content', models.TextField()),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='TweetAuthor',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('name', models.CharField(max_length=100)),
('username', models.CharField(max_length=100)),
],
options={
'abstract': False,
},
),
migrations.AddField(
model_name='tweet',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tweets', to='ede.TweetAuthor'),
),
]
No changes.
View
@@ -0,0 +1,12 @@
from django.db import models
class TimestampsMixin(models.Model):
"""
`created_at` and `updated_at`
"""
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
View
@@ -0,0 +1,18 @@
from django.db import models
from ede.mixins import TimestampsMixin
class TweetAuthor(TimestampsMixin, models.Model):
""" The one who writes the tweets (or their minion) """
name = models.CharField(max_length=100)
username = models.CharField(max_length=100)
@property
def url(self):
""" e.g. https://twitter.com/jesus """
return "https://twitter.com/{username}".format(username=self.username)
class Tweet(TimestampsMixin, models.Model):
author = models.ForeignKey(to="ede.TweetAuthor", related_name="tweets", on_delete=models.CASCADE)
content = models.TextField()

0 comments on commit 6ba208b

Please sign in to comment.