-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e826555
commit 9a81a2b
Showing
8 changed files
with
229 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from pathlib import Path | ||
|
||
from fake import FACTORY, FileSystemStorage, ModelFactory, SubFactory | ||
|
||
from article.models import Article, User | ||
|
||
__all__ = ( | ||
"ArticleFactory", | ||
"UserFactory", | ||
) | ||
|
||
# Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
MEDIA_ROOT = BASE_DIR / "media" | ||
|
||
STORAGE = FileSystemStorage(root_path=MEDIA_ROOT, rel_path="tmp") | ||
|
||
|
||
class UserFactory(ModelFactory): | ||
id = FACTORY.pyint() | ||
username = FACTORY.username() | ||
first_name = FACTORY.first_name() | ||
last_name = FACTORY.last_name() | ||
email = FACTORY.email() | ||
last_login = FACTORY.date_time() | ||
is_superuser = False | ||
is_staff = False | ||
is_active = FACTORY.pybool() | ||
date_joined = FACTORY.date_time() | ||
|
||
class Meta: | ||
model = User | ||
|
||
|
||
class ArticleFactory(ModelFactory): | ||
id = FACTORY.pyint() | ||
title = FACTORY.sentence() | ||
slug = FACTORY.slug() | ||
content = FACTORY.text() | ||
image = FACTORY.png_file(storage=STORAGE) | ||
pub_date = FACTORY.date() | ||
safe_for_work = FACTORY.pybool() | ||
minutes_to_read = FACTORY.pyint(min_value=1, max_value=10) | ||
author = SubFactory(UserFactory) | ||
|
||
class Meta: | ||
model = Article |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
from typing import Optional | ||
|
||
__all__ = ( | ||
"Article", | ||
"User", | ||
) | ||
|
||
|
||
@dataclass | ||
class User: | ||
id: int | ||
username: str | ||
first_name: str | ||
last_name: str | ||
email: str | ||
last_login: Optional[datetime] | ||
date_joined: Optional[datetime] | ||
password: Optional[str] = None | ||
is_superuser: bool = False | ||
is_staff: bool = False | ||
is_active: bool = True | ||
|
||
def __str__(self): | ||
return self.username | ||
|
||
|
||
@dataclass | ||
class Article: | ||
id: int | ||
title: str | ||
slug: str | ||
content: str | ||
author: User | ||
image: Optional[str] = None # Use str to represent the image path or URL | ||
pub_date: datetime = datetime.now() | ||
safe_for_work: bool = False | ||
minutes_to_read: int = 5 | ||
|
||
def __str__(self): | ||
return self.title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
import IPython | ||
|
||
|
||
def main(): | ||
"""Run administrative tasks.""" | ||
sys.path.insert(0, os.path.abspath(".")) | ||
IPython.embed() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters