Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial models creation #28

Open
wants to merge 6 commits into
base: nightly
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions FriendsWave/FriendsWave/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os

from pathlib import Path
from decouple import config
from decouple import config, Csv

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -21,12 +22,12 @@
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-^o$t%co88y9u5o+me!c!x^*bzrli3oxz)@k61ea)3au0*d!4b('
SECRET_KEY = config('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = config('DEBUG', cast=bool)

ALLOWED_HOSTS = []
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())


# Application definition
Expand All @@ -38,7 +39,11 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'social.apps.StoreSocial',
'social.apps',
'groupModule.apps',
'postModule.apps',
'commentModule.apps',
'topicModule.apps',
'rest_framework',
]

Expand Down Expand Up @@ -76,8 +81,7 @@
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

SECRET_KEY = config('SECRET_KEY')
DEBUG = config('DEBUG', cast=bool)

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
Expand Down Expand Up @@ -136,4 +140,5 @@
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10
}
}

19 changes: 3 additions & 16 deletions FriendsWave/FriendsWave/urls.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
"""FriendsWave URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path('admin/', admin.site.urls),
]
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Empty file.
3 changes: 3 additions & 0 deletions FriendsWave/commentModule/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions FriendsWave/commentModule/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CommentmoduleConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'commentModule'
Empty file.
34 changes: 34 additions & 0 deletions FriendsWave/commentModule/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.db import models
from social.models import Profil
from postModule.models import Post
from django.utils import timezone
# Create your models here.


"""
model Content
"""
class Content(models.Model):
Profil = models.ForeignKey(Profil, on_delete=models.CASCADE, related_name="creator")
shares = models.ManyToManyField(Profil, through='Share')
likes = models.ManyToManyField(Profil, through='Like')
content = models.TextField(max_length=1000)
media = models.FileField(upload_to='uploads/%Y/%m/%d/', null=True, blank=True)
created_at = models.DateTimeField(default=timezone.now, editable=False)
update_at = models.DateTimeField(auto_now=True)

class Meta:
ordering = ['created_at']
abstract = True
verbose_name = 'content'
verbose_plural_name = "contents"

def __str__(self):
return self.content


"""
model Comment
"""
class Comment(Content):
post = models.ForeignKey(Post, on_delete=models.CASCADE)
3 changes: 3 additions & 0 deletions FriendsWave/commentModule/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions FriendsWave/commentModule/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
Empty file.
3 changes: 3 additions & 0 deletions FriendsWave/groupModule/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions FriendsWave/groupModule/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class GroupmoduleConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'groupModule'
Empty file.
44 changes: 44 additions & 0 deletions FriendsWave/groupModule/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django.db import models
from social.models import Profil
from django.utils import timezone

# Create your models here.


"""
model Group
"""
class Group(models.Model):
VISIBILITY = (
('PUG', 'Public Group'),
('PRG', 'Private Group')
)

members = models.ManyToManyField(Profil, through='Member')
name = models.CharField(max_length=100)
description = models.TextField(max_length=100)
visibilty = models.CharField(max_length=100, choices=VISIBILITY)
link = models.CharField(max_length=100)
created_at = models.DateTimeField(default=timezone.now, editable=False)
update_at = models.DateTimeField(auto_now=True)

class Meta:
ordering = ['created_at', 'name']
verbose_name = "Group"
verbose_plural_name = "Groups"

def __str__(self):
return self.name



"""
model Member
"""
class Member(models.Model):
group = models.ForeignKey(Group, on_delete=models.CASCADE)
profil = models.ForeignKey(Profil, on_delete=models.CASCADE)
is_admin = models.BooleanField(default=False)
is_owner = models.BooleanField(default=False)
date_joined = models.DateTimeField(default=timezone.now, editable=False)
end= models.DateTimeField(null=True)
3 changes: 3 additions & 0 deletions FriendsWave/groupModule/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions FriendsWave/groupModule/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
Empty file.
3 changes: 3 additions & 0 deletions FriendsWave/postModule/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions FriendsWave/postModule/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class PostmoduleConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'postModule'
Empty file.
44 changes: 44 additions & 0 deletions FriendsWave/postModule/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django.db import models
from social.models import Profil, Topic
from django.utils import timezone

# Create your models here.

"""
model Content
"""
class Content(models.Model):
Profil = models.ForeignKey(Profil, on_delete=models.CASCADE, related_name="creator")
shares = models.ManyToManyField(Profil, through='Share')
likes = models.ManyToManyField(Profil, through='Like')
content = models.TextField(max_length=1000)
media = models.FileField(upload_to='uploads/%Y/%m/%d/', null=True, blank=True)
created_at = models.DateTimeField(default=timezone.now, editable=False)
update_at = models.DateTimeField(auto_now=True)

class Meta:
ordering = ['created_at']
abstract = True
verbose_name = 'content'
verbose_plural_name = "contents"

def __str__(self):
return self.content


"""
model Post
"""
class Post(Content):
topic = models.ForeignKey(Topic, on_delete=models.CASCADE)



"""
model Like
"""
class Like(models.Model):
profil = models.ForeignKey(Profil, on_delete=models.CASCADE)
content = models.ForeignKey(Content, on_delete=models.CASCADE)
created_at = models.DateTimeField(default=timezone.now, editable=False)
update_at = models.DateTimeField(auto_now=True)
3 changes: 3 additions & 0 deletions FriendsWave/postModule/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions FriendsWave/postModule/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
41 changes: 41 additions & 0 deletions FriendsWave/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
asn1crypto==0.24.0
backports.entry-points-selectable==1.1.1
configparser==4.0.2
contextlib2==0.6.0.post1
cryptography==2.1.4
distlib==0.3.3
django-environ==0.4.5
duplicity==0.7.17
enum34==1.1.6
fasteners==0.12.0
filelock==3.2.1
idna==2.6
importlib-metadata==2.1.2
importlib-resources==3.3.1
ipaddress==1.0.17
keyring==10.6.0d
keyrings.alt==3.0
lockfile==0.12.2
Markdown==3.1.1
monotonic==1.0
mysql-connector-python==2.1.6
mysql-utilities==1.6.4
paramiko==2.0.0
pathlib2==2.3.6
pexpect==4.2.1
platformdirs==2.0.2
psycopg2-binary==2.8.6
pyasn1==0.4.2
pycrypto==2.6.1
pygobject==3.26.1
pyodbc==4.0.17
pysqlite==2.7.0
python-decouple==3.5
pyxdg==0.25
scandir==1.10.0
SecretStorage==2.3.1
singledispatch==3.7.0
six==1.16.0
typing==3.10.0.0
virtualenv==20.10.0
zipp==1.2.0
77 changes: 75 additions & 2 deletions FriendsWave/social/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
from django.db import models
from django.db import models, utils
from django.contrib.auth.models import AbstractUser
from django.utils import timezone
from topicModule.models import Topic

# Create your models here.

"""
model user extend default user django
"""
class User(AbstractUser):
GENRE = (
('M', 'Masculin'),
('F', 'Feminin')
)

first_name = models.CharField(max_length=100)
last_npassame = models.CharField(max_length=100)
birth_date = models.DateField(null=True, blank=True)
genre = models.CharField(max_length=1, choices=GENRE)
phone_number = models.CharField(max_length=20)
address = models.CharField(max_length=30, blank=True)
user_name = models.CharField(max_length=20)
password = models.CharField(max_length=20)
created_at = models.DateTimeField(default=timezone.now, editable=False)
update_at = models.DateTimeField(auto_now=True)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need 2 line between 2 first level code in python (ref PEP 8) https://pep8.org/

Copy link

@ttgedeon ttgedeon Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General
1- A light comment(specifying purpose) should be added on each field for each model, and a doc-string(purpose/utility) added to each class of the code
2- _Descriptor class is imported form functools module without a clear use
3- Always provide a related name for each Fk and M2M relation
4- Always specify the on_delete behavior on each FK relation
5- use same name to refer to the same reality troughout the code. status vs etat, title vs subject, start vs start_date, end vs end_date
6- Use a Mixins to handle creation, last update time, and soft delete of every

class Meta:
ordering = ['created_at', 'genre']

def __str__(self):
return "%s %s" % (self.first_name, self.last_name)


"""
model Profil
"""
class Profil(models.Models):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="belong")
follow = models.ManyToManyField('self', through='Friend', related_name="have")
topics_of_interest = models.ManyToManyField(Topic, through='UserTopic')
pseudo = models.CharField(max_length=100)
avatar = models.ImageField(upload_to="static", null=True, blank=True)
email = models.EmailField(max_length=100)
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(default=timezone.now, editable=False)
update_at = models.DateTimeField(auto_now=True)

class Meta:
ordering = ['created_at']
verbose_name = "Profil"
verbose_plural_name = "Profils"

def __str__(self):
return self.pseudo



"""
model Friend
"""
class Friend(models.Model):
STATUS = (
('A', 'ACCEPT'),
('D', 'DENIE')
)

follower = models.ForeignKey(Profil, on_delete=models.CASCADE, related_name="friends")
followed = models.ForeignKey(Profil, on_delete=models.CASCADE, related_name="friend")
status = models.CharField(max_length=1, choices=STATUS)

class Meta:
verbose_name = "friend"
verbose_plural_name = "friends"

def __str__(self):
return self.STATUS
1 change: 0 additions & 1 deletion FriendsWave/social/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.shortcuts import render

# Create your views here.
Empty file.
3 changes: 3 additions & 0 deletions FriendsWave/systemModule/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
Loading