posts package
Submodules
posts.admin module
posts.apps module
posts.forms module
- class posts.forms.CommentForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]
Bases:
ModelForm
Class for holing the forms to write comment to a post.
- base_fields = {'text': <django.forms.fields.CharField object>}
- declared_fields = {}
- property media
Return all media required to render the widgets on this form.
- class posts.forms.PostForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]
Bases:
ModelForm
Class for holding the forms of sending post.
- base_fields = {'caption': <django.forms.fields.CharField object>, 'image': <django.forms.fields.ImageField object>}
- declared_fields = {}
- property media
Return all media required to render the widgets on this form.
posts.models module
- class posts.models.Comment(*args, **kwargs)[source]
Bases:
Model
Database model for adding comment to a post.
- Attributes:
post: link to the post in which the comment is. user: The user who write the comment. text: comment body. created_at: timestamp
- Methods:
__str__: display in database.
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- created_at
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
- get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- post
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- post_id
- text
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- user
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- user_id
- class posts.models.Post(*args, **kwargs)[source]
Bases:
Model
The class for each post in the homepage.
- Attributes:
user: Foreign Key from users table. Hold the username of a post. image: Photo uploaded for a post. caption: Details of the post and image caption. created_at: show post in newest first. likse: Users like for post.
- Methods:
total_likes: show number of total likes in a post. __str__: display post data in database format.
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- caption
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- comments
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- created_at
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
- get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- image
Just like the FileDescriptor, but for ImageFields. The only difference is assigning the width/height to the width_field/height_field, if appropriate.
- likes
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppings
andTopping.pizzas
areManyToManyDescriptor
instances.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- objects = <django.db.models.manager.Manager object>
- user
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- user_id
posts.tests module
posts.urls module
posts.views module
- posts.views.add_comment(request, post_id)[source]
Enable the commenting functionality. Add comment in multiple user in a specific post.
- Args:
request: The incomming http request. post_id: The specific post id in which the comment is written.
- Returns:
HttpResponse: Rendered to post_list template with the updated comment.
- posts.views.create_post(request)[source]
Give user access to create post to socialmeida.
- Args:
request (HttpRequest): The incoming HTTP request.
- Returns:
HttpResponse: Redirect to post_list page on successful post creation. Otherwise stays in create post form.