Cloning Airbnb with Python, Django, Tailwind and more ... 🐍
Start project with:
django-admin startproject config
Rename root config folder(This is to avoid naming conflict when moving inner config folder), move inner config folder and manage.py
file to root and delete old config folder.
Never have to many functionalities in one app
***Divide and Conquer***
You should be able to describe the application in one sentence
Applications name should be plurals. A good example is posts, users, todos etc.
Make little migrations as possible when defining your app models.
Define your import using strings => ""
```python
class Photo(core_models.TimeStampedModel):
"""Photo Model Definition."""
caption = models.CharField(max_length=100) file = models.ImageField() room = models.ForeignKey(Room, on_delete=CASCADE)
Room
is not defined first before before the Photo class. A good practice is...class Photo(core_models.TimeStampedModel): """Photo Model Definition."""
caption = models.CharField(max_length=100)
file = models.ImageField()
room = models.ForeignKey("Room", on_delete=CASCADE)
## Yes, enclose in quotes, haha...
#### def _str(self): function (self-depr method.... forgive me🤣):
```python
class Conversation(core_models.TimeStampedModel):
"""Conversation Model Definition"""
participants = models.ManyToManyField("users.User", blank=True)
def __str__(self):
return self.created ## Django is expecting a string, it gets a DateTime object(Hence Error).
#return str(self.created) ## Here we force a string conversion
# I will be getting back to that though, just to hack it for now...