مشاركة حلول: عمل model للمنشورات posts

مرحباً جميعاً

المهمة المطلوبة

بإمكانك الإطلاع على المهمة المطلوبة من هنا

كيفية كتابة الأكواد في المنتدى

5 Likes
class WebPage:
    posts = []
    def __init__(self,logo,name,photo,content):
        self.logo = logo
        self.name = name
        self.photo = photo
        self.content = content

    def new(self):
        new_post = {}
        self.name = input("Enter your name: ")
        new_post["Name"] = self.name
        self.photo = input("Enter photo URL")
        new_post["photo"] = self.photo
        self.content = input("Write your post here .. ")
        new_post["post"] = self.content
        #posts.append(new_post)

    #def edit(self):


    #def delete(self):

post1 = WebPage("http://wddfjkll.jpg","Asmaa","http://ityyuddty.jpg","i just trying my code")
post1.new()


3 Likes

عمل رائع جداً أسماء :+1:

ملاحظة بسيطة وهي أن الدالة new والقائمة posts لا داعي لها في هذا الكلاس, لأن هذه وظيفة الكلاس الآخر Store… كما تعرفي مبدأ SRP - Single Responsibility Principle (وظيفة واحدة للعنصر الواحد), كل كلاس له وظيفته :wink:

4 Likes
class Facebook:
    def __init__(self, title, photo, name, content):
        self.title = title
        self.photo = photo
        self.name = name
        self.content = content

class Postes():
    def new(self):
        new_post = []
        self.photo = input("enter url for photo")
        new_post.extend(self.photo)
        self.name = input("enter your name: ")
        new_post.extend(self.name)
        self.content = input("write any post")
        new_post.extend(self.content)
    
post1= Postes()
post1.new()
print (post1)

لكن لدي سؤال لماذا لا يتم تخزين المعلومات التي اقوم بكتابنها في القائمة new_post؟

2 Likes

عمل رائع يا يحيى… اعتقد انك عرفت اجابة سؤالك في المهمات الاخرى.

1 Like

سلام استاذ ياسر اكثر توضيح من فضلك لم أفهم المطلوب جيدا

1 Like

مرحباً سارة

مثلما قمنا بعمل model للـ blog في هذا الدرس:

https://coretabs.net/classroom/backend/عمل-تطبيق-مشابه-للفيسبوك/بناء-تطبيق-كونسول-console-app/عمل-نموذج-model-لمقالة-blog

نحتاج الآن model للـ post لتنفيذه على مشروعنا كما هو مشروح في المهمة (مالذي يحتويه هذا المودل)

1 Like
class POSTES():
    def __init__(self, logo, photo, name, content):
        self.logo = logo
        self.photo = photo
        self.name = name
        self.content =content


    


poste1 = POSTES(logo='logo',photo='photo',name='sara',content='hello every one')
poste2 = POSTES(logo='logo2',photo='photo2',name='mohamed',content='how are you')

Postes =[poste1,poste2]
print(Postes[1].name)
3 Likes

عمل رائع سارة :+1:

1 Like
class Blog:
    def __init__(self, logo, name, image, content):
        self.logo = logo
        self.name = name
        self.image = image
        self.content = content


blog1 = Blog('logo address', 'Ahmed', 'image address', 'this is my first model')

4 Likes

سرعة رائعة في انهاء المهام، high five :raised_hand_with_fingers_splayed:

هذه تجربتي ^^

class Post:

    def __init__(self, name, picture, content):
        self.name = name
        self.picture = picture
        self.content = content 
    
    def edit_post(self, content):
        self.content = content

    def delet_post(self):
        self.name = None
        self.picture = None
        self.content = None

post1 =Post(name = "kamel", picture="kam.jpg", content="I tried to make model for posts, I hope you like my work,and correct it to me ^^ .")
post2 =Post(name = "Yaser", picture="Yaser.jpg", content="Nice work Kamel keep going ^^ .")
print("="*5 + "POST ONE" + "="*5)
print("Post one name : "+str(post1.name))
print("Post one Photo : "+str(post1.picture))
print("Post one content : "+str(post1.content))
print("="*5 + "POST TWO" + "="*5)
print("Post two name : "+str(post2.name))
print("Post two Photo : "+str(post2.picture))
print("Post two content : "+str(post2.content))
print("="*5 + "EDIT POST ONE" + "="*5)
post1.edit_post("This is new content after editing post ^^")
print("Post one name : "+str(post1.name))
print("Post one Photo : "+str(post1.picture))
print("Post one content : "+str(post1.content))
print("="*5 + "DELET POST ONE" + "="*5)
post1.delet_post()
print("Post one name : "+str(post1.name))
print("Post one Photo : "+str(post1.picture))
print("Post one content : "+str(post1.content))

وهذه هي النتيجة

=====POST ONE=====
Post one name : kamel
Post one Photo : kam.jpg
Post one content : I tried to make model for posts, I hope you like my work,and correct it to me ^^ .
=====POST TWO=====
Post two name : Yaser
Post two Photo : Yaser.jpg
Post two content : Nice work Kamel keep going ^^ .
=====EDIT POST ONE=====
Post one name : kamel
Post one Photo : kam.jpg
Post one content : This is new content after editing post ^^
=====DELET POST ONE=====
Post one name : None
Post one Photo : None
Post one content : None
2 Likes

عمل رائع جدا يا كمال :+1:

بالمناسبة انت لا تحتاج الدالتين edit delete لانهما سيكونان موجودين في كلاس اخر (في الدروس القادمة).

1 Like

اها هذا جيد ^^
شكرا استاذ ياسر

1 Like

class post:
    def __init__(self, name, photo, body):
        self.name = name
        self.photo = photo
        self.body = body
post1 = post("anam", "https://www.pexels.com/photo/men-s-white-dress-shirt-936229/", "I am student")
post2 = post("sam", "https://www.pexels.com/photo/men-s-white-dress-shirt-936229/", "I am student")
post3 = post("ali", "https://www.pexels.com/photo/men-s-white-dress-shirt-936229/", "I am student")
print(post1.name)
1 Like

كالعادة يا علي… عمل رائع :+1:

1 Like
class Post:
    def __init__(self, logo, photo, name, content):
        self.logo = logo
        self.photo = photo
        self.name = name
        self.content = content

post1 = Post(logo='logo',photo='image1',name='yaser',content='first interesting topic goes here...')
post2 = Post(logo='logo',photo='https://www.pexels.com/photo/adult-beard-boy-casual-220453/',name='mohammed',content='second topic goes here...')
post3 = Post(logo='logo',photo='image3',name='sara',content='third topic goes here...')


print(post1.name)
print(post2.photo)
print(post3.content)
1 Like

كالعادة عمل رائع :+1:

ماهي فائدة الحقل logo ؟

1 Like

يعني شعار ثابت لكل المنشورات

1 Like

بإمكانك جعله بهذا الشكل طالما هو ثابت:

class Post:
    logo = 'logo'

    def __init__(self, photo, name, content):
        self.photo = photo
        self.name = name
        self.content = content

سندخل في هذه الأمور بتعمق أكثر مستقبلا :wink:

2 Likes