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

Interactive Tweet Management System #877

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions Web_Development/djangotweet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env/
4 changes: 4 additions & 0 deletions Web_Development/djangotweet/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
asgiref==3.8.1
Django==5.1.2
sqlparse==0.5.1
tzdata==2024.2
Binary file added Web_Development/djangotweet/tweethead/db.sqlite3
Binary file not shown.
22 changes: 22 additions & 0 deletions Web_Development/djangotweet/tweethead/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tweethead.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
5 changes: 5 additions & 0 deletions Web_Development/djangotweet/tweethead/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
asgiref==3.8.1
Django==5.1.2
pillow==11.0.0
sqlparse==0.5.1
tzdata==2024.2
83 changes: 83 additions & 0 deletions Web_Development/djangotweet/tweethead/templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{% load static %}

<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">

</head>
<title>
{% block title %}

Chai and django

{% endblock %}


</title>
</head>
<body>
<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container-fluid">
<a class="navbar-brand" href="#">Tweet bar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link disabled" aria-disabled="true">Disabled</a>
</li>
</ul>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>

<a href="{% url 'tweet_list' %}" class="btn btn-primary mx-2">Tweet Home</a>
{% if user.is_authenticated %}
<form method="post" action="{% url 'logout' %}">
{% csrf_token %}
<button class="btn btn-danger" type="submit">Logout</button>
</form>
{% else %}
<a href="{% url 'register' %}" class="btn btn-primary mx-2">Register</a>
<a href="{% url 'login' %}" class="btn btn-outline-success mx-2">Login</a>
{% endif %}
</div>
</div>
</nav>




<div class="container">
{% block container %}


{% endblock %}


</div>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "layout.html" %}

{% block container %}
<h2>Logged out</h2>

<p>You have been logged out<a href="{% url 'login' %}">Login here</a></p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "layout.html" %}

{% block container %}
<h2>Login form</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button class="btn btn-primary">Login</button>
</form>
<p>Don't have an account? <a href="{% url 'register' %}">Register here</a></p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "layout.html" %}

{% block container %}
<h2>Register form form</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button class="btn btn-primary">Register</button>
</form>

{% endblock %}
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions Web_Development/djangotweet/tweethead/tweet/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin
from .models import Tweet

# Register your models here.

admin.site.register(Tweet)
6 changes: 6 additions & 0 deletions Web_Development/djangotweet/tweethead/tweet/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class TweetConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'tweet'
16 changes: 16 additions & 0 deletions Web_Development/djangotweet/tweethead/tweet/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django import forms
from .models import Tweet
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

class TweetForm(forms.ModelForm):
class Meta:
model = Tweet
fields = ['text','photo']


class UserRegistrationForm(UserCreationForm):
email=forms.EmailField()
class Meta:
model = User
fields = ('username','email','password1','password2')
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.1.2 on 2024-10-17 06:04

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Tweet',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.TextField(max_length=240)),
('photo', models.ImageField(blank=True, null=True, upload_to='photos/')),
('created_at', models.DateField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file.
Copy link

Choose a reason for hiding this comment

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

Hey @Ananyashetty7 ,
Please remove the BINARY files like .pyc.
Also try adding a README.md file to this , helps understand the structure of the project.
Update the changes and I will approve the PR.
Also if you need any help let me know!
Thank you!

Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions Web_Development/djangotweet/tweethead/tweet/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.db import models
from django.contrib.auth.models import User

# Create your models here.


class Tweet(models.Model):

user=models.ForeignKey(User,on_delete=models.CASCADE)
text=models.TextField(max_length=240)
photo=models.ImageField(upload_to = 'photos/', blank=True, null=True)
created_at=models.DateField(auto_now_add=True)
updated_at=models.DateTimeField(auto_now=True)


def __str__(self):
return f'{self.user.username} - {self.text[:10]}'






17 changes: 17 additions & 0 deletions Web_Development/djangotweet/tweethead/tweet/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "layout.html" %}

{% block title %}


Chai aur tweet

{% endblock %}

{% block container %}


<h1 class="text-center mt-4">
Welcome to this django project

</h1>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "layout.html" %}

{% block title %}


Chai aur tweet

{% endblock %}

{% block container %}


<h1 class="text-center mt-4">
Are you sure you want to delete this tweet?

</h1>

<form method="post">
{% csrf_token %}
<button class="btn btn-danger">Delete</button>
<a class="btn btn-success" href="{% url 'tweet_list' %}">Cancel</a>
</form>



{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends "layout.html" %}

{% block title %}
Chai aur tweet
{% endblock %}

{% block container %}
<h1 class="text-center mt-4">
Welcome to this Django project
</h1>

<h2>
{% if form.instance.pk %}
Edit Tweet
{% else %}
Create Tweet
{% endif %}
</h2>

<form method="post" enctype="multipart/form-data" class="form">
{% csrf_token %}
{{ form.as_p }}
<button class="btn btn-warning" type="submit">Submit</button>
</form>

<a href="{% url 'tweet_list' %}">Back to tweet list</a>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends "layout.html" %}

{% block title %}


Chai aur tweet

{% endblock %}

{% block container %}


<h1 class="text-center mt-4">
Welcome to this django project
</h1>

<a class="btn btn-primary" href="{% url 'tweet_create' %}">Create a tweet</a>

<div class="container row gap-3">
{%for tweet in tweets%}
<div class="card" style="width: 18rem;">
<img src="{{tweet.photo.url}}" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">{{tweet.user.username}}</h5>
<p class="card-text">{{tweet.text}}</p>

{% if tweet.user == user %}
<a href="{% url 'tweet_edit' tweet.id %}" class="btn btn-primary">Edit</a>
<a href="{% url 'tweet_delete' tweet.id %}" class="btn btn-danger">Delete</a>
{% endif %}
</div>
</div>

{% endfor %}


</div>


{% endblock %}
3 changes: 3 additions & 0 deletions Web_Development/djangotweet/tweethead/tweet/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.
14 changes: 14 additions & 0 deletions Web_Development/djangotweet/tweethead/tweet/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

from django.urls import path
from . import views


urlpatterns = [


path('',views.tweet_list,name='tweet_list'),
path('create/',views.tweet_create,name='tweet_create'),
path('<int:tweet_id>/edit/',views.tweet_edit,name='tweet_edit'),
path('<int:tweet_id>/delete/',views.tweet_delete,name='tweet_delete'),
path('register/',views.register,name='register'),
]
Loading