-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: nightly
Are you sure you want to change the base?
Conversation
from django.db import models | ||
from django.db.models.base import Model | ||
from django.db.models.fields.related import OneToOneField | ||
|
There was a problem hiding this comment.
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
FriendsWave/social/models.py
Outdated
etat = models.BooleanField(default=False) | ||
|
||
class Friend(models.Model): | ||
follower = models.ForeignKey(Profil, OneToOneField = models.CASCADE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1- Wrong setup of the ForeignKey relations using OneToOneField
FriendsWave/social/models.py
Outdated
|
||
class Profil(models.Models): | ||
pseudo = models.CharField(max_length=100) | ||
image = models.ImageField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1- Make sure static file settings if well configure and Specify specific storage of each static data with functionnality
2- Consider storing an email on Profile
FriendsWave/social/models.py
Outdated
profil = models.ForeignKey(Profil, on_delete=models.CASCADE) | ||
topic = models.ForeignKey(Topic, on_delete=models.CASCADE) | ||
choice_date = models.DateField() | ||
raison = models.TextField(max_length=100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"raison": always use English name to refer to field, variables, ... in code
FriendsWave/social/models.py
Outdated
class UserTopic(models.Model): | ||
profil = models.ForeignKey(Profil, on_delete=models.CASCADE) | ||
topic = models.ForeignKey(Topic, on_delete=models.CASCADE) | ||
choice_date = models.DateField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
choice_date vs creation date use a timestamp model mixins to thandle it automatically in created field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to make some changes on:
- coding style (PEP8)
- class and attributs naming
- foreign keys definitions
- and mode
from django.db import models | ||
from django.db.models.base import Model | ||
from django.db.models.fields.related import OneToOneField | ||
|
There was a problem hiding this comment.
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/
FriendsWave/social/models.py
Outdated
etat = models.BooleanField(default=False) | ||
|
||
class Friend(models.Model): | ||
follower = models.ForeignKey(Profil, OneToOneField = models.CASCADE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify a related_name on this field to avoid duplication on foreignt key definition by the ORM
FriendsWave/social/models.py
Outdated
|
||
class Friend(models.Model): | ||
follower = models.ForeignKey(Profil, OneToOneField = models.CASCADE) | ||
followed = models.ForeignKey(Profil, OneToOneField = models.CASCADE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify a related_name on this field to avoid duplication on foreignt key definition by the ORM
FriendsWave/social/models.py
Outdated
|
||
class Group(models.Model): | ||
designation = models.TextField(max_length=100) | ||
_description = models.TextField(max_length=100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A field name should not start with _
FriendsWave/social/models.py
Outdated
class Group(models.Model): | ||
designation = models.TextField(max_length=100) | ||
_description = models.TextField(max_length=100) | ||
type = models.BooleanField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type
is a python's reserved word. You can propose aomething alse.
FriendsWave/social/models.py
Outdated
designation = models.TextField(max_length=100) | ||
_description = models.TextField(max_length=100) | ||
type = models.BooleanField() | ||
created_at = models.DateField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The created_at
field is intended to be used in what case ? Are you planning to write it value yourself everytime?
FriendsWave/social/models.py
Outdated
members = models.ManyToManyField(Profil, through='Member') | ||
private_key = models.TextField(max_length=100, null=True) | ||
|
||
class Invitation(models.Model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible foreign key conflit in this class to handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is two Foreign key
to the same class.
FriendsWave/social/models.py
Outdated
Content = models.ForeignKey(Profil, on_delete=models.CASCADE) | ||
created_at = models.DateField() | ||
|
||
class share(models.Model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Model name don't start like this. Refer to the PEP8 documentation for coding style guideline
FriendsWave/social/models.py
Outdated
end_date = models.DateField(null=True) | ||
|
||
class Content(models.Model): | ||
Profil = models.ForeignKey(Profil, on_delete=models.CASCADE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class attributes don't start like this, refer to the PEP8 coding style.
FriendsWave/social/models.py
Outdated
image = models.ImageField() | ||
user = models.ForeignKey('auth.User', on_delete=models.CASCADE) | ||
friends = models.ManyToManyField('self', through='Friend') | ||
topics = models.ManyToManyField('Topic', through='UserTopic') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
topics relates to what? topics created by the user, read by the users, deleted by the user.... Use topics_of_interest: it more meaningfull
FriendsWave/social/models.py
Outdated
|
||
class Profil(models.Models): | ||
pseudo = models.CharField(max_length=100) | ||
image = models.ImageField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user profile_image intead of image: it's more meaningfull
FriendsWave/social/models.py
Outdated
user = models.ForeignKey('auth.User', on_delete=models.CASCADE) | ||
friends = models.ManyToManyField('self', through='Friend') | ||
topics = models.ManyToManyField('Topic', through='UserTopic') | ||
etat = models.BooleanField(default=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
etat field is meaning less. active, is_active, profile_is_active are increasingly meaningful
FriendsWave/social/models.py
Outdated
topic = models.ForeignKey(Topic, on_delete=models.CASCADE) | ||
choice_date = models.DateField() | ||
raison = models.TextField(max_length=100) | ||
start_date = models.DateField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add field like last_opened for practical reasons
FriendsWave/social/models.py
Outdated
|
||
|
||
class Group(models.Model): | ||
designation = models.TextField(max_length=100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider replacing designation by name
FriendsWave/social/models.py
Outdated
|
||
class Group(models.Model): | ||
designation = models.TextField(max_length=100) | ||
_description = models.TextField(max_length=100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the underscore on "_description"
FriendsWave/social/models.py
Outdated
class Group(models.Model): | ||
designation = models.TextField(max_length=100) | ||
_description = models.TextField(max_length=100) | ||
type = models.BooleanField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"type" field is meaningless
FriendsWave/social/models.py
Outdated
designation = models.TextField(max_length=100) | ||
_description = models.TextField(max_length=100) | ||
type = models.BooleanField() | ||
created_at = models.DateField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created_at: should be created, and automatically generated by a Timestamp mixin
FriendsWave/social/models.py
Outdated
class Invitation(models.Model): | ||
profil = models.ForeignKey(Profil, on_delete=models.CASCADE) | ||
group = models.ForeignKey(Group, on_delete=models.CASCADE) | ||
sujbject = models.ForeignKey(Profil, on_delete=models.CASCADE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ubdate "sujbject"
FriendsWave/social/models.py
Outdated
group = models.ForeignKey(Group, on_delete=models.CASCADE) | ||
sujbject = models.ForeignKey(Profil, on_delete=models.CASCADE) | ||
created_at = models.DateField() | ||
etat = models.BooleanField(default=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider storing etat which might refer to state in a charfield with predefined choice list
FriendsWave/social/models.py
Outdated
created_at = models.DateField() | ||
etat = models.BooleanField(default=False) | ||
|
||
class Member(models.Model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider adding a state boolean on this class to track multiple times sbdy becomes or leaves his group privileges
FriendsWave/social/models.py
Outdated
profil = models.ForeignKey(Profil, on_delete=models.CASCADE) | ||
is_admin = models.BooleanField(default=False) | ||
is_owner = models.BooleanField(default=False) | ||
start_date = models.DateField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start_date should be datetime and handled by a model mixin
FriendsWave/social/models.py
Outdated
end_date = models.DateField(null=True) | ||
|
||
class Content(models.Model): | ||
Profil = models.ForeignKey(Profil, on_delete=models.CASCADE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1- you are using the "Profil" class name to define a field in an other class
2- No need to link content to Topic class
3- this class should store obvious common attributes between Post and comment leaving any specialized attribute to be defined in corresponding classes
FriendsWave/social/models.py
Outdated
class Meta: | ||
abstract = True | ||
|
||
class Post(Content): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1-a post should be able to store a static file
FriendsWave/social/models.py
Outdated
pass | ||
|
||
class Comment(Content): | ||
post = models.ForeignKey(Post, on_delete=models.CASCADE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why linking comment to post? what about comment on a comment. review it
FriendsWave/social/models.py
Outdated
|
||
class Like(models.Model): | ||
profil = models.ForeignKey(Profil, on_delete=models.CASCADE) | ||
Content = models.ForeignKey(Profil, on_delete=models.CASCADE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are using "Content" class name to name a field on an other class
FriendsWave/social/models.py
Outdated
class Like(models.Model): | ||
profil = models.ForeignKey(Profil, on_delete=models.CASCADE) | ||
Content = models.ForeignKey(Profil, on_delete=models.CASCADE) | ||
created_at = models.DateField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created_at should be created, handled with a mixin automatically and must be a datetime
FriendsWave/social/models.py
Outdated
class share(models.Model): | ||
sender = models.ForeignKey(Profil, on_delete=models.CASCADE) | ||
recipient = models.ForeignKey(Profil, on_delete=models.CASCADE) | ||
post = models.ForeignKey(Post, on_delete=models.CASCADE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two things can be shared: post & comment. handle this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle all these issues with high precision
…iendsWave-api into feat-modelCorrection
first model correction
The list of models